Excel workbook to single HTML file conversion with Aspose.Cells for .NET API in C#

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.

@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.

1 Like

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

How can I do the above and get the html as the fixed html.
thankyou

@jarvis447,

As I mentioned in my previous reply, Aspose.Cells follows MS Excel standards and specifications in rendering Excel to HTML file format. 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 (render single HTML file) 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.
  1. Render Excel workbook to MHtml file format if it suits your needs.

Please note, it seems there is no concept of rendering fixed HTML in MS Excel. If you know MS Excel supports it, let us know with details and sample file, we will check it soon.