Page 1 of 1

Convert XLS to html using java

Posted: Mon Mar 12, 2012 8:44 pm
by sixlove
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

XMultiComponentFactory xMultiComponentFactory = xComponentContext.getServiceManager();
        Object desktopService = xMultiComponentFactory.createInstanceWithContext("com.sun.star.frame.Desktop", 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);
        xclosable.close(true);

Re: Convert XLS to html using java

Posted: Wed Mar 14, 2012 10:07 pm
by rudolfo
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.