Aspose Cell ToImage Issue with chart

Hi Team,


Chart is not displayed in generated image.

I have attached sample input excel file and resulted image.

Code:


Aspose.Cells.Worksheet sheet = excelDocument.Worksheets[excelDocument.Worksheets.ActiveSheetIndex];
Aspose.Cells.Rendering.ImageOrPrintOptions imageAndPrintOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions();
imageAndPrintOptions.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionLZW;
imageAndPrintOptions.IsCellAutoFit = true;
imageAndPrintOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;
imageAndPrintOptions.PrintingPage = Aspose.Cells.PrintingPageType.Default;
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, imageAndPrintOptions);

MemoryStream fs = new MemoryStream();
// excelDocument.Save(fs, Aspose.Cells.SaveFormat.TIFF);
sr.ToTiff("");

Thanks and Regards,
Nakul

Hi,

Thanks for your posting and using Aspose.Cells.

After initial investigation, we found that output image is same as Ms-Excel Print Preview. We have attached the MS-Excel Print Preview output for your reference. So it is not a bug of Aspose.Cells.


Hi,


Well, if you could open your template file and check the print preview of the sheet, you will also see that chart is not displayed in the print preview either. The reason for this is due to the fact that a limited print area is set (please open the PageSetup dialog box in MS Excel for the sheet, click the sheet tab to check the print area which is set to A1:M11), so the chart is not rendered. You have to either remove the print area or extend the area to include the chart as well. I have added a line to code to your code and it works fine.

e.g

Sample code:

Aspose.Cells.Worksheet sheet = excelDocument.Worksheets[excelDocument.Worksheets.ActiveSheetIndex];

sheet.PageSetup.PrintArea = “”; //Remove your print area (for your worksheet) as it was set to A1:M1–> due to this limited area the chart was not printed

Aspose.Cells.Rendering.ImageOrPrintOptions imageAndPrintOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions();
imageAndPrintOptions.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionLZW;
imageAndPrintOptions.IsCellAutoFit = true;
imageAndPrintOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;
imageAndPrintOptions.PrintingPage = Aspose.Cells.PrintingPageType.Default;
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, imageAndPrintOptions);

MemoryStream fs = new MemoryStream();
//excelDocument.Save(fs, Aspose.Cells.SaveFormat.TIFF);
sr.ToTiff("");



Hi Shakeel/Amjad,


I did not notice print area setting.

Just adjusted print area and it works fine.

Thanks for quick help.

Regards,
Nakul

Hi,


Good to know that your issue is resolved. Feel free to contact us any time if you have further query or have some other issue, we will be happy to assist you soon.

Thank you.