We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Binding resources (xml,css) to html in Aspose Cell

Hi,

I’m converting xls / xlsx to HTML using aspose cell. its perfectly converting the document but in that conversion it splits (htm,css,.xml) as in seperate folder. Is there is any way to add it as inline html.

        private void generateXLS(String output, MemoryStream docStream)
        {
            Console.WriteLine("XLS ---------->");
            Aspose.Cells.License license = new Aspose.Cells.License();
            license.SetLicense(Path.GetFullPath(Directory.GetCurrentDirectory() + "//license//Aspose.Total.lic"));

            Workbook workbook = new Workbook(docStream);
            Aspose.Cells.HtmlSaveOptions htmlSaveOptions = new Aspose.Cells.HtmlSaveOptions();
            htmlSaveOptions.ExportGridLines = true;
            htmlSaveOptions.ExportImagesAsBase64 = true;
            htmlSaveOptions.ExportSimilarBorderStyle = true;
            htmlSaveOptions.ExportDocumentProperties = false;
            htmlSaveOptions.ExportWorkbookProperties = false;
            htmlSaveOptions.ExcludeUnusedStyles = true;
            htmlSaveOptions.DisableDownlevelRevealedComments = true;

            workbook.Save(output, htmlSaveOptions);
            Console.WriteLine("Done conversion ------------>");
        }

Screenshot 2019-12-11 at 11.28.58 AM.png (25.9 KB)

@pravnviji,
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:

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:

 //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

Thank you… Its working

@pravnviji,

Good to know that the suggested approach and code segment work for your needs. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.