<script></script>
procedure TExprmResultDlg.PreviewExprmReport;
var
Template, NewTemplate,DocumentType,OleVisible:oleVariant;
strTitle_Prior,strText_Prior,strTitle_Last,strText_Last:String;
begin
Try
Wordapplication1.Connect;
Except
Application.MessageBox('您尚未安装 Word应用程序,请先安装Word2000,然后再运行本程序!',
'系统提示',mb_Ok +MB_ICONWARNING);
Abort;
End;
Template := EmptyParam; //表示不使用模板
NewTemplate := False; //表示新建新建文档的类型为文档
Doc.ConnectTo(WordApplication1.Documents.Add(Template, NewTemplate,DocumentType,OleVisible));
//关闭拼音查找和语法查找,以便提高程序运行的效率
WordApplication1.Options.CheckSpellingAsYouType := False;
WordApplication1.Options.CheckGrammarAsYouType := False;
//添加页眉
AddRepPageHeader(18,Edit_RepHeader.Text,alCenter);
//添加页脚 页码设置
AddRepPageFooder(1,alCenter);
m_wordSesson:= WordApplication1.Selection;
WordFont1.ConnectTo(m_wordSesson.Font);
WordFont1.Name := '宋体';
//输出报告信息
AddParagraphTitle('模块信息');//添加段落标题
strTitle_Prior:='厂站名称:';
strText_Prior:=Edit_FactoryName.Text;
AddParagraphContentSingle(strTitle_Prior,strText_Prior);
strTitle_Prior:='测试人:';
strText_Prior:=Edit_TestPeoson.Text;
strTitle_Last:='测试时间:';
strText_Last:=FormatDateTime('yyyy"年"mm"月"dd"日"',now);
AddParagraphContentDouble(strTitle_Prior,strText_Prior,strTitle_Last,strText_Last);
//输出报告内容
AddParagraphTitle('试验结果');//添加段落标题
WriteReportInformation;
AddParagraphTitle('试验结论');//添加段落标题
m_wordSesson.TypeParagraph;
m_wordSesson.TypeParagraph;
m_wordSesson.TypeParagraph;
Wordapplication1.Disconnect;
end;
procedure TExprmResultDlg.AddRepPageHeader(const nFontSize:integer;const strText:String;Const PageFoodAlign:TPageFoodAlign);//添加页眉
var
alTextAlign:OleVariant;
begin
Case PageFoodAlign of
alLeft:alTextAlign:=wdAlignParagraphLeft;
alCenter:alTextAlign:=wdAlignParagraphCenter;
alRight:alTextAlign:=wdAlignParagraphRight;
alJustify:alTextAlign:=wdAlignParagraphJustify;
end;
WordApplication1.ActiveWindow.ActivePane.View.SeekView :=wdSeekCurrentPageHeader;
WordApplication1.Selection.ParagraphFormat.Alignment := alTextAlign;
WordApplication1.Selection.Font.Size:=18;
WordApplication1.Selection.Font.Color:=ClBlack;
WordApplication1.Selection.InsertAfter(strText);
end;
procedure TExprmResultDlg.AddRepPageFooder(const nFistPageNum:integer;Const PageFoodAlign:TPageFoodAlign);//添加页脚 页码设置
var
mmm,nPageNum,aaa,alTextAlign:OleVariant;
begin
Case PageFoodAlign of
alLeft:alTextAlign:=wdAlignParagraphLeft;
alCenter:alTextAlign:=wdAlignParagraphCenter;
alRight:alTextAlign:=wdAlignParagraphRight;
alJustify:alTextAlign:=wdAlignParagraphJustify;
end;
mmm:=wdLine;
nPageNum:=nFistPageNum;
aaa:=wdFieldPage;
WordApplication1.ActiveWindow.ActivePane.View.SeekView :=wdSeekCurrentPageFooter;
WordApplication1.Selection.Move(mmm,nPageNum);
WordApplication1.Selection.ParagraphFormat.Alignment := alTextAlign;
WordApplication1.Selection.InsertAfter('第');
mmm:=wdCharacter;
WordApplication1.Selection.Move(mmm,nPageNum);
WordApplication1.Selection.Fields.Add(WordApplication1.Selection.Range,aaa,mmm,nPageNum);
aaa:=wdFieldNumPages;
WordApplication1.Selection.InsertAfter('页/共');
WordApplication1.Selection.Move(mmm,nPageNum);
WordApplication1.Selection.Fields.Add(WordApplication1.Selection.Range,aaa,mmm,nPageNum);
WordApplication1.Selection.InsertAfter('页');
WordApplication1.ActiveWindow.ActivePane.View.SeekView := wdSeekMainDocument;
end;
procedure TExprmResultDlg.PastePicToWord(Const imageName:TImage);
var
AFormat:word;
AData :cardinal;
APalette : hpalette;
begin
imageName.Picture.SaveToClipboardFormat(AFormat,AData,APalette);
Clipboard.SetAsHandle(AFormat,AData);
doc.Sentences.Last.Paste;
end;
procedure TExprmResultDlg.AddParagraphTitle(const strTitle:String);//添加段落标题
begin
//加回车键,形成段落:
ParaFmt.SpaceBefore := 30;
ParaFmt.SpaceAfter := 30;
//m_wordSesson.TypeParagraph;
WordFont1.Size:=14;
WordFont1.Bold:=1;
m_wordSesson.TypeText(strTitle + #13);
m_tableNum:=m_tableNum + 1;
end;
procedure TExprmResultDlg.AddParagraphContentSingle(Const strTitle,strText:String);
var
i:integer;
TableBehavior,AutoFitbehavior:oleVariant;
begin
TableBehavior:=FALSE;
AutoFitbehavior:=FALSE;
Doc.Tables.Add(WordApplication1.Selection.Range, 1 , 4, TableBehavior,AutoFitbehavior);//创建表格
m_tableRow:=m_tableRow + 1;
for i:=1 to 4 do
begin
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Font.Size := 12;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Font.Bold:=0;
//去掉表格边框
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Borders.item(wdBorderLeft).LineStyle := wdLineStyleNone;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Borders.item(wdBorderRight).LineStyle := wdLineStyleNone;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Borders.item(wdBorderTop).LineStyle := wdLineStyleNone;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Borders.item(wdBorderBottom).LineStyle := wdLineStyleNone;
end;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,2).Merge(Doc.Tables.Item(m_tableNum).Cell(m_tableRow,3));
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,2).Merge(Doc.Tables.Item(m_tableNum).Cell(m_tableRow,3));
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,1).Range.ParagraphFormat.Alignment:=wdAlignParagraphRight;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,2).Range.ParagraphFormat.Alignment:=wdAlignParagraphLeft;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,1).Range.Text:=strTitle;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,2).Range.Text:=strText;
WordApplication1.Selection.SetRange(100 * m_tableRow,100 * m_tableRow);//设定段落范围
end;
procedure TExprmResultDlg.AddParagraphContentDouble(Const strTitle_Prior,strText_Prior,strTitle_Last,strText_Last:String);
var
i:integer;
TableBehavior,AutoFitbehavior:oleVariant;
begin
TableBehavior:=FALSE;
AutoFitbehavior:=FALSE;
Doc.Tables.Add(WordApplication1.Selection.Range, 1 , 4, TableBehavior,AutoFitbehavior);//创建表格
m_tableRow:=m_tableRow + 1;
for i:=1 to 4 do
begin
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Font.Size := 12;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Font.Bold:=0;
//去掉表格边框
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Borders.item(wdBorderLeft).LineStyle := wdLineStyleNone;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Borders.item(wdBorderRight).LineStyle := wdLineStyleNone;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Borders.item(wdBorderTop).LineStyle := wdLineStyleNone;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,i).Range.Borders.item(wdBorderBottom).LineStyle := wdLineStyleNone;
end;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,1).Range.ParagraphFormat.Alignment:=wdAlignParagraphRight;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,2).Range.ParagraphFormat.Alignment:=wdAlignParagraphLeft;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,3).Range.ParagraphFormat.Alignment:=wdAlignParagraphRight;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,4).Range.ParagraphFormat.Alignment:=wdAlignParagraphLeft;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,1).Range.Text:=strTitle_Prior;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,2).Range.Text:=strText_Prior;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,3).Range.Text:=strTitle_Last;
Doc.Tables.Item(m_tableNum).Cell(m_tableRow,4).Range.Text:=strText_Last;
WordApplication1.Selection.SetRange(100 * m_tableRow,100 * m_tableRow);//设定段落范围
end;
分享到:
相关推荐
Delphi与Word之间的融合技术
Delphi中使用Olecontainer打开Word文档后,并实现打印功能
DELPHI 2010 调用word,直接在程序中显示word 的信息。
Delphi版Word文档批量合并、文字替换、修改、插入图片程序
delphi word中图片 通过clipboard 拷贝到 jpg文件
使用Delphi 7控制Word 2000生成文档的方法.
delphi 控制 WORD delphi 控制 WORD delphi 控制 WORD
delphi7操作word,插入文字,表格
Delphi开发的Word文档批量处理程序,可批量Word文字替换,批量字体修改、批量插入图片,批量合并Word文档、删除指定页等功能,还可以批量新建文档。关于本程序的使用说明: 1、系统将根据样版文件复制成多个文件;...
delphi 10.2 实现的 向word 标注了书签的位置插入 文字,或者图片。内码亲测可以。。里面路径自己替换下就ok了。免费供新手参考
Delphi代码,实现了对Word内容的读取,代码中是按段落读取!
描述使用Delphi控制Word文件,实现Word打印、查找、替换等功能,主要用于使用delphi处理word文档
delphi 将word 转换成txt
delphi用ole方式操作word, 环境delphiXE,支持word2010 Word 97 - 2003
delphi ole word.rar
Delphi操作word文档,实现word功能
一个DELPHI操作WORD的实例,图文并茂,很有参考价值
Delphi使用Word自动化服务器插入数据到Word程序中,这个程序演示了使用Word作为自动化服务器,Delphi地自动化控制器是如何将一个查询结果插入到word文档中,返回应用参数.这个调用在英文和法文版的 Word中相同。对...
delphi 操作 word excel
在word中插入表格,对行、列进行操作。本人在开发项目中所写。对于在项目开发中涉及到word表格操作很有用。delphi源码。