数据导出到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;