I create a small tablet in Word, and then I need to make a graph based on it. I found how to add a graph, but the code all the time crashes with an error in the position
w := wrd.ActiveDocument.Shapes.AddOLEObject('MSGraph.Chart.8');
and the graph is created but not created based on the data in the table. How to do right?
procedure TForm1.btn2Click(Sender: TObject); var wrd, w, Child: OleVariant; i: Integer; StartRange: Variant; begin wrd:=CoWordApplication.Create; wrd.Visible:=true; wrd.Documents.Add; wrd.ActiveDocument.Tables.Add(wrd.ActiveDocument.Range(0, 0), 5, 2); wrd.Visible := True; For i:=1 to 5 do begin wrd.ActiveDocument.Tables.Item(1).Cell(i,1).Range.Text := i; wrd.ActiveDocument.Tables.Item(1).Cell(i,2).Range.Text := i*i; end; w:=wrd.ActiveDocument.Shapes.AddOLEObject('MSGraph.Chart.8'); Child:=w.DiagramNode.Children.AddNode; for i:=1 to 5 do begin Child.Children.AddNode; end; end;
Child:=w.DiagramNode.Children.AddNode;
- kami