Mis At FMCorp a écrit :
What I need to now is format a spreadheet. Specifically I would like
to set the format of the top row to Bold (as in a header row) and set
the freeze point to force the headers to always be shown when the user
scrolls the data.
Hi,
The easiest thing to do to apply styles, is to first define them in
OpenOffice (via the F11 shortcut). Then you just call setStyleName()
with the name you gave it. The vertical split is not standard but I've
included in the attachement how OO does it.
HTH,
Sylvain.
import java.io.File;
import java.io.IOException;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.xpath.XPath;
import org.jopendocument.dom.spreadsheet.Sheet;
import org.jopendocument.dom.spreadsheet.SpreadSheet;
public class Example {
public static void main(String[] args) throws IOException, JDOMException {
final SpreadSheet spread = SpreadSheet.createFromFile(new
File(args[0]));
final Sheet sheet = spread.getSheet(0);
// set a style defined in OpenOffice
sheet.getCellAt("A1").setStyleName("myBoldStyle");
// the vertical split is not part of OpenDocument, but this how
OpenOffice uses it
// see the whole settings.xml for more
final XPath xp = spread
.getXPath("./office:settings/config:config-item-s...@config:name='ooo:view-settings']/config:config-item-map-index...@config:name='Views']//config:config-item-map-ent...@config:name=$sheetName]");
xp.setVariable("sheetName",
sheet.getElement().getAttributeValue("name", spread.getNS().getTABLE()));
final Element sheetSettings = (Element)
xp.selectSingleNode(spread.getPackage().getDocument("settings.xml").getRootElement());
final Element splitMode = (Element)
spread.getXPath("./config:config-it...@config:name='VerticalSplitMode']").selectSingleNode(sheetSettings);
// 0 to disable
splitMode.setText("1");
final Element splitPos = (Element)
spread.getXPath("./config:config-it...@config:name='VerticalSplitPosition']").selectSingleNode(sheetSettings);
// height in pixels
splitPos.setText("64");
spread.saveAs(new File("out"));
}
}