Convert XLS to html using java

Java, C++, C#, Delphi, ??? - Using the UNO bridges

Convert XLS to html using java

Postby sixlove » Mon Mar 12, 2012 8:44 pm

I have managed to convert xls to html using OO api in java. However the images are not on the converted html. I would like to store the images in the same way the OO UI application stores the images when I export to html i.e "<img style="height:1.682cm;width:5.4559cm;" alt="" src="data:image/*;base64,iVBORw0KGgoAAAANSUhEUg...."

Below is my code. Please help.

Code: Select all   Expand viewCollapse view
XMultiComponentFactory xMultiComponentFactory = xComponentContext.getServiceManager();
        Object desktopService = xMultiComponentFactory.createInstanceWithContext("", xComponentContext);
        XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktopService);
        PropertyValue[] conversionProperties = new PropertyValue[3];
        conversionProperties[0] = new PropertyValue();
        conversionProperties[1] = new PropertyValue();
        conversionProperties[2] = new PropertyValue();

        conversionProperties[0].Name = "InputStream";
        conversionProperties[0].Value = input;
        conversionProperties[1].Name = "Hidden";
        conversionProperties[1].Value = new Boolean(true);
        conversionProperties[2].Name  = "IsExportContentsPage" ;
        conversionProperties[2].Value = false;

        XComponent document = xComponentLoader.loadComponentFromURL("private:stream", "_blank", 0, conversionProperties);

        conversionProperties[0].Name = "OutputStream";
        conversionProperties[0].Value = output;
        conversionProperties[1].Name = "FilterName";
        conversionProperties[1].Value = filterName;

        XStorable xstorable = (XStorable) UnoRuntime.queryInterface(XStorable.class,document);
        xstorable.storeToURL("private:stream", conversionProperties);

        XCloseable xclosable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class,document);
OpenOffice 3.3.9 on MacOS 10.4
Posts: 1
Joined: Mon Mar 12, 2012 8:33 pm

Re: Convert XLS to html using java

Postby rudolfo » Wed Mar 14, 2012 10:07 pm

Not sure if I understand your code. I can't find any comment in there and Java tends to be a bit bloated when it comes to UNO objects. What I can guess is that you use .loadComponentFromURL() and storeToURL() to do the conversion. So you can only get what the "Save As" and "Export" functionality offers you. Have you tried to manually save a spreadsheet as HTML? Were the images included in that case? Typically I wouldn't expect the API to do more then a GUI menu does that is calling the API in the Application internally.

But as you are listing src="data:image/*;base64,iVBORw0KGgoAAAANSUhEUg...." you have probably looked into the zip archive and its XML files. So if you are not satisfied with what OpenOffice is doing for you, you can always grasp the OASIS documentation of the ODF format and write your own XSLT formatter. Have a look that this long discussion Create XSLT filters for import and export.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest