Free Support Forum -

Possibility of saving xlsx to html in single html file


I have a question regarding aspose cells for java. When saving excel file as html using HtmlSaveOptions, besides the main html file, new html file is created for every sheet in workbook. Is there any way to have only one html file which will hold all the content when saving xlsx file as html through aspose ?



Thanks for your query.

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 (MS Excel does the same thing). But you may still choose any of the following options to cope with it for your needs:

  1. Use MHtml file format as an output file format from Excel workbooks. It will generate single output file.

  2. 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 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 to set the relevant attribute(s)) otherwise it will create folders.

Hope, this helps a bit.

Thanks for your answer.

For option 2) : how can I save (export) every worksheet to single html? Is there any method for that, or you are reffering to these existing htmls which appear in resource folder?


See the sample (.NET) code for your reference, you may refer to it and write your code in Java accordingly. You may loop through each sheet in the workbook:
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.

I tried it, that’s what I needed. Thank you very much!


You are welcome.