<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2654.45">
<TITLE>RE: [jdom-interest] Building and XML Spreadsheet for Microsoft Excel - Office XP Prof essional</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Hi Per</FONT>
</P>
<P><FONT SIZE=2>You a champ, this worked like a charm.</FONT>
</P>
<P><FONT SIZE=2>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.</FONT></P>
<P><FONT SIZE=2> Namespace ns = Namespace.getNamespace("urn:schemas-microsoft-com:office:spreadsheet");</FONT>
<BR><FONT SIZE=2> Namespace o = Namespace.getNamespace("o","urn:schemas-microsoft-com:office:office");</FONT>
<BR><FONT SIZE=2> Namespace x = Namespace.getNamespace("x","urn:schemas-microsoft-com:office:excel");</FONT>
<BR><FONT SIZE=2> Namespace dt = Namespace.getNamespace("dt", "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882");</FONT>
<BR><FONT SIZE=2> Namespace ss = Namespace.getNamespace("ss", "urn:schemas-microsoft-com:office:spreadsheet");</FONT>
<BR><FONT SIZE=2> Namespace html = Namespace.getNamespace("html", "<A HREF="http://www.w3.org/TR/REC-html40" TARGET="_blank">http://www.w3.org/TR/REC-html40</A>");</FONT>
<BR><FONT SIZE=2> </FONT>
<BR><FONT SIZE=2> Element wb = new Element("Workbook", ns);</FONT>
<BR><FONT SIZE=2> wb.addNamespaceDeclaration(o);</FONT>
<BR><FONT SIZE=2> wb.addNamespaceDeclaration(x);</FONT>
<BR><FONT SIZE=2> wb.addNamespaceDeclaration(dt);</FONT>
<BR><FONT SIZE=2> wb.addNamespaceDeclaration(ss);</FONT>
<BR><FONT SIZE=2> wb.addNamespaceDeclaration(html);</FONT>
<BR><FONT SIZE=2> Document doc_out = new Document(wb);</FONT>
</P>
<P><FONT SIZE=2>Regards</FONT>
<BR><FONT SIZE=2>Ben</FONT>
</P>
<BR>
<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: Per Norrman [<A HREF="mailto:pernorrman@telia.com">mailto:pernorrman@telia.com</A>] </FONT>
<BR><FONT SIZE=2>Sent: Thursday, November 13, 2003 1:46 PM</FONT>
<BR><FONT SIZE=2>To: 'Ben Brand'; jdom-interest@jdom.org</FONT>
<BR><FONT SIZE=2>Subject: SV: [jdom-interest] Building and XML Spreadsheet for Microsoft Excel - Office XP Prof essional</FONT>
</P>
<BR>
<P><FONT SIZE=2>Hi,</FONT>
</P>
<P><FONT SIZE=2>Always used namespaces when creating elements. Add namespace declarations as necessary to the root element.</FONT>
</P>
<P><FONT SIZE=2>For example:</FONT>
<BR><FONT SIZE=2>-------------------------------------------------------------</FONT>
<BR><FONT SIZE=2>import org.jdom.Document;</FONT>
<BR><FONT SIZE=2>import org.jdom.Element;</FONT>
<BR><FONT SIZE=2>import org.jdom.Namespace;</FONT>
<BR><FONT SIZE=2>import org.jdom.output.XMLOutputter;</FONT>
</P>
<P><FONT SIZE=2>public class Excel {</FONT>
</P>
<P> <FONT SIZE=2>public static void main(String[] args) throws Exception {</FONT>
<BR> <FONT SIZE=2>Namespace ns =</FONT>
<BR> <FONT SIZE=2>Namespace.getNamespace(</FONT>
<BR>
<BR><FONT SIZE=2>"urn:schemas-microsoft-com:office:spreadsheet");</FONT>
<BR> <FONT SIZE=2>Namespace o =</FONT>
<BR> <FONT SIZE=2>Namespace.getNamespace(</FONT>
<BR> <FONT SIZE=2>"o",</FONT>
<BR> <FONT SIZE=2>"urn:schemas-microsoft-com:office:office");</FONT>
</P>
<P> <FONT SIZE=2>Element wb = new Element("Workbook", ns);</FONT>
<BR><FONT SIZE=2> wb.addContent(new Element("OfficeStuff", o));</FONT>
<BR><FONT SIZE=2> wb.addContent(new Element("ExcelStuff", ns));</FONT>
<BR> <FONT SIZE=2>wb.addNamespaceDeclaration(o);</FONT>
</P>
<P> <FONT SIZE=2>new XMLOutputter(" ", true).output(new Document(wb),</FONT>
<BR><FONT SIZE=2>System.out);</FONT>
</P>
<P> <FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>/pmn</FONT>
</P>
</BODY>
</HTML>