Spreadsheet
From NOA Documentation Wiki
According to Snippet 15 and http://ubion.ion.ag/mainForumFolder/noa_forum/0048/ you can load a spreadsheet (and fill it with data) like this:
IFrame officeFrame = officeApplication.getDesktopService().constructNewOfficeFrame(panel);
IDocument document=officeApplication.getDocumentService().constructNewDocument(officeFrame, IDocument.CALC, DocumentDescriptor.DEFAULT);
ISpreadsheetDocument spreadDocument=(ISpreadsheetDocument) document;
spreadDocument.addCloseListener(new OOoCloseListener(configs.getOfficeApplication()));
XSpreadsheets spreadsheets = spreadDocument.getSpreadsheetDocument().getSheets();
String sheetName= "Tabelle1";
Object rows[][] = {
new Object[]{new String("DataCell1"),new String("DataCell2"),new String("DataCell3"),new String("DataCell4")},
new Object[]{new Integer(10),new Integer(20),new Integer(30),new Integer(40)},
new Object[]{new Double(11.11),new Double(22.22),new Double(33.33),new Double(44.44)}
};
String sheetName= "Tabelle1";
XSpreadsheet spreadsheet1 =
(XSpreadsheet)UnoRuntime.queryInterface(
XSpreadsheet.class,spreadsheets.getByName(sheetName));
// insert your Data
XSheetCellCursor cellCursor = spreadsheet1.createCursor();
for(int i = 0; i < rows.length; i++) {
Object[] cols = rows[i] ;
for(int j = 0; j < cols.length; j++) {
XCell cell= cellCursor.getCellByPosition(j,i);
XText cellText = (XText)UnoRuntime.queryInterface(XText.class, cell);
Object insert = cols[j];
if(insert instanceof Number)
cell.setValue(((Number)insert).doubleValue());
else if(insert instanceof String)
cellText.setString((String)insert);
else
cellText.setString(insert.toString());
}
}
* */
frame.validate();
// Now it is time to disable two commands in the frame
officeFrame.disableDispatch(GlobalCommands.CLOSE_DOCUMENT);
officeFrame.disableDispatch(GlobalCommands.QUIT_APPLICATION);
}
catch (Throwable throwable) {
throwable.printStackTrace();
}
of course officeApplication.getDocumentService().constructNewDocument will construct a new document, you could as well load one by using (analogue to writer documents)
IDocument document=officeApplication.getDocumentService().loadDocument(officeFrame,IDocument.CALC);
instead of using
XSpreadsheet spreadsheet1 = (XSpreadsheet)UnoRuntime.queryInterface( XSpreadsheet.class,spreadsheets.getByName(sheetName));
I personally recommend getElementNames, otherwise you might be subject to localization if your user uses a different language version of OOO.o:
XSpreadsheet.class,spreadsheets.getByName(spreadsheets.getElementNames()[0]));

