Image Gridline color different from the color in the excel sheet

I am using Aspose.Cells to take snapshot of a range, when I get the image it has gridlines which are thicker and of a different color than in the excel sheet. I took one image using Range.getImage() of excel javascript API and I want my aspose image to look as close to that as possible. Also, I would rather not use borders because they overwrite any borders that are manually set on a range or table in excel(look at range called table).
Excel Js API Image -
image.png (9.6 KB)
(Don’t mind the blue background outside the range, not part of the image)

Aspose Image -
image.png (4.1 KB)

Source file-
sourceFile.zip (25.7 KB)

Here is my code -
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[namedRange.SheetIndex - 1];
Aspose.Cells.Range range = namedRange.GetRange();

worksheet.AutoFitRows();
worksheet.PageSetup.PrintArea = namedRange.RefersTo;
worksheet.PageSetup.LeftMargin = 0;
worksheet.PageSetup.RightMargin = 0;
worksheet.PageSetup.TopMargin = 0;
worksheet.PageSetup.BottomMargin = 0;
worksheet.PageSetup.PrintGridlines = true;
worksheet.IsGridlinesVisible = true;

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions
{
OnePagePerSheet = true,
ImageType = ImageType.Jpeg,
HorizontalResolution = 400,
VerticalResolution = 400,
PrintingPage = PrintingPageType.IgnoreBlank,
GridlineType = GridlineType.Hair
};

SheetRender sr = new SheetRender(worksheet, imgOptions);

@Adhirath

To address the issue of gridline color and thickness in the image generated by Aspose.Cells compared to the Excel JavaScript API, you can adjust the GridlineType property in your ImageOrPrintOptions.

In your current implementation, you are using GridlineType.Hair, which may not match the appearance of the gridlines in Excel. You can try using GridlineType.Normal or GridlineType.Thick to see if that better matches the gridline style you are looking for.

Here’s an updated version of your code snippet with the suggested change:

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions
{
    OnePagePerSheet = true,
    ImageType = ImageType.Jpeg,
    HorizontalResolution = 400,
    VerticalResolution = 400,
    PrintingPage = PrintingPageType.IgnoreBlank,
    GridlineType = GridlineType.Normal // Change this to Normal or Thick
};

Additionally, ensure that the PrintGridlines property is set to true, which you have already done. This will ensure that the gridlines are included in the image output.

If the gridlines still do not match after these adjustments, consider checking the Excel file’s gridline settings directly, as they may affect how Aspose renders them.

For further customization, you might also explore applying borders to specific cells if necessary, but as you mentioned, this could overwrite any manually set borders in your Excel sheet.

Feel free to test these changes and see if they help achieve the desired appearance for your image output.

Sources:
[1]: Apply Style on cell

Only two options available on gridlinetype - hair and dotted, no normal.

@Adhirath
By testing with sample files and code on the latest version v25.3, we can reproduce the issue.Image gridline color is different from the color in the excel sheet.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-58026

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

is there something I can do about it for now?

@Adhirath
As a temporary solution, you can set borders on the area where grid lines need to be output and modify the borders to the desired style. We need time to fix the issue with the grid lines. Once there is an update, we will notify you promptly.

@Adhirath ,

When you printview the file in Excel or save the file to pdf manually in Excel, you will find the color of gridline is also black.

We can consider to add a new enum in GridlineType(e.g. Gray), but the line width will be same as GridlineType.Hair. Please let us know your feedback.

works for me

@Adhirath ,

OK, we will add a new enum in GridlineType(e.g. Gray).

1 Like

@Adhirath
We will public Worksheet.GridlineColor property in the next version 25.4, then you can set your excepted gridline color.