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:28 am

Hello,

When generating images from a print area made up of several ranges, errors are occurring in some cases. From the tests carried out I think it has to do with the thick outer edge. It manages to capture the first area (the one with the thick outer border) but not the following ones. When accessing the second range of the print area it gives the error: "Object reference not set to an instance of an object."

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);
   image.ExportFile("prueba_13_12_0.png", AnyBitmap.ImageFormat.Png);
   var content = image.ExportBytes(AnyBitmap.ImageFormat.Png);
   result.Add(content);
}


Regards,
Carlos
Attachments
Compuesta1.zip
Excel with composed print area (3 different ranges)
(7.72 KiB) Downloaded 367 times

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

Thu Mar 28, 2024 2:32 am

Hello,

Thanks for your inquiry.
I have reproduced the issue you mentioned and logged it into our tracking system with the ticket number SPIREXLS-5186, our dev team will investigate and fix it. We apologize for any inconvenience caused. Once the issue is fixed, I will inform you asap.

Sincerely,
William
E-iceblue support team
User avatar

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

Fri May 24, 2024 7:52 am

Hello,

Thank you for your patience.
Glad to inform that we just released Spire.XLS Pack(Hotfix) Version:14.5.3, which fixed the issue of SPIREXLS-5186, welcome to test it.
Our website link: https://www.e-iceblue.com/Download/down ... t-now.html
NuGet link: https://www.nuget.org/packages/Spire.XLS

If you have any questions, please let us know.

Sincerely,
William
E-iceblue support team
User avatar

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

Return to Spire.XLS