數據導出到word代碼如下
procedure ExportToWord ;
var wordAppWordDocWrdSelection:variant;
strAdd:string;
i : integer;
wdParwdRange:OleVariant;
begin
wordApp := CreateOleObject(WordApplication);
wordAppVisible := true;
wordDoc:=WordAppDocumentAdd();
wordDocselect;
wrdSelection := WordAppselection;
strAdd:=Title;
wrdSelectionParagraphFormatAlignment:=wdAlignParagraphCenter;
wrdSelectionFontbold := true;
wrdSelectionFontSize := ;
wrdSelectionFontUnderLine := ;
wrdSelectionTypeText(strAdd);
wordAppselectionTypeParagraph;//換行
//從新設置字體
wrdSelectionParagraphFormatAlignment:=wdAlignParagraphLeft;
wrdSelectionFontbold := false;
wrdSelectionFontSize := ;
wrdSelectionFontUnderLine := ;
wdPar:=WordAppActiveDocumentParagraphsAdd;
wdRange:=wdParRange;
wdRange := wordApppActiveDocumentContent;
wdRangeCollapse(wdCollapseEnd);
wordDocTablesAdd(wdRange);
wordDocTablesItem()Cell()RangeText:=向第一個Table的單元格中寫數據;
wordAppSelectionEndKey(wdStoryEmptyParam);
wdPar := end;
wdPar := wordAppActiveDocumentParagraphsAdd;
wdRange := wordAppactiveDocumentContent;
wdRangeCollapse(wdCollapseEnd);
wordDocTablesAdd(wdRange);
wordDocTablesItem()Cell()RangeText:=向第二個Table中寫入數據;
//注意使用wordAppSelectionEndKey將光標調整到輸出的最下方使用Collapse方法也是調整輸出位置的
//給Tables設置底紋wordDocTablesItem()RowsItem()ShadingTexture:=wdTexturePercent;
From:http://tw.wingwit.com/Article/program/Delphi/201311/24763.html