Convert to single HTML file


#1

Hi,

I wanted to ask if it is possible to convert a workbook into a single HTML file, similar to the SaveFormat.HtmlFixed in Aspose.Words. If I save an excel file as html it will generate a folder for the sheets. I also checked the HtmlSaveOptions but found anything.
I am aware of the MHTML SaveFormat, however the generated files are not displayed correctly in Chrome browser and Firefox also only opens a save as dialog when opening a local file. This is also the case if I generate them with MS Excel itself.

Is there a soloution to convert a workbook to a single file which works with the common browsers?

Kind regards,
Daniel.


#2

@Serraniel,

Well, Aspose.Cells follows Ms Excel standards and specifications in rendering Excel to HTML file format, so by default it will create folder containing the resource files against worksheets in the workbook. But you may still choose the following option/approach to accomplish the task and cope with it:

  1. Try to export every worksheet (in the workbook) to single HTML and then group these individual HTMLs to one (final) HTML by yourselves via e.g some tag control or using your own code. In a loop, you may set active for each sheet and then render separate HTML file (based on every worksheet) via Aspose.Cells APIs. Please note, when exporting every worksheet to separate HTML, you would need to export image as base64 format (you will use HtmlSaveOptions class here) otherwise it will create folders. See the sample code for your reference:
    e.g
    Sample code:

     //Load your sample workbook
     Workbook wb = new Workbook(“e:\test2\Book1.xlsx”);
    
     //Specify HtmlSaveOptions
     //Export image as bytes (base 64) as inline images
     //Export active worksheet only
     HtmlSaveOptions opts = new HtmlSaveOptions();
     opts.ExportImagesAsBase64 = true;
     opts.ExportActiveWorksheetOnly = true;//You may activate one sheet at a time.
    
     //Save the workbook in HTML format with above HtmlSaveOptions
     wb.Save(“e:\test2\out1.html”, opts);
    

Hope, this helps a bit.


#3

Thanks for your feedback, this will probably help us :+1: