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:
- The
setImageType
setting is being ignored by theHtmlSaveOptions
instance. - 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.