Gridlines don't appear in html conversion

Hi,

I was trying to get force gridlines to appear in our html documents by using the ExportGridlines property and IsGridlinesVisible property. I noticed two bugs with this:

  1. The gridlines only appear if the aspose license is set

  2. The gridlines don’t appear if there are more than 1 worksheet and the ExportActiveWorksheetOnly property is set to true.

         //if the license isn't set, gridlines do not appear at all
         var excel = new Aspose.Cells.License();
         excel.SetLicense("Aspose.Total.lic");
    
         //this works as expected because there is 1 worksheet
         var workbookStream1 = new FileStream("gridlines_off_1worksheet.xls", FileMode.Open);
         var workbook1 = new Workbook(workbookStream1);
         var saveOptions1 = new HtmlSaveOptions { ExportImagesAsBase64 = true, ExportActiveWorksheetOnly = true, ExportGridLines = true };
         workbook1.CalculateFormula();
         workbook1.Worksheets[workbook1.Worksheets.ActiveSheetIndex].IsGridlinesVisible = true;
         workbook1.Save(@"..\1worksheetForceGridlinesOn.html", saveOptions1);
    
         //same workbook with a second blank worksheet, this only works if the ExportActiveWorksheetOnly property is set to false
         var workbookStream2 = new FileStream("gridlines_off_2worksheets.xls", FileMode.Open);
         var workbook2 = new Workbook(workbookStream2);
         var saveOptions2 = new HtmlSaveOptions { ExportImagesAsBase64 = true, ExportActiveWorksheetOnly = true, ExportGridLines = true };
         workbook2.CalculateFormula();
         workbook2.Worksheets[workbook2.Worksheets.ActiveSheetIndex].IsGridlinesVisible = true;
         workbook2.Save(@"..\2worksheetsForceGridlinesOn.html", saveOptions2);
    

WorkbookReproducers.zip (12.5 KB)

@dfactset

Thanks for using Aspose APIs.

ExportActiveWorksheetOnly is only valid when you set a license. Without license, only Evaluation Warning sheet be set as active worksheet.

Please see the following sample code, its sample Excel file and output HTML file. Everything is fine and the code was executed without setting a license.

The code was tested with Aspose.Cells for .NET 17.11.6.

Download Links:
Input Excel File.zip (6.1 KB)
OutputGridLines.zip (9.9 KB)

C#

Workbook wb = new Workbook("sample.xlsx");

HtmlSaveOptions opts = new HtmlSaveOptions();
opts.ExportGridLines = true;
//opts.ExportActiveWorksheetOnly = true;

wb.Save(dirPath + "OutputGridLines.html", opts);

Thanks for the information about using ExportActiveWorksheetOnly with the license, that’s not an issue at all because we do use the license. However, with 17.11.6 and both of our sample codes, gridlines do not work if ExportActiveWorksheetOnly=true and there are multiple worksheets in the workbook.

also having same problem and i would really appreciate if someone could help with this. thanks for the answer shakeel anyway. may i come back with some questions in case i would have some? thanks!

@dfactset

Thanks for using Aspose APIs.

We have looked into this issue and found your Excel file has only cell. Open your Excel file in Microsoft Excel and press Ctrl + END and you will see, the worksheet has only one cell.

Besides, there are no borders in your worksheet, all the worksheet has no color or filled with white color. Because of that Grid Lines are not being rendered. We will look into this issue further and update you asap.

@Mandis

You can also create a new topic and illustrate the problem relating to Grid Lines there, we will also look into your issue and help you asap.

@dfactset

We have looked into your Excel file i.e. gridlines_off_1worksheet.xls and found its grid lines are not visible. So we made them visible in the following code. We also found, you have only one cell i.e. A1, so in order to show more grid lines, we added a space in cell J10, now grild lines show up better. Please see the screenshot shown below. Please also read the comments inside the code for more help.

C#

Workbook wb = new Workbook("gridlines_off_1worksheet.xls");

Worksheet ws = wb.Worksheets[0];

//Add some values in some cells because you have only one cell
ws.Cells["J10"].PutValue(" ");

//Gridlines of your worksheet are not visible - make them visible
ws.IsGridlinesVisible = true;

HtmlSaveOptions opts = new HtmlSaveOptions();
opts.ExportGridLines = true;

wb.Save(dirPath + "OutputGridLines.html", opts);

Screenshot

I’m more concerned with the gridlines_off_2worksheets.xls case where there are multiple worksheets and the ExportActiveWorksheetOnly is set to true on the HmlSaveOptions. I added a few more cells in both of the worksheets and I still don’t see gridlines appearing in that section of the sample code. Were you guys able to reproduce the behavior with that document and the code I provided above?

@dfactset

We will look into this issue further with your second file and update you asap.

@dfactset

Please uncheck the Gridlines checkbox either using Microsoft Excel or using Aspose.Cells as shown in the screenshot given below. It will fix your issue. I have tested it at my end and everything is fine. Please read the comments on screenshot for more help.

I have done that with the example code I’ve included in my original post. I have set the license in the code so the evaluation warning is not the active sheet, and then I set IsGridlinesVisible for the active worksheet before I save as html. Like I’ve mentioned before, this code behaves as expected as long as ExportActiveSheetOnly is not set to true. It will force the gridlines to turn on for the active sheet only.

gridlines_off_2worksheets.zip (6.4 KB)

For example, with the attached xls file above the code below will not output gridlines in the html which is the second worksheet. However, if you set ExportActiveSheetOnly=false then you will see that the 2nd worksheet has gridlines forced on.

@dfactset

We were able to observe this issue 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 let you know asap.

This issue has been logged as

  • CELLSNET-45807 - Gridlines do not appear when HtmlSaveOptions.ExportActiveWorksheetOnly property is set true

@dfactset

Please download and try the following fix and let us know your feedback.

Thanks, I tested out that build and it’s working as I would expect. The gridlines are appearing when we only export the active sheet and there are multiple worksheets in the workbook.

@dfactset

Thanks for using Aspose APIs.

Please try the following code. It works fine. I have attached the output HTML generated by this code and screenshot for a reference.

Output HTML.zip (9.0 KB)

C#

var workbook2 = new Workbook("gridlines_off_2worksheets.xls");

workbook2.Worksheets[0].IsGridlinesVisible = true;
workbook2.Worksheets[1].IsGridlinesVisible = true;
                
workbook2.CalculateFormula();

HtmlSaveOptions opts = new HtmlSaveOptions();
opts.ExportGridLines = true;

workbook2.Save(dirPath + @"output.htm", opts);

Screenshot

The issues you have found earlier (filed as CELLSNET-45807) have been fixed in this Aspose.Cells for .NET 18.1 update.

Please also check the following article: