Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

RE: [jdom-interest] Building and XML Spreadsheet for Microsoft Ex
 cel - Office XP Prof essional

Ben Brand

2003-11-13


RE: [jdom-interest] Building and XML Spreadsheet for Microsoft Excel - Office XP Prof essional

Hi Per

You a champ, this worked like a charm.

At the moment I am not sure if the name space is generic, especially the uuid seems a bit suspect, but I have copied the complete code here for all to use. I might be back with some more remarks once I have investigated the whole project.

            Namespace ns = Namespace.getNamespace("urn:schemas-microsoft-com:office:spreadsheet");
            Namespace o = Namespace.getNamespace("o","urn:schemas-microsoft-com:office:office");
            Namespace x = Namespace.getNamespace("x","urn:schemas-microsoft-com:office:excel");
            Namespace dt = Namespace.getNamespace("dt", "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882");
            Namespace ss = Namespace.getNamespace("ss", "urn:schemas-microsoft-com:office:spreadsheet");
            Namespace html = Namespace.getNamespace("html", "http://www.w3.org/TR/REC-html40");
           
            Element wb = new Element("Workbook", ns);
            wb.addNamespaceDeclaration(o);
            wb.addNamespaceDeclaration(x);
            wb.addNamespaceDeclaration(dt);
            wb.addNamespaceDeclaration(ss);
            wb.addNamespaceDeclaration(html);
            Document doc_out = new Document(wb);

Regards
Ben


-----Original Message-----
From: Per Norrman [mailto:pernorrman@telia.com]
Sent: Thursday, November 13, 2003 1:46 PM
To: 'Ben Brand'; jdom-interest@jdom.org
Subject: SV: [jdom-interest] Building and XML Spreadsheet for Microsoft Excel - Office XP Prof essional


Hi,

Always used namespaces when creating elements. Add namespace declarations as necessary to the root element.

For example:
-------------------------------------------------------------
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.output.XMLOutputter;

public class Excel {

        public static void main(String[] args) throws Exception {
                Namespace ns =
                        Namespace.getNamespace(
       
"urn:schemas-microsoft-com:office:spreadsheet");
                Namespace o =
                        Namespace.getNamespace(
                                "o",
                                "urn:schemas-microsoft-com:office:office");

                Element wb = new Element("Workbook", ns);
            wb.addContent(new Element("OfficeStuff", o));
            wb.addContent(new Element("ExcelStuff", ns));
                wb.addNamespaceDeclaration(o);

                new XMLOutputter("   ", true).output(new Document(wb),
System.out);

        }
}

/pmn

©2008 junlu.com - Jax Systems, LLC, U.S.A.