码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi 操作word 表格

时间:2016-03-07 10:11:50      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

var
wordApp, WordDoc, WrdSelection, wrdtable: variant;
strAdd: string;
wdPar,wdRange:OleVariant;
iCol, iRow, I, J: Integer;

begin

try
wordApp := CreateOleObject(‘Word.Application‘);
except
Application.MessageBox(‘Word没有安装‘, ‘提示信息‘, MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Exit;
end;
Self.Chart_Edit.CopyToClipboardBitmap;
wordApp.Visible := true;
wordDoc:=WordApp.Documents.Add();
wordDoc.select;
wrdSelection := WordApp.selection;
strAdd:=‘XXX分析报告‘;
//strAdd:= Format(strAdd, [FormatDateTime(‘YYYY‘, Date), WeekofYear(Date)]);
wrdSelection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
// wrdSelection.Font.bold := true;
// wrdSelection.Font.Size := 15;
// wrdSelection.TypeText(strAdd);
// wordApp.selection.TypeParagraph;//换行
// wrdSelection.Font.bold := false;
// wrdSelection.Font.Size := 10;
// wrdSelection.Font.bold := false;
// wrdSelection.ParagraphFormat.Alignment:=wdAlignParagraphLeft;
// wrdSelection.TypeText(‘打印时间:‘ + FormatDateTime(‘yyyy年hh月dd日 hh时MM分ss秒‘, Now));
// strAdd := ‘进样时间:‘ + FormatDateTime(‘yyyy年hh月dd日 hh时MM分ss秒‘, Now) + ‘ , 操作人:unknown‘;
// wrdSelection.TypeText(stradd);
// wordApp.selection.TypeParagraph;//换行
// strAdd := ‘质检(E)字第()号‘;
// wrdSelection.TypeText(stradd);
// wordApp.selection.TypeParagraph;//换行
// strAdd := ‘进样单位: ‘ + ‘ 仪器型号:SC-1001-09A‘;
// wrdSelection.TypeText(stradd);
// wordApp.selection.TypeParagraph;//换行
// strAdd := ‘取样日期:‘ + FormatDateTime(‘yyyy年hh月dd日 ‘, Now) + ‘ 取样日期:‘ + FormatDateTime(‘yyyy年hh月dd日 ‘, Now);
// wrdSelection.TypeText(stradd);
// wordApp.selection.TypeParagraph;//换行
// strAdd := ‘样品批号: ‘ + ‘ 样品名称:固液‘ ;
// wrdSelection.TypeText(stradd);
// wordApp.selection.TypeParagraph;//换行
// strAdd := ‘样品罐号: ‘ ;
// wrdSelection.TypeText(stradd);
wordApp.selection.TypeParagraph;//换行
wordApp.selection.paste;
wordApp.selection.TypeParagraph;//换行
wordApp.selection.TypeParagraph;//换行
wordApp.selection.TypeParagraph;//换行

wdPar:=WordApp.ActiveDocument.Paragraphs.Add;
wdRange:=wdPar.Range;
wdRange := wordApp.ActiveDocument.Content;
wdRange.Collapse(wdCollapseEnd);
iRow := SGrid_PeakResult.RowCount;
iCol := SGrid_PeakResult.ColCount;
wrdtable := wordDoc.Tables.Add(wdRange,iRow, iCol);
for I := 0 to SGrid_PeakResult.RowCount -1 do
begin
for J := 0 to SGrid_PeakResult.ColCount -1 do
begin
wrdtable.Cell(I,J).Range.Text:= SGrid_PeakResult.Cells[J, I];
end;
end;
wrdtable.Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleSingle;
wrdtable.Borders.Item(wdBorderRight).LineStyle:=wdLineStyleSingle;
wrdtable.Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle;
wrdtable.Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleSingle;
wrdtable.Borders.Item(wdBorderHorizontal).LineStyle:=wdLineStyleSingle;
wrdtable.Borders.Item(wdBorderVertical).LineStyle:=wdLineStyleSingle;
wrdtable.Borders.Item(wdBorderVertical).LineWidth:= wdLineWidth150pt; //

end;

Delphi 操作word 表格

标签:

原文地址:http://www.cnblogs.com/zhangzhifeng/p/5249487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!