Create & Insert Graphs?

hi Guys,

How do i create and insert native word charts in documents with Aspose.Words? i can’t find it in the documentation.

Greetings,

Simon

Hi
Thanks for your request. As I know Word format has no native charts. As a rule charts are inserted into the word document as embedded OLE objects. Unfortunately Aspose.Words doesn’t allow inserting of OLE objects.
I think that you can use Aspose.Chart component to create graph and then insert it into the word document. For example see the following code:

// Create a sample chart.
Aspose.Chart.Chart lineChart = new Aspose.Chart.Chart();
lineChart.Height = 300;
lineChart.Width = 400;
Aspose.Chart.Series lineSeries = new Aspose.Chart.Series();
lineSeries.ChartType = Aspose.Chart.ChartType.Line;
lineSeries.Name = "Series";
lineSeries.DataPoints.Add(new Aspose.Chart.DataPoint(1, 1));
lineSeries.DataPoints.Add(new Aspose.Chart.DataPoint(2, 2));
lineSeries.DataPoints.Add(new Aspose.Chart.DataPoint(3, 3));
// Fill a series manually
lineChart.SeriesCollection.Add(lineSeries);
// Save chatr in EMF format
MemoryStream ms = new MemoryStream();
lineChart.Save(ms, ImageFormat.Emf);
// Create new document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert chart using GetChartImage method
builder.InsertImage(lineChart.GetChartImage());
// Insert chart as EMF
builder.InsertImage(ms);
// Save document
doc.Save(@"Test068\out.doc");

You can read about Aspose.Chart component here:
https://products.aspose.com/
I hope this could help you.
Best regards.

Hi,

thanks. with word 2007 you can insert graphs and double click them to make changes to their plots or change the chart type etc. it when graphs are inserted into the older .doc files.

i’m suspecting word 2007 has a emf format its using for this. can this be done with Aspose.Chart?

Greetings,

Simon

EDIT: i’ll give it a try after the weekend

Hi
Exactly this I meant. These charts are not native Word charts but these are embedded OLE objects.
As you can see from my code example chart created by Aspose.Chart was inserted into the Word document in EMF format.
Best regards.

Hi

thanks for the info
- what is the format of native word graphs/charts? is it emf ? ( just making sure )

  • is it possible to insert an image from a bitmap object? (just a minor question i guess)

sorry for all the questions. i’m kinda new to this

Simon

Hi
Thanks for your request. The native Word chart is Microsoft Graph Chart. You can double click this chart to edit it.
EMF is just metafiles (vector images).
Best regards.

ok i understand. thanks