We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Word Charts and Microsoft Excel Charts

Hi Aspose team.

I’m implementing a solution to manipulate charts on Aspose Words based on a template file. For my needs, there are two types of charts I want to manipulate: Word Charts (Insert -> Chart) and Microsoft Excel Charts (Insert -> Object -> Microsoft Excel Chart).

I can access both types of charts using:

shapes = doc.getChildNodes(NodeType.Shape, true);
for (Shape shape : shapes)
{
    if (shape.hasChart())
    {
        // Word Chart
        Chart chart = shape.getChart();
    }
    if (null != shape.getOleFormat())
    {
        // Object Linking and Embedding
        // Check if is Excel Chart and implement a solution using Aspose Cells
    }
}

In the above example, I’m lacking the knowledge on how to manipulate the existent chart data and replacing it with my own, since the charts data are based on an embedded worksheet.
Ie. Having a chart with one collection and two series. In the first serie I’ll have ‘numberA’ and on the second serie ‘numberB’ (literal Strings). Then I’ll want to replace those values with 1 and 2 respectively. Of course, those literal Strings can be anything and the values to be replaced were calculated previously on runtime.

Am I thinking this thoroughly? Can I access that embedded worksheet and implement a solution using Aspose Cells as in Microsoft Excel Chart?

Best Regards

Hi there,

Thanks for your inquiry. Unfortunately, Aspose.Words does not support the requested features at the moment. However, we have logged these features in our issue tracking system as follow.

WORDSNET-14738 : Add feature to modify Word Charts
WORDSNET-14739 : Add feature to modify Excel Charts embedded in Word document

You will be notified via this forum thread once these features are available. We apologize for your inconvenience.

mAroucha:
Can I access that embedded worksheet and implement a solution using Aspose Cells as in Microsoft Excel Chart?

In this case, we suggest you following solution.

  1. Get the Excel chart (Shape node) and save it using OleFormat.save
  2. Modify the Excel chart using Aspose.Cells. Please refer to the following articles:

Chart Formatting
Data Formatting in Charts

  1. Move the cursor to the Shape node (Excel chart) and insert the modified Excel document using DocumentBuilder.InsertOleObject
  2. Remove the old shape Node.

Hope this helps you.

Hi there,

Regarding WORDSNET-14738 (modify Word charts), we suggest you please recreate new series instead of change them as shown below. Hope this helps you.

Document doc = new Document("input.docx");

for (Shape shape : (Iterable)doc.getChildNodes(NodeType.SHAPE,true)) {
    if (shape.hasChart()) {
        // Word Chart
        // Chart property of Shape contains all chart related options.
        Chart chart = shape.getChart();

        // Get chart series collection.
        ChartSeriesCollection seriesColl = chart.getSeries();

        // Delete all old series, or just the one you would like to update seriesColl.RemoveAt(1);.
        seriesColl.clear();

        // Create category names array, in this example we have two categories.
        String[] categories = new String[] { "AW Category 1", "AW Category 2" };

        // Adding new series. Please note, data arrays must not be empty and arrays must be the same size.
        seriesColl.add("AW Series 1", categories, new double[] { 1, 2 });
        seriesColl.add("AW Series 2", categories, new double[] { 3, 4 });
        seriesColl.add("AW Series 3", categories, new double[] { 5, 6 });
        seriesColl.add("AW Series 4", categories, new double[] { 7, 8 });
        seriesColl.add("AW Series 5", categories, new double[] { 9, 10 });
    }
}

doc.save("UpdateChart.docx");

Hello Tahir,

Thank you for your attention. Regarding your second response, I’ve already seen that example. My problem is that I’d need to read the values from the chart before clearing it since the values to insert are dependent on those original values.
In your first response you suggest to save the original chart in OleFormat and modify it using Aspose.Cells and finally insert it as an OleObject. This isn’t exactly what I’m looking for. As I’ve said on my original post, I’m modifying the document based on a template and the final document should have the same structure and styles as the original. This would change the Word Chart into a OleObject Excel Chart and that goes against my needs.

I think WORDSNET-14738 (modify Word charts) makes sense as it should be possible to read the values from a Chart instead of only adding new ones.
I’m attaching an image (chartValues.png) so I can better explain what I’m trying to read and modify.

I’ll keep analysing this and see if I can get a workaround that could satisfy my needs using a mix of both your suggestions.

Best Regards

Hi there,

Thanks for your feedback.

We will inform you via this forum thread once these features are available. We apologize for your inconvenience.