Convert to Html with wrong img path in Linux

Hi there

I am using Aspose cells to convert Excel files to HTML files.

The result src of img tags in HTML seems not in right format (Only in Linux environment).

Here is my code for test:

Workbook book = new Workbook(“custom/input/xlsx/WCQX_Pusheen.xls”);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
// only one page for test
if (i != 0) {
book.getWorksheets().get(i).setVisible(false);
}
}
HtmlSaveOptions saveOps = new HtmlSaveOptions();

saveOps.setCreateDirectory(false);
saveOps.setExportActiveWorksheetOnly(false);
saveOps.setParseHtmlTagInCell(true);
saveOps.setEncoding(Encoding.getUTF8());
saveOps.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);
saveOps.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
saveOps.setExportImagesAsBase64(false);
saveOps.setExportHiddenWorksheet(false);

saveOps.setStreamProvider(new IStreamProvider() {

@Override
public void initStream(StreamProviderOptions arg0) throws Exception {
arg0.setStream(new ByteArrayOutputStream());
}

@Override
public void closeStream(StreamProviderOptions arg0)
throws Exception {
System.out.println(arg0.getDefaultPath());
}
});
book.save(baos, saveOps);
IOUtils.write(baos.toByteArray(), new FileOutputStream(
“custom/output/xlsx/stream.html”));


There will be a img tag like this:


The attribute src seems like the combination of “/tmp” and "image000.gif"

From System output:

System.out.println(arg0.getDefaultPath());

“image000.gif” showed up.

So, the String of src might be made inappropriately.


Please check the file in attachment, thanks :slight_smile:
Hi Craig,

Thank you for sharing the sample.

I have evaluate the presented scenario in CentOS 6.5 against the latest revision of Aspose.Cells for Java 8.9.0, and I am able to notice the said problem, that is; SRC attribute for the IMG tag is not correctly formed. Moreover, the issue seems to happen in Linux environment only as the SRC attribute is correctly formed if the conversion is done in Windows (I have tested it in Windows 10 x64). I have logged this incident as CELLSJAVA-41929 for further analysis by the product team. Please spare us little time, in the meanwhile, we will keep you posted with updates in this regard.

@craig.w.su,

Please try our latest version/fix(attached): Aspose.Cells for Java v21.8.5:
aspose-cells-21.8.5-java.zip

When implement IStreamProvider, it needs to set StreamProviderOptions.CustomPath to link the image while exporting htm.

Please try the following code with our latest version/fix:

Workbook book = new Workbook("custom/input/xlsx/WCQX_Pusheen.xls");
ByteArrayOutputStream baos = new ByteArrayOutputStream();

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
    // only one page for test
    if (i != 0) {
        book.getWorksheets().get(i).setVisible(false);
    }
}
HtmlSaveOptions saveOps = new HtmlSaveOptions();

saveOps.setCreateDirectory(false);
saveOps.setExportActiveWorksheetOnly(false);
saveOps.setParseHtmlTagInCell(true);
saveOps.setEncoding(Encoding.getUTF8());
saveOps.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);
saveOps.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
saveOps.setExportImagesAsBase64(false);
saveOps.setExportHiddenWorksheet(false);

saveOps.setStreamProvider(new IStreamProvider() {

    OutputStream _outstream;

    @Override
    public void initStream(StreamProviderOptions arg0) throws Exception {
        String outPath = "custom/output/xlsx/stream_html_files" + arg0.getDefaultPath();
        arg0.setCustomPath(outPath);
        _outstream = new FileOutputStream(outPath);
        arg0.setStream(_outstream);
    }

    @Override
    public void closeStream(StreamProviderOptions arg0)
            throws Exception {
        if(_outstream != null)
        {
            _outstream.close();
        }
        System.out.println(arg0.getDefaultPath());
    }

});
book.save(baos, saveOps);

IOUtils.write(baos.toByteArray(), new FileOutputStream("custom/output/xlsx/stream.html"));

Let us know if you still find any issue.