Difference between revisions of "Documentation/DevGuide/Spreadsheets/Example: Editing Spreadsheet Cells"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Documentation/Developers Guide/Spreadsheet Documents)
m (FINAL VERSION FOR L10N)
Line 5: Line 5:
 
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files
 
|NextPage=Documentation/DevGuide/Spreadsheets/Handling Spreadsheet Documents Files
 
}}
 
}}
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Example: Editing Spreadsheet Cells}}
 
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>:  
 
The method <code>insertSpreadsheet()</code> returns a <idl>com.sun.star.sheet.XSpreadsheet</idl> interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface <idl>com.sun.star.sheet.XSpreadsheet</idl> returned by <code>insertSpreadsheet()</code> is derived from <idl>com.sun.star.table.XCellRange</idl>. By working with it, cells can be accessed immediately using <code>getCellByPosition()</code>:  
 
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]-->
 
<!--[SOURCE:Spreadsheet/GeneralTableSample.java]-->

Revision as of 10:21, 14 May 2009



The method insertSpreadsheet() returns a com.sun.star.sheet.XSpreadsheet interface. This interface is passed to the method below, which shows how to access and modify the content and formatting of single cells. The interface com.sun.star.sheet.XSpreadsheet returned by insertSpreadsheet() is derived from com.sun.star.table.XCellRange. By working with it, cells can be accessed immediately using getCellByPosition():

 void cellWork(XSpreadsheet xRange) {
 
     com.sun.star.beans.XPropertySet xPropSet = null;
     com.sun.star.table.XCell xCell = null;
     
     // Access and modify a VALUE CELL
     xCell = xRange.getCellByPosition(0, 0);
     // Set cell value.
     xCell.setValue(1234);
     
     // Get cell value.
     double nDblValue = xCell.getValue() * 2;
     xRange.getCellByPosition(0, 1).setValue(nDblValue);
     
     // Create a FORMULA CELL
     xCell = xRange.getCellByPosition(0, 2);
     // Set formula string.
     xCell.setFormula("=1/0");
     
     // Get error type.
     boolean bValid = (xCell.getError() == 0);
     // Get formula string.
     String aText = "The formula " + xCell.getFormula() + " is ";
     aText += bValid ? "valid." : "erroneous.";
     
     // Insert a TEXT CELL using the XText interface
     xCell = xRange.getCellByPosition(0, 3);
     com.sun.star.text.XText xCellText = (com.sun.star.text.XText)
         UnoRuntime.queryInterface(com.sun.star.text.XText.class, xCell);
     com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor();
     xCellText.insertString(xTextCursor, aText, false);
 }


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages