Free Support Forum - aspose.com

Overflow error Aspose.Cells.Chart

Hi,

I tried using the following code that I picked up from one of the threads to convert an excel chart into an Image and I have two queries about that

1) I used the following code

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();

workbook.Open(@"C:\Sheets.xls");

Aspose.Cells.Chart chart = workbook.Worksheets[0].Charts[0];

Bitmap bitmap = chart.ToImage();

bitmap.Save(@"C:\Test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

When I tried running the above code, I got an "OverFlow exception" at System.Drawing.Graphics.CheckErrorStatus(Int32 status)

I then modified the above code as follows

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();

workbook.Open(@"C:\Sheets.xls");

Aspose.Cells.Chart chart = workbook.Worksheets[0].Charts[0];

workbook.Save(@"C:\Text.xls");

Bitmap bitmap = chart.ToImage();

bitmap.Save(@"C:\Test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

and the error disappeared.

Why is this happening?

2) When I saved the image from the code above, I could not see anything in the image, everything was white and all I got was a white square. Why is the formatting from the excel sheet not getting saved? I have attached the excel file I am using

Thanks in advance

Hi,

Thanks for the template file.

Yes, we found the problem, we will fix it soon.

Thank you.

Hi,

Thanks for your file! Please try this fix.

Hi,

Thank you for the dll. I tired using the dll with the attached excel sheet and the below code.

spose.Cells.Workbook workbook = new Aspose.Cells.Workbook();

workbook.Open(@"C:\Sheets.xls",FileFormatType.ExcelXP);

Aspose.Cells.Chart chart = workbook.Worksheets[0].Charts[0];

chart.Title.Text = "Test \n Test 2";

Bitmap bitmap = new Bitmap(chart.ToImage());

bitmap.Save(@"C:\Test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

It works fine if all the cells are empty, but if the first row is empty and there are values in the second row, they are not displayed image. I have also attached the image file for your reference.

Please advise

Thank you

Hi,

Please try this fix.

Thanks Warren, the dll was able to fix the problem.