Convert Excel file to single HTML file with no outside resources like (css, js,img) using Aspose.Cells for .NET in C#

can i convert excel to html just one html file with no outsite resources(css,js,img)?

i don’t want to use the frame mode,thank you for your answer!

@yuweiming314,

MS Excel allows you to save the Excel file to Single File Webpage and same can be achieved with Aspose.Cells API.

// Load your source workbook
Workbook workbook = new Workbook(filePath);

// Save in Excel2007 xlsx format
workbook.Save(dataDir + ".output.mhtml", Aspose.Cells.SaveFormat.MHtml);

Hope, this helps a bit.

thank you for your answer,
but as i know mhtml file only supported by IE, isn’t it?

@yuweiming314,

You are right. However, this is the only option available in MS Excel. Please let us know if you are able to achieve it any other way using MS Excel so that we can investigate.

@yuweiming314,

As Ahsan Iqbal told you that 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 try the following approach to cope with it for your needs:

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, etc. 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 (the code is provided in .NET, you may easily convert it to Java (if required)):
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.