We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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)<o:p></o:p>
    var iop = new ImageOrPrintOptions<o:p></o:p>
        IsCellAutoFit = false,<o:p></o:p>
        ImageFormat = ImageFormat.Emf,<o:p></o:p>
        VerticalResolution = 96,<o:p></o:p>
        HorizontalResolution = 96,<o:p></o:p>
        Quality = 100,<o:p></o:p>
        OnePagePerSheet = true,<o:p></o:p>
        OnlyArea = true,<o:p></o:p>
        SaveFormat = SaveFormat.Auto,<o:p></o:p>
        ChartImageType = ImageFormat.Emf,<o:p></o:p>
        SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default<o:p></o:p>
    var sheet = string.IsNullOrWhiteSpace(sheetName)<o:p></o:p>
        ? workbook.Worksheets[workbook.Worksheets.ActiveSheetIndex]<o:p></o:p>
        : workbook.Worksheets[sheetName];<o:p></o:p>
    var sr = new SheetRender(sheet, iop);<o:p></o:p>
    var imgOleObject = sr.ToImage(pageIndex);<o:p></o:p>
    return imgOleObject;<o:p></o:p>
We are holding for this issue on a stage and cant go ahead. Eagerly 
waiting for your response.


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.

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”);

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.


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.