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