熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

Delphi向Word中導出數據

2022-06-13   來源: Delphi編程 

  數據導出到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
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.