Image Gridline color different from the color in the excel sheet

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.

The issues you have found earlier (filed as CELLSNET-58026) have been fixed in this update. This message was posted using Bugs notification tool by leoluo

Hi Simon how do I use this?

@Adhirath
Please refer to the following example code to set the grid line color.

Workbook workbook = new Workbook(filePath + "sourceFile.xlsx");
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
worksheet.AutoFitRows();
worksheet.PageSetup.PrintArea = "R4:S7";
worksheet.PageSetup.LeftMargin = 0;
worksheet.PageSetup.RightMargin = 0;
worksheet.PageSetup.TopMargin = 0;
worksheet.PageSetup.BottomMargin = 0;
worksheet.PageSetup.PrintGridlines = true;
worksheet.IsGridlinesVisible = true;

//add this line to set grid line color
worksheet.GridlineColor = Color.Red;

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);
sr.ToImage(0, filePath + "out_net.png");

Hope helps a bit.

Hi, I am getting weird gridlines for some reason using this code-

worksheet.AutoFitRows();
worksheet.PageSetup.PrintArea = printArea;
worksheet.PageSetup.LeftMargin = 0;
worksheet.PageSetup.RightMargin = 0;
worksheet.PageSetup.TopMargin = 0;
worksheet.PageSetup.BottomMargin = 0;
worksheet.PageSetup.PrintGridlines = true;
worksheet.GridlineColor = System.Drawing.Color.Gray;
worksheet.IsGridlinesVisible = true;

ImageOrPrintOptions originalImgOptions = new ImageOrPrintOptions
{
TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
OnePagePerSheet = true,
ImageType = ImageType.OfficeCompatibleEmf,
};

the Image of the range from excel is the following-
image.png (7.8 KB)

and with gridlines it should look like this-
image.png (3.5 KB)

but what I end up with is this
image.png (13.8 KB)

gridline is dotted, the borders are also the same color as gridline?

@Adhirath
Please refer to the following example code to change the grid line type.

ImageOrPrintOptions originalImgOptions = new ImageOrPrintOptions
{
    TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
    OnePagePerSheet = true,
    ImageType = ImageType.OfficeCompatibleEmf,
    GridlineType = GridlineType.Hair
};

Hope helps a bit.

Same issue with the following code too-

            worksheet.AutoFitRows();
            worksheet.PageSetup.PrintArea = printArea;
            worksheet.PageSetup.LeftMargin = 0;
            worksheet.PageSetup.RightMargin = 0;
            worksheet.PageSetup.TopMargin = 0;
            worksheet.PageSetup.BottomMargin = 0;
            worksheet.PageSetup.PrintGridlines = true;
            worksheet.GridlineColor = System.Drawing.Color.Gray; 
            worksheet.IsGridlinesVisible = true;
            
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions
            {
               OnePagePerSheet = true,
               ImageType = ImageType.Png,
               HorizontalResolution = 400,
               VerticalResolution = 400,
               PrintingPage = PrintingPageType.IgnoreBlank,
               GridlineType = GridlineType.Hair
             };
             SheetRender sr = new SheetRender(worksheet, imgOptions);

             using (MemoryStream ms = new MemoryStream())
             {
                sr.ToImage(0, ms);
              }

@Adhirath
Would you like to provide your sample file and complete runnable test code? We will check it soon.

I have provided the entire code for generating the image above, the table is present in this file-
tableexcel.zip (12.2 KB), this did not use to happen with 24.7.0 version started happening when i moved to 25.4.0

@Adhirath ,

We can see the color of border which is automatic color is changed to be same color as grildline after setting worksheet.GridlineColor = System.Drawing.Color.Gray; . In Excel, after changing the color of gridline, the color of border set in cell is also changed.

The gridline is solid after setting GridlineType = GridlineType.Hair, which is OK.

Do you want only the color of gridline is changed to the set color, while keeping the color of border set in Cells as it is?

yes I would like that

@Adhirath
Thank you for your feedback. We will further study and solve your issue. We will notify you promptly once there are any updates.

@Adhirath ,

We decide to add new API ImageOrPrintOptions.GridlineColor to set grildline color during rendering. It will ignore the grildline color settings in the source file.
Please check the result with prefix(setting ImageOrPrintOptions.GridlineColor to Color.Gray.
CELLSNET-58026_prefix.zip (95.5 KB)

Code:

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

Please let us know your feedback.