I was trying to create excel workbook to html file. It does create and work well while opening in browser. But found that in html code some of the html tags doesn’t have proper closing tags like the following
tags (link, meta, col tags) (pasted below). Attached the html file which is generated using aspose.
We use this html to do further conversion to other formats during which it fails as this html doesn’t have closing tags for these. Is there a way to generate these tags with closing tags like <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
as <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
Here is the code used to convert excel workbook to html
public byte[] convertToHtml(Workbook wb) throws Exception {
HtmlSaveOptions opts = new HtmlSaveOptions();
opts.setExportActiveWorksheetOnly(true);
opts.setExportImagesAsBase64(true);
ByteArrayOutputStream os = new ByteArrayOutputStream();
wb.save(os, opts);
///wb.save(destinationHtmlFile, opts);
return os.toByteArray();
}
Please note, Aspose.Cells follows MS Excel standards and specifications when parsing or rendering to HTML file format. I can see these meta heading tags are there (without closing tags) when you manually convert an Excel file to HTML (“Web Page”) in MS Excel manually. Aspose.Cells just follows MS Excel standards and cannot go beyond it, so these heading tags will be retained as they are.
Please provide input Excel file and output HTML file(s) generated by Aspose.Cells for evaluation. You may zip the files and attach it here, we will check it soon.
I tested your scenario/ case using your file to convert to HTML with the following sample code using latest version/fix: Aspose.Cells for Java v20.6.x, it works fine. I can see all styles/formattings (e.g style0 upto .x118) are declared in <head> tag. However, I noticed .x119 is pasted in the end although it is outside of <body> section, so it is ok:
e.g Sample code:
Workbook workBook = new Workbook("f:\\files\\MainReport_Template.xlsx");
HtmlSaveOptions opts = new HtmlSaveOptions();
opts.setExportActiveWorksheetOnly(true);
opts.setExportImagesAsBase64(true);
workBook.save("f:\\files\\outMainReport_Template1.html", opts);
Please find attached the output HTML file for your reference. files1.zip (12.2 KB)
Question is why is .x119 alone is coming outside of head tag at the end? I would want to have all styles inside head tag. Since .x119 is not within head tag and its within html tag, it does causes issue while rendering later using some other tool
@sunithaprabhu,
We have observed this issue where one of the style is found outside the head tag. This issue is logged in our database for an investigation and fix (if possible).
This issue is logged as: CELLSJAVA-43242 -One of the style tag found outside the head tag
Just to add to it, that style is used for the image tag.
Attached zip has excel and html for reference as the previous one doesn’t have the right style
@sunithaprabhu,
This is to inform you that we have fixed your issue (logged earlier as “CELLSJAVA-43242”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.