Free Support Forum - aspose.com

Excel Conversion

HI Team,

My requirement is, I need to convert Excel into HTMl without distortion of style and again regenerate Excel xlsx back from HTML …Thus after conversion and regeneration both excel files should look same.

for Html Conversion I am using following code

Aspose.Cells.Workbook excel = new Aspose.Cells.Workbook(Root+“demoExcel.xlsx”);
Aspose.Cells.HtmlSaveOptions options = new Aspose.Cells.HtmlSaveOptions();
options.Encoding = System.Text.Encoding.UTF8;
options.ExportImagesAsBase64 = true;
options.ExportGridLines = true;
options.ExportSimilarBorderStyle = true;
options.ExportFrameScriptsAndProperties = true;
options.ExportBogusRowData = true;
options.ExportHiddenWorksheet = true;

using this process I am getting HTML in good format…

please guide me how to regenerate xlsx back from HTML.

I can also use this flow

  1. xlsx to pdf :- as here I am having option for each sheet as one page of pdf…that’s very good
  2. pdf to html:- html conversion is perfect.

now using this html how can I get back to xlsx…

@kotharib2,

You can convert HTML file to an XLSX file with below code:

    HTMLLoadOptions loadOptions = new HTMLLoadOptions(Aspose.Cells.LoadFormat.Html);
    Workbook wb = new Workbook("Test.html", loadOptions);
    wb.Save("Test_18.9.2.xlsx"); 

There may be some differences as HTML and XLSX are different file formats and the conversion may not have 100% fidelity. If you notice problems then share the files and we will investigate it on our end.

  1. At the time of Html Conversion I am getting an extra folder containing css file and individual sheets…I don’t want that…I want to avoid creation of extra folder…need only single html with all sheet.

  2. After regeneration from HTML …even though options.ExportGridlines is ‘true’…for some sheet it failed to show grid lines…

please check original xlsx file, html file with its folder and regenerated file for your reference.Document.zip (27.9 KB)

@kotharib2,

  1. Regarding the extra folders, if we convert source XLSX file “demoExcel.xlsx” to HTML using EXCEL, it also creates these extra folders. Please share steps to create ONLY html using Excel with us. We will try to provide you assistance to perform same task using Aspose.Cells.

  2. We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46371 - Grid lines not displayed in some sheets while converting XLSX->HTML->XLSX

HI @ahsaniqbalsidiqui

this is the code I am trying to use for html conversion…

Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(LicensePath);
Aspose.Cells.Workbook excel = new Aspose.Cells.Workbook(filename);
Aspose.Cells.HtmlSaveOptions options = new Aspose.Cells.HtmlSaveOptions();
options.Encoding = System.Text.Encoding.UTF8;
options.ExportImagesAsBase64 = true;
options.ExportDocumentProperties = true;
options.ExportGridLines = true;
options.ExportSimilarBorderStyle = true;
options.ExportWorksheetProperties = true;
options.ExportWorkbookProperties = true;
options.ExportFrameScriptsAndProperties = true;
options.ExportBogusRowData = true;
options.ExportHiddenWorksheet = true;
excel.Save(Root + folderName + “.html”, options);

@kotharib2,

Thank you for providing more information. We have added this additional code to the logged ticket for our later reference. We will write back here as soon as some feedback is ready to share.

okay,

I found no solution …hope so this ticket will get resolved sooner

Thanks for your efforts

@kotharib2,

You are welcome.

@kotharib2,

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 choose any of the following options to cope with it:

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

@kotharib2,

This is to inform you that we have fixed your issue (logged earlier as “CELLSNET-46371”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@kotharib2,

Please try our latest version/fix: Aspose.Cells for .NET v18.11.2 (attached)

Your issue should be fixed in it.

Let us know your feedback.
Aspose.Cells18.11.2 For .Net2_AuthenticodeSigned.Zip (4.7 MB)
Aspose.Cells18.11.2 For .Net4.0.Zip (4.7 MB)

The issues you have found earlier (filed as CELLSNET-46371) have been fixed in Aspose.Cells for .NET v18.12. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi