Office4J - The office API for java


With office4j it will be easy possible to acces the microsoft office applications (word, excel, powerpoint, access ...).  To use this API it will be necessary to download the Java COM Bridge (JACOB) from Dan Dandler.

Info:

This API is a first pre alpha version. If you are interested to help me to complete the API send a mail to luckysmile2007@gmx.net.


Installation:

Example:

    In this section I will explain how to create a new office instance, how to insert a text, a table and how to save the document to disc.

    File wordDocument = new File("data", "WordTest.doc");
    // creates a new word instance
    Application word = new Application();
    word.setVisible(true);
    // creates a new document
    Document document=word.getDocuments().add();
    Range range=document.getRange();
    // inserts a test info
    range.insertAfter("This is a test information");
    range.goToPosition(0);
    // inserts a new table with 4 rows and 5 columns
    Table table=document.getTables().add(range, 4, 5);
    Selection selection=document.getGlobal().getSelection();
    // inserts a test info in cell (2,3)
    Cell cell=table.getCell(2, 3);
    cell.getRange().insertAfter("test text");
    // prints out the content of the document  to the console
    selection.getBookmarks().getItem("\\Section").select();
    range = selection.getRange();
    System.out.println(range.getText());
    // saves the document to hard disc
    document.saveAs(wordDocument);
    document.close(WdSaveOptions.wdSaveChanges,WdOriginalFormat.wdOriginalDocumentFormat,false);
    word.quit(WdSaveOptions.wdDoNotSaveChanges, WdOriginalFormat.wdOriginalDocumentFormat, false);