OO-Snippets: cell/columns attrib

Commons

Keywordscell attributes, backgroundcolor, optimal width
LanguageJava
ApplicationCalc
AuthorsTom Schindl (initial)
Supported Versions
Supported OS
Question How can I modify cell-attributes

e.g. set the background-color, set the width to optimal value

Answer

Code-Snippet-Listing (snippet-source)

try {
    XCellRange range = xSpreadSheet_.getCellRangeByPosition(0,1,17,1);
    XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, range);
    xPropSet.setPropertyValue("CharWeight", new Double(FontWeight.BOLD));
    xPropSet.setPropertyValue("CellBackColor", new Integer(0xAAAAAA));
    xPropSet.setPropertyValue("HoriJustify",  CellHoriJustify.LEFT);
						
    XColumnRowRange xColRange = (XColumnRowRange)UnoRuntime.queryInterface(XColumnRowRange.class,range);
    XEnumerationAccess xEnumAccess = (XEnumerationAccess)UnoRuntime.queryInterface(XEnumerationAccess.class,xColRange.getColumns());
    XEnumeration xEnum = xEnumAccess.createEnumeration();
			
    Object tableColumnService;
			
    while( xEnum.hasMoreElements() ) {
        tableColumnService = xEnum.nextElement();
        xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, tableColumnService);
        xPropSet.setPropertyValue("OptimalWidth",new Boolean(true));
    }
} catch( Exception e) {
    e.printStackTrace();
}

Changelog

DateUserModification
2004-11-18tomsontomInitial version

and