Image Gridline color different from the color in the excel sheet

@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.

just what I wanted guys. You will add this feature or it already exists?
Also what all do i need to do in the page setup then?

@Adhirath,

We will add this feature to our upcoming release.

You may use the same code as you do previously for PageSetup. However, kindly note that when you apply ImageOrPrintOptions.GridlineColor, it will override your existing settings related to gridline color when rendering the worksheet to an image.

so i leave out gridline color in pagesetup?

@Adhirath,

Yes, if you do not render to Excel file and only rendering to image, you may leave gridline color setting in PageSetup.

@Adhirath
The issues you have found earlier (filed as CELLSNET-58026) have been fixed in this update.

Thank you soo much !

@Adhirath
Thank you for your feedback. You are welcome. If you have any questions, please feel free to contact us at any time.

also forgot to ask, how do I use it?

@Adhirath

Please refer to the sample code provided by @peyton.xu earlier. I hope your issue can be resolved. If you still have any questions, please feel free to contact us at any time.

1 Like

Hi guys I have been trying to get it to work. I have added the GridlineColor property as well. But I do not see any gridlines being added. I tried creating a table without any formatting and am not getting any gridlines on it. Do I have to change any other properties? I am using the following code for setting the image options-
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions
{
OnePagePerSheet = true,
ImageType = ImageType.Png,
HorizontalResolution = 400,
VerticalResolution = 400,
PrintingPage = PrintingPageType.IgnoreBlank,
GridlineType = GridlineType.Hair,
GridlineColor = Color.Gray,
};

PageSetup-
worksheet.AutoFitRows();
worksheet.PageSetup.PrintArea = printArea;
worksheet.PageSetup.LeftMargin = 0;
worksheet.PageSetup.RightMargin = 0;
worksheet.PageSetup.TopMargin = 0;
worksheet.PageSetup.BottomMargin = 0;

@Adhirath

Please add the following code to enable to print gridline:

worksheet.PageSetup.PrintGridlines = true;

Thanks guys, it’s working now. Really amazing support!