You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Danny Mui <da...@muibros.com> on 2002/12/27 18:12:38 UTC
Using the Cocoon HSSFSerializer without Cocoon
Here's my test class to serialize a gnumeric-based xml file to Excel
using the HSSFSerializer
I'm using Jdom because it's simpler (imo) to manipulate xml but since it
implements the standard interfaces you can use any valid xml document.
==Snip=========================================================
public class poi
{
private static org.apache.avalon.framework.logger.Logger
avalonLogger = new
org.apache.avalon.framework.logger.ConsoleLogger(org.apache.avalon.framework.logger.ConsoleLogger.LEVEL_INFO);
/** Creates a new instance of poi */
public poi()
{
}
public static void main(String[] args){
java.io.File infile = new
java.io.File("e:\\development\\poi-test\\plsr.xml");
java.io.File outfile = new
java.io.File("e:\\development\\poi-test\\out.xls");
try {
outfile.createNewFile();
java.io.OutputStream fos = new
java.io.FileOutputStream(outfile);
org.jdom.input.SAXBuilder builder = new
org.jdom.input.SAXBuilder();
org.jdom.Document doc = builder.build(infile);
org.apache.cocoon.serialization.HSSFSerializer hssf = new
org.apache.cocoon.serialization.HSSFSerializer();
hssf.enableLogging(avalonLogger);
hssf.initialize();
hssf.setOutputStream(fos);
org.jdom.output.SAXOutputter saxOutput = new
org.jdom.output.SAXOutputter(hssf);
saxOutput.output(doc);
System.out.println("Done");
} catch (Exception e){
e.printStackTrace();
}
}
}