//导出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;

Delphi导出word的更多相关文章

  1. delphi 导出到excel的7种方法

    本文来自 爱好者8888 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/kpc2000/article/details/17066823?utm_source=cop ...

  2. Delphi 导出数据至Excel的7种方法【转】

    一; delphi 快速导出excel   uses ComObj,clipbrd;   function ToExcel(sfilename:string; ADOQuery:TADOQuery): ...

  3. Delphi 导出数据至Excel的7种方法

    一; delphi 快速导出excel uses ComObj,clipbrd; function ToExcel(sfilename:string; ADOQuery:TADOQuery):bool ...

  4. java 导出word 并下载

    记录一下导出操作 源码: /************ * 导出word 并下载 * @param id 房号记录编号 * ***********************/ @RequestMappin ...

  5. Asp.net通过模板(.dot/Html)导出Word,同时导出图片

    一.Office组件导出Word(服务器配置麻烦) 需要引用Office的DLL,在下文的附件中,不同的Offic版本用的不一样,虽然高级版本可以兼容低级的,不过,还是统一版本最好 贴上核心代码(转载 ...

  6. 导出Excel And 导出word

      <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx. ...

  7. 使用NPOI2.1.3.1版本导出word附带表格和图片

    原文:http://www.cnblogs.com/afutureBoss/p/4074397.html?utm_source=tuicool&utm_medium=referral 最近项目 ...

  8. Java使用velocity导出word

    效果展示: 使用word编辑好模板

  9. 【吉光片羽】MVC 导出Word的两种方式

    1.直接将Html转成Word.MVC自带FileResult很好用.Html中我们也可以嵌入自己的样式. html: <div id="target"> <st ...

随机推荐

  1. FileInputStream和FileOutStream的使用——文件字节输入/输出流

    最近又退回到java EE的学习,这篇博客就来讲解一下字节流中最重要的两个类FileInputStream和FileOutputStream的用法: FileInputStream:全称是文件字节输入 ...

  2. [LeetCode 题解]:Candy

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

  3. 解决 centos 7 部署 tomcat 后外部不能访问应用(端口、防火墙)

    https://blog.csdn.net/Rebs_Hugo/article/details/85042602

  4. json 登陆协议分析

    登录方式有两种:1)用户名密码登陆,code 为 5401 (2) IMSI和TOKEN 登陆, code 为93 POST /tcpbus/mobile HTTP/1.1Host: clientac ...

  5. [BJ2006] 狼抓兔子

    题目链接:戳我 按理说以dinic\(O(M*N^2)\)的时间复杂度应该是过不去的(呃我也知道这个上界很松).但是最小割确实可以水过去?? 但是本着写正解的精神,我还是学了学平面图和对偶图,跑最短路 ...

  6. eclipse问题 - windows版

    问题:java compiler level does not match the version of the installed java project facet:但是项目仍能运行 解释:项目 ...

  7. Thinkpad R400无线网络一个都不见了!

    今天,我的Thinkpad R400无线网络一个都不见了,用手机测试,家里的无线网络正常.反复开关无线网络控制硬件开关,还是不好使,无线网络那个图标里面,并没有无线网络.上网搜索一下,发现小黑居然还有 ...

  8. 如何构建debian包

        1)安装dh_make如下: sudo apt-get intasll aptitude sudo aptitude install dh_make    2)以jsoncpp为例,说明如何生 ...

  9. AHOI2005航线规划 bzoj1969(LCT缩点)

    题目描述 对Samuel星球的探险已经取得了非常巨大的成就,于是科学家们将目光投向了Samuel星球所在的星系——一个巨大的由千百万星球构成的Samuel星系. 星际空间站的Samuel II巨型计算 ...

  10. HDU3183 贪心/RMQ-ST表

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...