Xlsx worksheet to image conversion problem

Dear Concern,

I’m trying to save the attached “temp.xlsx” worksheet as image.
But it throws error. We’ve found that Sparkline data is the cause of
error. If the marked sparklines in the attached image are cleared,
it works fine.

You are requested to fix the issue.
If fix takes time, please suggest us a workaround or at least would
you please inspect the source data of Sparkline and explain in which
condition the error throws, such that we could find out a workaround
as soon as possible to avoid the error.

The source code is given below, and necessary files are attached here.

var book = new Workbook("..\\..\\Template\\temp.xlsx");
var img = book.GetWorksheetImage(); 
public  Image GetWorksheetImage(this Workbook workbook, string sheetName = “”, int pageIndex = 0)
{
    var iop = new ImageOrPrintOptions
    {
        IsCellAutoFit = false,
        ImageFormat = ImageFormat.Emf,
        VerticalResolution = 96,
        HorizontalResolution = 96,
        Quality = 100,
        OnePagePerSheet = true,
        OnlyArea = true,
        SaveFormat = SaveFormat.Auto,
        ChartImageType = ImageFormat.Emf,
        SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default
    };
    var sheet = string.IsNullOrWhiteSpace(sheetName)
        ? workbook.Worksheets[workbook.Worksheets.ActiveSheetIndex]
        : workbook.Worksheets[sheetName];
 
   var sr = new SheetRender(sheet, iop);
    var imgOleObject = sr.ToImage(pageIndex);
 
    return imgOleObject;
} 

We are holding for this issue on a stage and cant go ahead. Eagerly
waiting for your response.

Hi,

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue after converting your worksheet into image using the latest version: Aspose.Cells
for .NET v8.5.1.5
. It throws overflow error exception.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43827 - Converting worksheet to image throws Overflow error exception

I have tested this issue with the following sample code.

C#
string path = @“F:\Shak-Data-RW\Downloads\temp.xlsx”;

Workbook workbook = new Workbook(path);

Worksheet worksheet = workbook.Worksheets[0];

Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
options.OnePagePerSheet = true;
options.ImageFormat = ImageFormat.Png;

SheetRender sr = new SheetRender(worksheet, options);
sr.ToImage(0, path + “.out.png”);

Exception:
A first chance exception of type ‘Aspose.Cells.CellsException’ occurred in Aspose.Cells.dll
at Š.”.™ˆ(Int32 , ImageOrPrintOptions )
at Š.”.•(Int32 , ImageOrPrintOptions , Stream )
at Š.”.•(Int32 , String , ImageOrPrintOptions )
at Aspose.Cells.Rendering.SheetRender.ToImage(Int32 pageIndex, String fileName)
at AsposeProject.Program.f1() in F:\Shak-Data-RW\Projects\AsposeProject\AsposeProject\Program.cs:line 2041
at AsposeProject.Program.Main(String[] args) in F:\Shak-Data-RW\Projects\AsposeProject\AsposeProject\Program.cs:line 301
A first chance exception of type ‘Aspose.Cells.CellsException’ occurred in AsposeProject.exe
An unhandled exception of type ‘Aspose.Cells.CellsException’ occurred in AsposeProject.exe

Additional information: Overflow error.

Hi Mandy,


This is to inform you that we have fixed the problem logged earlier as CELLSNET-43827. We will shortly provide the fix here after assuring the quality & incorporating other enhancements. As soon as the next build of Aspose.Cells for .NET API is available for public use, you will be notified here along with the link to upgraded API.

Hi,

Thanks for using Aspose.Cells.

Please download and use the latest version: Aspose.Cells for .NET 8.5.2.

Please try the new version for drawing sparkline.