Convert html table to Excel file using Aspose.Cells for .NET in C#

Hi, I am using Aspose.cells to convert html tables into excel but they do not keep the borders, not also the background color. If I open the html file using excel software it renders the styles correctly. What might be the issue?

example.zip (26.0 KB)

@Pedro77,

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-46366 - Borders and background colors are missing while converting the HTML to XLSX

@Pedro77,

Please try our latest version/fix: Aspose.Cells for .NET v18.10.5:

Aspose.Cells18.10.5 For .Net2_AuthenticodeSigned.Zip (4.7 MB)
Aspose.Cells18.10.5 For .Net4.0.Zip (4.7 MB)

Your issue should be fixed in it.

Let us know your feedback.

excelExport.png (36.3 KB)

Hi, I am using Aspose.cells to convert html tables into excel but styles and image is not reflecting in excel which is of type xlsx format.

I am using aspose.cell version 18.

Below is the code to export :
string dir = @“directoryName”;
string FileName = “HCP_Fees_for_Services_and_Consultancy_20181114114513242.html”;
string inputfileName = dir + FileName;
string outputfileName = dir + “checkdatasa.xls”;
Aspose.Cells.HTMLLoadOptions hTMLLoad = new Aspose.Cells.HTMLLoadOptions(LoadFormat.Html);
hTMLLoad.IgnoreNotPrinted = true;

        if (File.Exists(inputfileName))
        {
            Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(inputfileName, hTMLLoad);
            Aspose.Cells.Worksheet worksheet = null;
            
            if (workbook != null)
            {
                worksheet = workbook.Worksheets[0];
                worksheet.PageSetup.PrintTitleRows = "$1:$3";
            }
            //workbook.Save(outputfileName,SaveFormat.Xlsx);
            worksheet.PageSetup.Orientation = Aspose.Cells.PageOrientationType.Portrait;
            worksheet.Workbook.Save(outputfileName);

@mzaman,

Thanks for the screenshot and code segment.

We need your template HTML file (you may zip it prior attaching) to evaluate your issue precisely. Please provide us your template HTML file, we will check it soon.

HCP_Fees_for_Services_and_Consultancy_20181114114513242.zip (2.1 KB)

Thanks for the quick reply. PFA zip html.

@mzaman,

Thanks for the template HTML file.

After an initial test, I am able to observe the issue as you mentioned by using your sample code with your template file. I found that formattings are lost in HTML to XLS rendering. I have logged a ticket with an id “CELLSNET-46447” for your issue. We will look into it soon.

Once we have an update on it, we will let you know here.

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

@mzaman,

Please try our latest version/fix: Aspose.Cells v18.11.4 (attached)

Your issue should be fixed in it.

We used the following sample code to test the new fix:
e.g
Sample code:

            string FileName = "HCP_Fees_for_Services_and_Consultancy_20181114114513242.html"; 
            string inputfileName = filePath + FileName; 
            string outputfileName = filePath + "checkdatasa.xls"; 

            Aspose.Cells.HTMLLoadOptions hTMLLoad = new Aspose.Cells.HTMLLoadOptions(LoadFormat.Html); 
            hTMLLoad.IgnoreNotPrinted = true;

           // add this line to get better result
            hTMLLoad.AutoFitColsAndRows = true;

            Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(inputfileName, hTMLLoad);
            Aspose.Cells.Worksheet worksheet = null;

            if (workbook != null)
            {
                worksheet = workbook.Worksheets[0];
                worksheet.PageSetup.PrintTitleRows = "$1:$3";
            }
            //workbook.Save(outputfileName,SaveFormat.Xlsx); 
            worksheet.PageSetup.Orientation = Aspose.Cells.PageOrientationType.Portrait;
            worksheet.Workbook.Save(outputfileName);

Aspose.Cells18.11.4 For .Net2_AuthenticodeSigned.Zip (4.7 MB)
Aspose.Cells18.11.4 For .Net4.0.Zip (4.7 MB)

Let us know your feedback.

HI support ,
Thanks for the solution ,but i am unable to download attached file?

Hi Support,
How will i get aspose.cells v18,11.4? because i could not download the attached files above.

@mzaman,

You may please try to download the libraries from the following links:
https://www.dropbox.com/s/v70wfrt5wwevscr/Aspose.Cells18.11.4%20For%20.Net4.0.Zip?dl=0
https://www.dropbox.com/s/48nc6jk7v9mxzie/Aspose.Cells18.11.4%20For%20.Net2_AuthenticodeSigned.Zip?dl=0

Hi Support ,
i appreciate that you solved this bug so quickly. Kudos!
One thing that image in html is still not coming in excel sheet.
Other is that width and height of the columns and rows differs in html to excel.
Thanks.

@mzaman,

When I open your template HTML file into the browser or Ms Excel, the image (rather linked image) is also not shown either, so the converted XLS file by Aspose.Cells also does not display the image. See the screenshot for your reference:

Well, we added a line to your code segment to make the view more compact:

// add this line to get better result
hTMLLoad.AutoFitColsAndRows = true;

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