Personal tools
You are here: Home Forum Nice Office Access (NOA) Posting data to a spreadsheet

 • Posting data to a spreadsheet

Replies: 1   Views: 193
Up one level

 • Posting data to a spreadsheet

Posted by Blacklock at 2007-03-08 07:54:45
I am interested in in using NOA to use OpenOffice in a eclipse application. I can currently open a spreadsheet. My question is can I programmatically add data to this openned spreadsheet, and after the user edits it, programmatically retrieve the data in the eclipse application. This appears doable in a text document. If this is possible can you point me in the right direction to start? Thanks
Blacklock Member
Posts: 1

 • Re: Posting data to a spreadsheet

Posted by Markus Krueger at 2007-03-09 13:28:44
Hello David,
I am sorry to tell You, that we have not implemented an easy
access to calc as our focus is the writer. So you have to deal
with the real OpenOffice.org Java UNO API.

But here is a snippet on how to set data in a calc document.
Same way would be used to get data.
IDocument document = documentService.constructNewDocument(
    IDocument.CALC, DocumentDescriptor.DEFAULT);
ISpreadsheetDocument spreadsheetDocument = (ISpreadsheetDocument) document;
XSpreadsheets spreadsheets = 
  spreadsheetDocument.getSpreadsheetDocument().getSheets();
String sheetName= "Tabelle1";
Object rows = new Object{
  new Object{"DataCell1","DataCell2","DataCell3","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)}};
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 ;
  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;
    if(insert instanceof Number)
      cell.setValue(((Number)insert).doubleValue());
    else if(insert instanceof String)
      cellText.setString((String)insert);
    else
      cellText.setString(insert.toString());          
  }
}

Best regards,

Markus
Markus Krueger Manager
Posts: 507

Powered by Plone, the Open Source Content Management System

This site conforms to the following standards: