Charts in XLSX Not Converting correctly using .ToImage(filename-imagetype)

I have attached screen shots of the Excel with the chart in it and the image created by Chart.ToImage(). I have also cut and pasted the code that I am using to pull the images from the Excel file loaded in Aspose.Cells object. If you compare the chart in the Excel to the one in the word file that I attached you will see the x-axis is not correct.

public void AsposeExportChart(string sWorksheetName, string outputChartName, string chartTitle)

{

ECells.Charts.ChartCollection oChartCollection = wb.Worksheets[sWorksheetName].Charts;

foreach (ECells.Charts.Chart oChart in oChartCollection)

{

if (oChart.Title != null && oChart.Title.Text != null)

{

if (chartTitle.Replace(".", string.Empty).Replace(",", string.Empty).Replace("'", string.Empty).Replace("\\", string.Empty).Replace("/", string.Empty).Replace("&", string.Empty).Replace("'", string.Empty).Replace(" ", string.Empty) == oChart.Title.Text.Replace(".", string.Empty).Replace(",", string.Empty).Replace("'", string.Empty).Replace("\\", string.Empty).Replace("/", string.Empty).Replace("&", string.Empty).Replace("'", string.Empty).Replace(" ", string.Empty))

{

try

{

oChart.ToImage(outputChartName, System.Drawing.Imaging.ImageFormat.Png);

}

catch (Exception ee)

{

Trace.WriteLine(ee.Message);

Trace.WriteLine(ee.StackTrace);

}

}

}

}

}

Is there a problem with converting to PNG format or is there a better way to get the chart out of Excel into Word?

Thanks,

Bryan

Hi Bryan,


I can see the problem in output image. I’m afraid you have to share your Input template file as well. That would be of great help to isolate this issue.
Looking forward to your reply.

When you say Input Template what are you referring to? Do you want the actual Excel File? I am actually loading the Workbook; searching for the Worksheet and then find the ChartCollection. Once I have the collection I take each Aspose.Cells Chart and do a convert to image. I am not creating the charts with Aspose.Cells. I am trying to take the chart that is already viewable in Excel and copy it to a Aspose.Words.Document object. If it would better to use the base data and create each chart from scratch, I will, but don't want to do it.

Thanks,

Bryan

Hi Bryan,


Yes, I am referring to the actual excel file that you are reading to search for charts.
If I get it right then, you are performing these steps,
  • Reading Excel Workbook
  • Finding Charts
  • If found then converting them to Images using Aspose.Cells.
  • Pasting these Images on Word Document using Aspose.Words
  • Saving the Word Document.
As I have said before, I can see the problem. To completely isolate and resolve this issue, it would be of great help that you provide a small Console application with you Input and Output Files. Also, please mention the versions you are using of Aspose.Cells and Aspose.Words.