Image Gridline color different from the color in the excel sheet

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.

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.