Image looks slightly different than in Excel after rendering

Hi,

we use following code to render an image in Excel to png:

Workbook wb = new Workbook(“Example2.xlsx”);
Worksheet excelWorksheet = wb.Worksheets[“Example 2”];
string rangeName = “BIPLI_Example2”;
CellsHelper.DPI = 96;
Aspose.Cells.Range range = wb.Worksheets.GetRangeByName(rangeName);
string startCell = CellsHelper.CellIndexToName(range.FirstRow, range.FirstColumn);
string endCell = CellsHelper.CellIndexToName(range.FirstRow + range.RowCount - 1, range.FirstColumn + range.ColumnCount - 1);
string rangeAddress = string.Format(“{0}:{1}”, startCell, endCell);

ImageOrPrintOptions options = new ImageOrPrintOptions();
options.AllColumnsInOnePagePerSheet = true;
options.ImageType = Aspose.Cells.Drawing.ImageType.Png;
options.OnePagePerSheet = true;
options.HorizontalResolution = 600;
options.VerticalResolution = 600;
options.OnlyArea = true;

Aspose.Cells.PageSetup pageSetup = excelWorksheet.PageSetup;
//set margins to zero.
pageSetup.LeftMargin = 0;
pageSetup.RightMargin = 0;
pageSetup.TopMargin = 0;
pageSetup.BottomMargin = 0;

pageSetup.PrintArea = rangeAddress;

SheetRender sr = new SheetRender(excelWorksheet, options);

using (MemoryStream imageStream = new MemoryStream())
{

sr.ToImage(0, imageStream);
System.IO.File.WriteAllBytes("image.png", imageStream.ToArray());

}

Specifically, it is about the representation of the second Interest expense columns. The label with the background looks different than in Excel.

here the documents
example.zip (232.3 KB)

Kind regards,
@Nachti

@Nachti

It sounds like you’re experiencing discrepancies in how the image is rendered compared to its appearance in Excel, particularly with the second Interest expense column. Here’s a structured approach to address the issue:

Cause: The differences in rendering may stem from font availability, DPI settings, rendering options, margins, or the image format used.

Solution: Follow these troubleshooting steps to resolve the issue:

  1. Check Font Settings: Ensure that the fonts used in your Excel file are available on the system where the rendering is taking place. Missing fonts may lead to visual differences.

  2. Adjust DPI Settings: Experiment with different DPI settings (like 300 or 600) to see if that improves the rendering quality.

  3. Rendering Options: Review the ImageOrPrintOptions settings. Set options.OnlyArea to false to include the entire sheet in the rendering, which may help with layout issues.

  4. Margins and Page Setup: Double-check the margins and page setup in your Excel worksheet. Small margins can affect how content is displayed in the rendered image.

  5. Test with Different Image Formats: Render the image in different formats (like JPEG or BMP) to see if the issue persists across formats.

Here’s a modified version of your code snippet that incorporates these suggestions:

ImageOrPrintOptions options = new ImageOrPrintOptions();
options.AllColumnsInOnePagePerSheet = true;
options.ImageType = Aspose.Cells.Drawing.ImageType.Png;
options.OnePagePerSheet = true;
options.HorizontalResolution = 300; // Try different DPI
options.VerticalResolution = 300; // Try different DPI
options.OnlyArea = false; // Include entire sheet

// Set margins to zero
pageSetup.LeftMargin = 0;
pageSetup.RightMargin = 0;
pageSetup.TopMargin = 0;
pageSetup.BottomMargin = 0;

SheetRender sr = new SheetRender(excelWorksheet, options);

Next Steps: After making these adjustments, render the image again and check if the appearance aligns more closely with what you see in Excel.

If the issue persists or if you have any further questions, please let me know! I’m here to help.

@Nachti,

Thanks for the template Excel file and sample code snippet.

I reproduced the issue as you mentioned by using your template Excel file and sample code snippet. I found in the output image, the label with the background looks different than in Excel.
We require thorough evaluation of the issue. 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-58850

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.

@Nachti,

This is to inform you that your issue (Ticket ID: “CELLSNET-58850”) has been resolved. The fix/enhancement will be included in our upcoming release (Aspose.Cells v25.8) that we plan to release during this week. You will be notified when the new version is published.

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