Aspose.Words - Access the chart data worksheet with C# .NET

Hello,

We have a chart “Bar of Pie” in a word document which we can edit its data by using Microsoft Word option “Right Click > Edit Data > Edit Data in Excel”.

We are trying to accomplish the same idea Using Aspose.Words .NET, which is edit the chart data worksheet programmatically. The below doesn’t exist, but that’s what we are trying to accomplish:

Document myDoc = new Document("File.docx");
Node[] shapes = doc.GetChildNodes(NodeType.Shape, true).ToArray();

foreach (Shape shape in shapes)
{
         var workbook = shape.Chart.ChartDataWorkbook;
         var worksheet = workbook.Worksheets[0];

         worksheet.Cells["F3"].Value = "m";
         worksheet.Cells["F6"].Value = 5;
         worksheet.Cells["F9"].Value = 0.25;
}

myDoc.Save("File_Updaded.docx"), Aspose.Words.SaveFormat.Docx);

Are you able to help?

Thanks a mil.

Similar topics:
https://forum.aspose.com/t/how-can-i-modify-ms-graph-chart-values/16685/6
https://docs.aspose.com/slides/java/updating-existing-chart-using-aspose-slides/

@docarr Unfortunately, such feature is not available yet. The appropriate feature request is logged as WORDSNET-18468. I have linked your request to it. We will keep you informed and let you know once this feature is implemented.

Hi Alexey,

Thanks for coming back to me on this. I see in another thread that this is already in development, any idea when is this expected to be released?

Thanks a mil,

https://forum.aspose.com/t/linq-reporting-engine-chart-generation-data-not-editable/247674

@docarr Unfortunately, currently we cannot provide you a reliable estimate. If everything goes smoothly the feature will be added in 2-3 months. But this is a rough estimate and you cannot 100% rely on it. We will be sure to inform you once it is implemented.

1 Like

Hi @alexey.noskov,

Is there any update on the WORDSNET-18468? Do you know when updated expected date to launch?

Thanks a mil

@docarr Unfortunately, there is no estimate yet. The issue is currently in development. We will keep you updated and let you know once it is ready. Please accept our apologies for your inconvenience.

The issues you have found earlier (filed as WORDSNET-18468) have been fixed in this Aspose.Words for .NET 23.5 update also available on NuGet.

We are currently using SyncFusion as Aspose did not support the edit of charts, however now that you seem to have added this functionality since version 23.5, we are refactoring our project to use Aspose.

Unfortunately we are not being able to edit the values in the excel sheet that populates the chart.

Manually, we would use “Right Click > Edit Data > Edit Data in Excel”.

In SyncFusion, we can simply specify the row, column and a value on the excel, as per below:

WChart chart = lstChart[0];

// Populate figures for chart
chart.ChartData.SetValue(2, 1, 4567);

chart.ChartData.SetValue(2, 2, 1234);
chart.ChartData.SetValue(3, 2, 5467);
chart.ChartData.SetValue(4, 2, 8900);

chart.ChartData.SetValue(2, 3, 6632);
chart.ChartData.SetValue(3, 3, 7878);
chart.ChartData.SetValue(4, 3, 9745);

chart.Refresh();

In Aspose, we can find the chart recursively in the word document:

Chart FindChart(Document document)
{
	var allChildNodes = document.GetChildNodes(NodeType.Shape, true);

	foreach (var childNode in allChildNodes)
	{
		var shape = childNode as Shape;

		if (shape != null && shape.HasChart)
			return shape.Chart;
	}

	return null;
}

But then I’m only able to change the series, which does not fully fit for purpose. How can I change the values of the worksheet?

Thanks a mil

@docarr I am afraid, currently there is no way to change valued in the chart’s underlying worksheet. This feature request is logged as WORDSNET-19455. We will keep you updated and let you know once it is implemented.