Save , Save as HTML and Edit LibreOffice WorkBook without running LO

libreoffice.ge at gmail.com libreoffice.ge at gmail.com
Mon Mar 12 02:25:00 PDT 2012


Dear Admins and Community Members ,


As we informed earlier we are trying to Migrate from OOO Calc to LO Calc 
in  our J2EE software.One of the function we need is to " SAVE AS HTML" 
OOO|LO Calc Workbook .Now we are doing it using the code / method below.

ANY CHANCE TO DO IT WITHOUT RUNNING OOO/LO ?(Like POI can do with Excel 
Files.) . We are looking to http://www.jopendocument.org/ , but we are 
very new to LO so any recommendation is very welcome.


Thanks

Nick


public byte[] exportAsHtml(byte[] tempReportContent) {

byte[] htmlContent = null;

try {

log.info <http://log.info>("Exporting As Html");

XStorable xStorable = null;

Object desktop = null;

XComponent document = null;

xRemoteContext = getRemoteContext();

xRemoteServiceManager = xRemoteContext.getServiceManager();

// Get a desktop instance

desktop = 
xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", 
xRemoteContext);

// Get a reference to the desktop interface that can load files

XComponentLoader loader = (XComponentLoader) 
UnoRuntime.queryInterface(XComponentLoader.class, desktop);

XInputStream xStream = new 
ByteArrayToXInputStreamAdapter(tempReportContent);

PropertyValue[] args = new PropertyValue[2];

args[0] = new PropertyValue();

args[0].Name = "InputStream";

args[0].Value = xStream;

args[0].State = PropertyState.DIRECT_VALUE;

args[1] = new PropertyValue();

args[1].Name = "Hidden";

args[1].Value = new Boolean(true);

document = loader.loadComponentFromURL("private:stream", "_blank", 0, args);

ByteArrayOutputStream out = new ByteArrayOutputStream();

XOutputStream xOut = new OutputStreamToXOutputStreamAdapter(out);

PropertyValue[] args1 = new PropertyValue[2];

args1[0] = new PropertyValue();

args1[0].Name = "OutputStream";

args1[0].Value = xOut;

args1[0].State = PropertyState.DIRECT_VALUE;

args1[1] = new PropertyValue();

args1[1].Name = "FilterName";

args1[1].Value = "HTML (StarCalc)";

xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, 
document);

xStorable.storeAsURL("private:stream", args1);

xOut.flush();

htmlContent = out.toByteArray();

xOut.closeOutput();

} catch (Exception ex) {

log.error(ex.getMessage(), ex);

}

return htmlContent;

}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20120312/3ec43a39/attachment-0001.html>


More information about the LibreOffice mailing list