Label randomly switches between 1- and 2- line when rendering

Hi,

we use following code to create pictures from Excel:

Workbook wb = new Workbook(“Example1.xlsx”);
Worksheet excelWorksheet = wb.Worksheets[“Example 1”];
string rangeName = “BIPLI_Example1”;
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());

}

The number of lines in the left label changes between 1 and 2 on different PCs.
Which settings influence this?

I add the content
example.zip (421.6 KB)

Kind regards,
@Nachti

@Nachti

Hi @Nachti,

Thank you for reaching out and providing the details of your issue. The switching between 1- and 2-line labels when rendering Excel content can be influenced by various factors in Aspose.Cells. Much of it depends on the PDF viewing application or the settings used in the rendering process.

Here are some potential settings that might affect the rendering of your content:

Settings that Can Influence Rendering

  1. Page Orientation:
    Ensure that the page orientation is consistent across different PCs. The label might switch lines if the orientation changes from portrait to landscape.

  2. DPI and Resolution:
    Confirm that the DPI and resolution settings are the same on all PCs. Variations here can affect how content is displayed.

    CellsHelper.DPI = 96;
    options.HorizontalResolution = 600;
    options.VerticalResolution = 600;
    
  3. Cell Styles:
    Check for any differences in cell styles, such as font size, font type, text alignment, and cell formatting. Inconsistencies here can lead to content appearing differently.

  4. Print Area and Page Margins:
    Verify that the print area and page margins are set identically on all PCs. Even slight differences can cause rendering issues.

    pageSetup.PrintArea = rangeAddress;
    pageSetup.LeftMargin = 0;
    pageSetup.RightMargin = 0;
    pageSetup.TopMargin = 0;
    pageSetup.BottomMargin = 0;
    

Steps to Reproduce Consistent Output

  1. Review Cell Formatting:
    Ensure that cell formatting is consistent. Export the content to a PNG image without any formatting and check for alignment issues:

    // Set options to export images without fonts or formatting
    options.HorizontalResolution = 600;
    options.VerticalResolution = 600;
    
  2. Use Consistent DPI and Resolution:
    Use the same DPI and resolution settings across all environments. Standard settings can prevent discrepancies:

    CellsHelper.DPI = 96;
    options.HorizontalResolution = 600;
    options.VerticalResolution = 600;
    
  3. Uniform Page Margins and Print Area:
    Make sure the PrintArea and Margin settings are the same across all environments.

    pageSetup.PrintArea = rangeAddress;
    pageSetup.LeftMargin = 0;
    pageSetup.RightMargin = 0;
    pageSetup.TopMargin = 0;
    pageSetup.BottomMargin = 0;
    
  4. Inconsistent Load:
    Save a copy of your workbook and open it on different PCs. Ensure that the machines all have identical versions of the workbooks:

    wb.Save("UniformOutputExample.xlsx");
    

Relevant Documentation

Please refer to the Aspose.Cells supported documentation for detailed information on these settings:

If you follow these guidelines and adjust the settings accordingly, you should achieve more consistent output for your images rendered from Excel on different PCs.

Feel free to ask if you need any further assistance!

Kind regards,

Hi,

as you can see in the code, I already use this settings.

Kind regards,
@Nachti

@Nachti,

I tested your scenario/case using your sample Excel file and code snippet and I got correct result same as your expected image “image example 1 correct.png”. There are two possibilities for incorrect layout on your end.

  1. Display Settings (OS): These can impact image accuracy and quality. What display settings are configured on your machine? Ensure that the display/scale settings are set to 100% to achieve accurate and correct images.
  2. Fonts: Missing fonts can lead to distorted layouts. Verify that the fonts (e.g. Arial) used in your Excel spreadsheets and chart are installed on the machine. Fonts are essential for rendering PDFs or images, so install any necessary fonts if they are missing. Additionally, specify the fonts folder in your code at the start of your application if it is not the default folder. For guidance, refer to the topic on configuring fonts for rendering spreadsheets: Configuring Fonts for Rendering Spreadsheets|Documentation.

Hi,

Scaling is 100%

Can I find out which Font Folder is in use ?

Do you know if the Culture setting has an impact (English, German, Italy) ?

Kind regards,
@Nachti

@Nachti,

This is the resultant image file generated on my end using your sample file and code snippet.
image1.zip (241.6 KB)

Could you please give us your environment details where it is giving error results. Also, add a line to your code snippet to save to PDF file as well and provide that PDF file here. We will look into it further.

@Nachti ,

Could you please try to render to Emf image, then share us correct and error Emf images? We can analyze the generated Emf images to get more infos.
Just change:

options.ImageType = Aspose.Cells.Drawing.ImageType.Png;

to

options.ImageType = Aspose.Cells.Drawing.ImageType.Emf;

@Nachti ,

Also, the width, height and resolution of the correct and error Png images you shared are different. It seems that they are generated by different code. Please check the code and the source file on your different PCs.

For the code: CellsHelper.DPI = 96;, please move it to the begining and only set it once.