Hi Keith, You are right, the code assumes that you create the style in your template with OpenOffice. Is there a reason you would preffer to create it programmaticaly ?
A template is by nature done by humans that always preffers a GUI. It reminds me why MS Office won over LateX ;) >From our point of view, an automation is supposed to "inject values". The "freeze" is done this way because "freeze" is not in the OpenDocument specification, but is a feature provided by OpenOffice. That's why you see the prefix "ooo:". Regards, Guillaume 2009/5/14 FM MIS <[email protected]> > Hi Sylvain and thanks very much for your help and examples. > > Couple of questions: 1). Your example presumes a template based approach, > which is OK, but I was hoping for a fully programmatic approach if its > possible. But your example does seem to point me in the direction I need to > go, presuming I can create the style through code. 2). I'm presuming that > the reason for the way to are doing the freeze is that the api doesn't > directly approach this concept (at least yet)? > > Thanks again > > Keith > > On Thu, May 14, 2009 at 12:02 PM, Sylvain Cuaz < > [email protected]> wrote: > >> 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")); >> } >> } >> >> >
