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

Delphi712操作word

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

//导出Word
procedure TFrm_Computing.ExportWord;
var
wordApp, WordDoc, WrdSelection, wrdtable, wrdtable1, cell: 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;

wdPar:=WordApp.ActiveDocument.Paragraphs.Add;
wdRange:=wdPar.Range;
wdRange := wordApp.ActiveDocument.Content;
wdRange.Collapse(wdCollapseEnd);
iRow := 12;
iCol := 2;
wrdtable := wordDoc.Tables.Add(wdRange,iRow, iCol);
wrdtable.Cell(1, 1).Merge(wrdtable.Cell(1, 2));
wrdtable.Cell(2, 1).Merge(wrdtable.Cell(2, 2));
wrdtable.Cell(1,1).Range.Text:= '打印时间:' + FormatDateTime('yyyy年hh月dd日 hh时MM分ss秒', Now);
wrdtable.Cell(2,1).Range.Text:= '进样时间:' + FormatDateTime('yyyy年hh月dd日 hh时MM分ss秒', Now);
wrdtable.Cell(3,1).Range.Text:= '质检(E)字第()号';
wrdtable.Cell(4,1).Range.Text:= '送样单位:' + 'XXX公司';
wrdtable.Cell(4,2).Range.Text:= '仪器型号:' + 'SC-1001-09A';
wrdtable.Cell(5,1).Range.Text:= '取样日期:' + FormatDateTime('yyyy年hh月dd日 ', Now);
wrdtable.Cell(5,2).Range.Text:= '收样日期:' + FormatDateTime('yyyy年hh月dd日 ', Now);
wrdtable.Cell(6,1).Range.Text:= '样品批号:' + '';
wrdtable.Cell(6,2).Range.Text:= '样品名称:' + '固液';
wrdtable.Cell(7,1).Range.Text:= '样品罐号:' + 'A-1-2';
wrdtable.Cell(8,1).Range.Text:= '仪器文件控制参数:' + '#1111';
wrdtable.Cell(9,1).Range.Text:= '';
wrdtable.Cell(10,1).Range.Text:= 'C:\AAAAAAA\111.bmp';
wrdtable.Cell(11,1).Range.Text:= '';
wrdtable.Cell(12,1).Range.Text:= '';

 


wordApp.selection.TypeParagraph;//换行
wordApp.selection.TypeParagraph;//换行

wordApp.selection.movedown(wdLine, 17);


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;
wrdtable1 := 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
//ShowMessage(SGrid_PeakResult.Cells[J, I]);
wrdtable1.Cell(I +1,J + 1).Range.Text:= SGrid_PeakResult.Cells[J, I];
end;
end;

wrdtable1.columns.item(2).width := 80;
wrdtable1.rows.item(2).Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle; //控制单行是否有线
wrdtable1.rows.item(2).Borders.Item(wdBorderTop).LineWidth:= wdLineWidth150pt; //控制单行的样式的线宽
wrdtable1.Rows.Item(1).Cells.VerticalAlignment:=wdCellAlignVerticalCenter;
wrdtable1.Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle;
wrdtable1.Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderRight).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderHorizontal).LineStyle:=wdLineStyleSingle;
wrdtable1.Borders.Item(wdBorderTop).LineWidth:= wdLineWidth150pt; //
wrdtable1.Borders.Item(wdBorderBottom).LineWidth:= wdLineWidth150pt; //
wrdtable1.Borders.Item(wdBorderBottom).LineStyle:= wdLineStyleSingle; //

 

// wrdtable1.Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderRight).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderHorizontal).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderVertical).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderVertical).LineWidth:= wdLineWidth150pt; //

//选择左边的表格
//Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
//Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
//选择右边的表格
////Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone

end;


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
delphi下如何获得不带扩展名的文件名?发布时间:2022-07-18
下一篇:
vs在matlab生成的dll中,load treebigger错误发布时间: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