Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Mar 27, 2024 8:18 am

Hello,

In an asp.net 6 mvc application, I am capturing images of the excel from its print area. When migrating from version 13.12.0 to 14.3.3 I see that the width of the captured area is different (801 pixels in 13.12.0 and 861 pixels in 14.3.3). In my code I am setting the margins in PageSetup to 0. Why is there this difference and how can I ensure the same width?

Code: Select all
var sheet = workbook.Worksheets[sheetNameFinal];

if (sheet == null || sheet.PageSetup.PrintArea == null)
{
    return new List<byte[]>();
}

sheet.PageSetup.LeftMargin = 0;
sheet.PageSetup.RightMargin = 0;
sheet.PageSetup.BottomMargin = 0;
sheet.PageSetup.TopMargin = 0;

var printArea = sheet.PageSetup.PrintArea;

var ranges = sheet.PageSetup.PrintArea.Split(',').ToList();

var result = new List<byte[]>();

foreach (var range in ranges)
{
   var cellRange = sheet.Range[range];
   AnyBitmap image = sheet.ToImage(cellRange.Row, cellRange.Column, cellRange.LastRow, cellRange.LastColumn);
   var content = image.ExportBytes(AnyBitmap.ImageFormat.Png);
   result.Add(content);
}


Regards,
Carlos
Attachments
test_14_3_3.png
image generated with 14.3.3
test_14_3_3.png (3.35 KiB) Viewed 7103 times
test_13_12_0.png
image generated with 13.12.0
test_13_12_0.png (3.3 KiB) Viewed 7103 times

ccarballo
 
Posts: 2
Joined: Tue Mar 14, 2023 5:51 pm

Thu Mar 28, 2024 2:52 am

Hello,

Thanks for your inquriy.
I simulated an Excel file and tested your issue with the two versions you mentioned, but did not reproduce it. For the convenience of our further investigation, please share your test files with us. You can attach it here or send it via email(support@e-iceblue.com). Thank you in advance.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.XLS