How to create a PivotTable in Word via Delphi?

0

I have documents .doc / .docx, which I am doing the replacement of TAGs, however I now need to do the creation of a PivotTable, based on a select, in these same files I am replacing tags . This table should be below the existing text in the file.

I've done a lot of research, but I was not able to succeed with the examples because it was not well explained. Could someone give an example?

    
asked by anonymous 01.06.2017 / 14:29

2 answers

0

There are native components for this. To enable go to:

  

Component / Install packages ... /   Microsoft Office XP Sample Automation Server Wrapper Components.

It will enable a palette called Servers . Probably what you want is TWordApplication .

    
15.07.2017 / 05:50
1

I did to export a program, see if it helps:

procedure TfrmPrincipal.Word1Click(Sender: TObject);
var
  WordApp, NewDoc, WordTable : OleVariant;
  i : Integer;
  s : string;
begin
  if RichEdit1.Lines.Count > 1 then
  begin
    WordApp := CreateOleObject('Word.Application');
    WordApp.Visible := True;
    NewDoc := WordApp.Documents.Add;
    WordTable := NewDoc.Tables.Add(WordApp.Selection.Range, 1, 1);
    WordTable.Cell(1,1).Range.Paragraphs.Alignment := wdAlignParagraphcenter;
    WordTable.Cell(1,1).Range.Paragraphs.SpaceAfter := 0;
    WordTable.Borders.OutsideLineStyle := wdLineStyleSingle;
    s := '';
    for i := 1 to RichEdit1.Lines.Count-1 do
    begin
      s := s + RichEdit1.Lines.Strings[i]+#13+#10;
    end;
    s := Copy(s,1,Length(s)-2);
    WordApp.Selection.Font.Size := 8;
    WordApp.Selection.Font.Name := 'Courier New';

    WordTable.Cell(1, 1).Range.Text := s;
    // Cleanup...
    WordApp := Unassigned;
    NewDoc := Unassigned;
    WordTable := Unassigned;
  end;
end;
    
02.06.2017 / 18:44