Rendering images as EMF or SVG type in Excel to HTML conversion

Hello,

When exporting a Worksheet to HTML, is not possible to specify the desired Image Type for Shapes/Charts that exist within the worksheet.

This can be reproduced via the latest Aspose Cells version 19.12, the attached DataAndChart.xlsx Workbook and the following code:

final String wbFile =  [PATH] + "DataAndChart.xlsx";

Workbook wb = new Workbook(wbFile);
wb.getWorksheets().setActiveSheetIndex(0);

// export the worksheet
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
options.setEncoding(Encoding.getUTF8());
options.setPresentationPreference(true);
options.setExportActiveWorksheetOnly(true);
options.setExportImagesAsBase64(true);

// *tries* to set the Chart Shape to EMF @ 300DPI, but results in PNG
ImageOrPrintOptions imgOptions = options.getImageOptions();
imgOptions.setImageType(ImageType.EMF);
imgOptions.setHorizontalResolution(300);
imgOptions.setVerticalResolution(300);

String htmlFile = wbFile.replace(".xlsx", ".html");
Files.deleteIfExists(Paths.get(htmlFile));
wb.save(htmlFile, options);
System.out.println("Saved new file: " + htmlFile);

After running the code above, if you open the newly generated “DataAndChart.html” file in a text editor, you should see the base64 encoded image is in PNG format per:
<img width='448' height=288' src="data:image/png;base64,...

Also, if you render the HTML file in any Browser and inspect the Chart, the Browser confirms it is in PNG format:
ImageProps.png (41.7 KB)

Note that in the code example above, we specified that we wanted the image to be in EMF format. But ideally we’d actually prefer to specify SVG format. Unfortunately, if you replace the code above with: imgOptions.setImageType(ImageType.SVG); - the following exception is thrown:

java.lang.IllegalStateException: Unexpected image type.
  at com.aspose.cells.zanv.a(Unknown Source)
  at com.aspose.cells.ImageOrPrintOptions.getImageFormat(Unknown Source)
  ...

To summarize, it seems there are two issues:

  1. The setImageType setting is being ignored by the HtmlSaveOptions instance.
  2. The ImageType.SVG setting throws an exception when exporting to HTML.

All relevant files are attached in: Html_ImageType.zip (73.4 KB)

Thank you.

@oraspose,
We have analysed the scenario and observed that specified image type is not followed and also SVG raises exception however we need to look into these issues more. We have logged the issues in our database for investigation and for a fix (if applicable). Once, we will have some news for you, we will update you in this topic.

This issues have been logged as

CELLSJAVA-43076 – Set image type EMF in the rendered HTML file
CELLSJAVA-43077 – Exception "Unexpected image type" raised while rendering worksheet to Html

@oraspose,

This is to inform you that we have fixed your issue “CELLSJAVA-43077” now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@oraspose,
This is to inform you that we have fixed your issue “CELLSJAVA-43076” now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@oraspose,

Please try our latest version/fix: Aspose.Cells for Java v20.1.1:
aspose-cells-20.1.1-java.zip (6.8 MB)

Your issues (“CELLSJAVA-43076” and “CELLSJAVA-43077”) should be fixed in it. For the issue “CELLSJAVA-43076”, please note:

  1. Base64 format does not/cannot support EMF (data:image/emf) format. so we will use PNG as default format.
  2. We have supported SVG, Jpeg and GIF formats. You can use these formats to implement your requirements accordingly.

Let us know your feedback.

Hi Amjad.
Thank you very much for looking into this and fixing it. The HTML with embedded SVG looks very good. As stated, we really prefer SVG - so not having Base64 encoded EMF is not a big deal. We are happy with the SVG results!

Thank you again.

@oraspose

Good to know that your issue(s) are sorted out by the new fix/version. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

The issues you have found earlier (filed as CELLSJAVA-43076,CELLSJAVA-43077) have been fixed in Aspose.Cells for Java v20.2. This message was posted using Bugs notification tool by ahsaniqbalsidiqui