• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Delphi操作word表格

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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;


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
matlab实现灰度图像伪彩色处理发布时间:2022-07-18
下一篇:
MATLAB动画显示串口数据【实例】(修正链接)发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap