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

Free Support Forum - aspose.com

A problem when converting Excel to Html

I have a (named) outer range which contains another one, inner range (ListObject, or table to be exact).
The inner range (table) has its own style set like this:
table.TableStyleType = TableStyleType.TableStyleDark4;
On outer range I set border like this:
range.SetOutlineBorder(Aspose.Cells.BorderType.TopBorder, CellBorderType.Thick, Color.Blue);
… (other border Type follow)
Now, when I save this as .xlsx everything looks fine - the outer border is thick & blue.
However, when I save as html, the table border style (on each cell level) gets merged with outer range border style … .
Is there any way to code this so that styles of outer objects border would NOT effect the inner range (table) style?

@bogdanw,

Thanks for some details.

When you save an Excel spreadsheet to HTML, some formattings/style might be lost/effected in certain cases. Anyways, could you provide us your template XLSX file or output/saved XLSX file (by Aspose.Cells APIs), we will check it soon.

Got it working.
In my case, the problem was caused by having multiple worksheets.
That is, when saving data to Html format I reused the same instance of “HtmlSaveOptions” object.
Once I created a new one with different value on CellCssPrefix property for each worksheet problem disappeared.
However!
A new problem popped up - I noticed that empty cells in tables do not get proper border formatting upone exporting to Html.
Trying to “fix” it by putting " " in empty cells but I see the text upon exporting.
Any suggestion on how to overcome this?

@bogdanw,

Good to know that your previous issue is sorted out now.

Could you provide us your template files (input and output files) and sample code (runnable) to show the issue, we will check it soon.

2 posts were split to a new topic: Output Excel File is Corrupt

Shakeel,
first off, sorry for this “corrupt excel file” problem. In testing, I was focus on the resulting .html file and I never opened .xlsx one. Indeed, .xlsx opens with “file is corrupted” message but this seems to be another Aspose issue. Please note that no error results (nor warning messages is fired when saving) in running this code. The problem is (or appears to be) that in the old code one of the table header was left empty. After populating it I see no more “file is corrupt” error. But this is a SIDE ISSUE for me at this moment. I can get around it. The real issue is (as I describe above) that table cells which have no value do not have properly formatted borders.
Below is new code (the same as above I just took care that table header cells have values).
Run the code, open .html file and look at cells in the first column please.
They are not formatted in the same way as cells which have values.
I want all cells in the table to be formatted in the same way.
Here is the code:

Workbook wb = new Workbook();
        Worksheet ws = wb.Worksheets[0];

        var outerRange = ws.Cells.CreateRange(0, 0, 10, 10);
        outerRange.SetOutlineBorder(Aspose.Cells.BorderType.TopBorder, CellBorderType.Thick, Color.Blue);
        outerRange.SetOutlineBorder(Aspose.Cells.BorderType.BottomBorder, CellBorderType.Thick, Color.Blue);
        outerRange.SetOutlineBorder(Aspose.Cells.BorderType.LeftBorder, CellBorderType.Thick, Color.Blue);
        outerRange.SetOutlineBorder(Aspose.Cells.BorderType.RightBorder, CellBorderType.Thick, Color.Blue);

        var innerRange = ws.ListObjects[ws.ListObjects.Add(3, 3, 6, 6, true)];
        for(int r = 0; r < 4; r ++)
        {
           for( int c = 0; c < 4; c++)
           {
                if ((r == 0) || (c > 0))
                    ws.Cells[innerRange.StartRow + r, innerRange.StartColumn + c].PutValue(r + c);
                else
                    ws.Cells[innerRange.StartRow + r, innerRange.StartColumn + c].PutValue(string.Empty);
            }
        }
        innerRange.TableStyleType = TableStyleType.TableStyleDark4;

        var myDir = @"MyDirHere";
        wb.Save(myDir + "TestAsPoseExcel.xlsx");

       HtmlSaveOptions saveOptions = new HtmlSaveOptions();
       //saveOptions.WarningCallback = new TestWaring();
       wb.Save(myDir + "TestAsPoseExcel.xlsx", saveOptions);

@bogdanw

Thanks for your sample code and using Aspose APIs.

Please check the Output Excel and HTML Files generated by the code. We do not see any difference in both files. Please see the screenshot given below for comparison. Please highlight your issues with some screenshots so that we could find the problem easily.

Download Link:
sc.png (70.9 KB)
Output Excel and HTML Files.zip (8.9 KB)

Screenshot:

Interesting. My excel file looks the same but html has borders. See the attached pictures please.
Have you changed something in the most recent release? Could it be Office version related?
Attaching images.
TestAsPoseExcel_1_Html.PNG (2.2 KB)
TestAsPoseExcel_1_Xlsx.PNG (16.9 KB)

Well, it looks like this is browser related rather.
The picture I attached in the post above came from MS Edge (the same problem is in IE).
Just checked the same file in Chrome and it looks like yours.
Still, do you have some flags/properties/methods I could call somewhere to fix in in IE?

@bogdanw

We were able to observe this issue as per your description and logged it in our database for investigation and for a fix. Once, the issue is resolved or we have some other news for you, we will update you asap.

This issue has been logged as

  • CELLSNET-46127 - Output HTML is good in Chrome but wrong in IE or Edge

Great.
Let me know please if you come up with a heck around this problem.
Also, consider adding another issue - the one where .xlsx file comes as corrupt (though no error is raised) when a table header cell has no value.

@bogdanw

This issue has been logged as CELLSNET-46128. Please see this topic for detail.

@bogdanw

Thanks for using Aspose APIs.

This is to inform you that we have fixed your issue CELLSNET-46127 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

@bogdanw

Please download and try the following fix for your issue CELLSNET-46127 and let us know your feedback.

Hi there,
good work!.
I have another question though, this time it is about DateTime colums in a table (ListObject).
It appears that when I put a DateTime instance in a cell it is converted to “Excel Numeric Date”, that is it is number of days since 1/1/1900. Is there any flag to avoid this automatic conversion?
Sample code below. Please open the resulting file and look at the first column.
Thx,
Bogdan

private static void TestAsPose()
    {
        Workbook wb = new Workbook();
        Worksheet ws = wb.Worksheets[0];
        var innerRange = ws.ListObjects[ws.ListObjects.Add(3, 3, 6, 6, true)];
        for (int r = 0; r < 4; r++)
        {
            for (int c = 0; c < 4; c++)
            {
                if (r == 0)
                {
                    var cellValue = (r + c);
                    ws.Cells[innerRange.StartRow + r, innerRange.StartColumn + c].PutValue(cellValue);
                }
                if ((r >= 1) && (c == 0))
                {
                    //var cellValue = DateTime.Now.ToLongDateString(); // <-- if you uncomment this //line and comment the one below everything works fine but I do not want to change data type //since I may generated totals
                    var cellValue = DateTime.Now;
                    ws.Cells[innerRange.StartRow + r, innerRange.StartColumn + c].PutValue(cellValue);
                }
                else
                {
                    var cellValue = r + c;
                    ws.Cells[innerRange.StartRow + r, innerRange.StartColumn + c].PutValue(cellValue);
                }
            }
        }
        innerRange.TableStyleType = TableStyleType.TableStyleDark4;

        var myDir = @"YourDirHere";
        wb.Save(myDir + "TestAsPoseExcel.xlsx");

        HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        wb.Save(myDir + "TestAsPoseExcel.xlsx", saveOptions);
    }

@bogdanw

Thanks for using Aspose APIs.

Dates are stored as numbers in Excel file. It is by the style of cell that Excel recognizes if the number stored is Date or not.

Please add the following code snippet in your existing code and it will generate correct output Excel and HTML files.

Download Link:
Output Excel and HTML files.zip (8.5 KB)

C#

//-------------------------
StyleFlag flg = new StyleFlag();
flg.NumberFormat = true;

Style st = ws.Cells["D5"].GetStyle();
st.Number = 14; //14 means Date

Range rng = ws.Cells.CreateRange("D5:D7");
rng.ApplyStyle(st, flg);
//-------------------------

The issues you have found earlier (filed as CELLSNET-46127) have been fixed in Aspose.Cells for .NET 18.6. Please also check the document/article for your reference: https://docs.aspose.com/display/cellsnet/Installation