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:
The gridlines only appear if the aspose license is set
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);
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.
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!
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.
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);
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?
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.
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.
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
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.