XStyleFamiliesSupplier.class, xSpreadsheetDoc);
XNameAccess oStyleFamilies = oStyleFamiliesSupplier.getStyleFamilies();
XIndexAccess oStyleFamiliesIndexAccess = (XIndexAccess)
UnoRuntime.queryInterface(XIndexAccess.class, oStyleFamilies);
XNameAccess oStyleFamilyNameAccess = null;
XStyle oStyle = null;
try {
oStyleFamilyNameAccess = (XNameAccess) AnyConverter.toObject(
new Type(XNameAccess.class),
oStyleFamiliesIndexAccess.getByIndex(0));
XIndexAccess oStyleFamilyIndexAccess = (XIndexAccess)
UnoRuntime.queryInterface(XIndexAccess.class,
oStyleFamilyNameAccess);
oStyle = (XStyle) AnyConverter.toObject(
new Type(XStyle.class),oStyleFamilyIndexAccess.getByIndex(0));
} catch(com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't get by index", e);
} catch(com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't get by index", e);
} catch(com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't get by index", e);
}
log.println("Creating a user-defined style");
XMultiServiceFactory oMSF = (XMultiServiceFactory)
UnoRuntime.queryInterface(
XMultiServiceFactory.class, xSpreadsheetDoc);
XInterface oInt = null;
try {
oInt = (XInterface)
oMSF.createInstance("com.sun.star.style.CellStyle");
} catch(com.sun.star.uno.Exception e) {
e.printStackTrace(log);
throw new StatusException("Couldn't create instance", e);
}
XStyle oMyStyle = (XStyle)UnoRuntime.queryInterface(XStyle.class, oInt);
XNameContainer oStyleFamilyNameContainer = (XNameContainer)UnoRuntime.
queryInterface(XNameContainer.class, oStyleFamilyNameAccess);
try {
if (oStyleFamilyNameContainer.hasByName("My Style")) {
oStyleFamilyNameContainer.removeByName("My Style");
}
oStyleFamilyNameContainer.insertByName("My Style", oMyStyle);
} catch(com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't create test environment", e);
} catch(com.sun.star.container.NoSuchElementException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't create test environment", e);
} catch(com.sun.star.container.ElementExistException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't create test environment", e);
} catch(com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't create test environment", e);
}
//using the style
log.println("Getting spreadsheet") ;
XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
XIndexAccess oIndexSheets = (XIndexAccess)
UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
XCell aCell = null;
try {
XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
log.println("Getting a cell from sheet") ;
aCell = oSheet.getCellByPosition(2,3) ;
} catch(com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't get spreadsheet by index", e);
} catch(com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't get spreadsheet by index", e);
} catch(com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't get spreadsheet by index", e);
}
XPropertySet xProp = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, aCell);
try {
xProp.setPropertyValue("CellStyle", oMyStyle.getName());
} catch(com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace(log);
throw new StatusException("Couldn't set property CellStyle", e);
} catch(com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace(log);