//***************************************************************************
//Open document
//Calc
XSpreadsheetDocument myDoc = null;
// XCell oCell = null;
System.out.println("Opening an empty Calc document");
myDoc = openCalc(xContext);
//***************************************************************************
//oooooooooooooooooooooooooooStep 3oooooooooooooooooooooooooooooooooooooooooo
// create cell styles.
// For this purpose get the StyleFamiliesSupplier and the the familiy
// CellStyle. Create an instance of com.sun.star.style.CellStyle and
// add it to the family. Now change some properties
//***************************************************************************
try {
XStyleFamiliesSupplier xSFS = (XStyleFamiliesSupplier)
UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, myDoc);
XNameAccess xSF = (XNameAccess) xSFS.getStyleFamilies();
XNameAccess xCS = (XNameAccess) UnoRuntime.queryInterface(
XNameAccess.class, xSF.getByName("CellStyles"));
XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class, myDoc );
XNameContainer oStyleFamilyNameContainer = (XNameContainer)
UnoRuntime.queryInterface(
XNameContainer.class, xCS);
XInterface oInt1 = (XInterface) oDocMSF.createInstance(
"com.sun.star.style.CellStyle");
oStyleFamilyNameContainer.insertByName("My Style", oInt1);
XPropertySet oCPS1 = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, oInt1 );
oCPS1.setPropertyValue("IsCellBackgroundTransparent", new Boolean(false));
oCPS1.setPropertyValue("CellBackColor",new Integer(6710932));
oCPS1.setPropertyValue("CharColor",new Integer(16777215));
XInterface oInt2 = (XInterface) oDocMSF.createInstance(
"com.sun.star.style.CellStyle");
oStyleFamilyNameContainer.insertByName("My Style2", oInt2);
XPropertySet oCPS2 = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, oInt2 );
oCPS2.setPropertyValue("IsCellBackgroundTransparent", new Boolean(false));
oCPS2.setPropertyValue("CellBackColor",new Integer(13421823));
} catch (Exception e) {
e.printStackTrace(System.err);
}
//***************************************************************************
//oooooooooooooooooooooooooooStep 4oooooooooooooooooooooooooooooooooooooooooo
// get the sheet an insert some data.
// Get the sheets from the document and then the first from this container.
// Now some data can be inserted. For this purpose get a Cell via
// getCellByPosition and insert into this cell via setValue() (for floats)
// or setFormula() for formulas and Strings
//***************************************************************************
XSpreadsheet xSheet=null;
try {
System.out.println("Getting spreadsheet") ;
XSpreadsheets xSheets = myDoc.getSheets() ;
XIndexAccess oIndexSheets = (XIndexAccess) UnoRuntime.queryInterface(
XIndexAccess.class, xSheets);
xSheet = (XSpreadsheet) UnoRuntime.queryInterface(
XSpreadsheet.class, oIndexSheets.getByIndex(0));