Data loss in saving a pivot table chart

I am getting data loss when try to Convert a Pivot chart to image Excel file. The attachment includes Original.xls that I am trying to open, and save as New.xls after replacing a chart with an image created from the chart which is included as well. I am using Aspose.Cells 22.11

The sheet named “Sheet 1” has a chart which is becoming blank when the file is opened and saved without any change.

The following is the code I am using.

private void bStart_Click(object sender, EventArgs e)
{
	Aspose.Cells.Workbook w = new Aspose.Cells.Workbook(@"Original.xls");
	ReplaceChartSheetWithPicture(ref w);
	w.Save(@"New.xls");
}

private static bool ReplaceChartSheetWithPicture(ref Aspose.Cells.Workbook pAsposeWorkbook)
{
    Aspose.Cells.Rendering.ImageOrPrintOptions iOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions();

    pAsposeWorkbook.Worksheets[0].Type = Aspose.Cells.SheetType.Worksheet;
    //Get chart picture
    MemoryStream sPictureStream = new MemoryStream();
    Aspose.Cells.Charts.Chart c = pAsposeWorkbook.Worksheets[0].Charts[0];
    Bitmap bImage = pAsposeWorkbook.Worksheets[0].Charts[0].ToImage(iOptions);
    bImage.Save(sPictureStream, System.Drawing.Imaging.ImageFormat.Png);
    pAsposeWorkbook.Worksheets[0].Charts.Clear();
    pAsposeWorkbook.Worksheets[0].Pictures.Add(0, 0, sPictureStream);

    return true;
}

SampleFile.zip (52.2 KB)

Please let me know how to create the chart successfully.

This topic has been moved to the related forum: Data loss in saving a pivot table chart - Free Support Forum - aspose.com