//导出Word
procedure TFrm_Computing.ExportWord(aFileName: string; aFileType: string);
var
wordApp, WordDoc, WrdSelection, wrdtable, wrdtable1, cell: variant;
strAdd: string;
wdPar,wdRange:OleVariant;
iCol, iRow, I, J: Integer;
vNode: TcxTreeListNode;
vcolumn: TcxTreeListColumn;
str: string;
begin

try
wordApp := CreateOleObject('Word.Application');
except
Application.MessageBox('Word没有安装', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Exit;
end;
Self.cht_Edit.CopyToClipboardBitmap;
wordApp.Visible := false;
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 := RzRichEdit_ReportTop.Lines.Count;
iCol := 1;
wrdtable := wordDoc.Tables.Add(wdRange,iRow, iCol);
for I := 0 to RzRichEdit_ReportTop.Lines.Count -1 do
begin
wrdtable.Cell(I, 1).Range.Text := RzRichEdit_ReportTop.Lines.Strings[I];
end;

wordApp.selection.TypeParagraph;//换行

wordApp.selection.movedown(wdLine, 17);

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

wdPar:=WordApp.ActiveDocument.Paragraphs.Add;
wdRange:=wdPar.Range;
wdRange := wordApp.ActiveDocument.Content;
wdRange.Collapse(wdCollapseEnd);

iRow := SGrid_PeakResult.Count;
iCol := SGrid_PeakResult.ColumnCount;
wrdtable1 := wordDoc.Tables.Add(wdRange,iRow, iCol);
for I := 0 to SGrid_PeakResult.Count -1 do
begin
vNode := SGrid_PeakResult.Items[I];
for J := 0 to SGrid_PeakResult.ColumnCount -1 do
begin
vcolumn := SGrid_PeakResult.Columns[J];
wrdtable1.Cell(I +1,J + 1).Range.Text:= vNode.Texts[vcolumn.ItemIndex];
end;
end;

wrdtable1.columns.item(2).width := 60;
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.columns.item(3).width := 60;
wrdtable1.columns.item(4).width := 60;
wrdtable1.columns.item(8).width := 60;

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

wdPar:=WordApp.ActiveDocument.Paragraphs.Add;
wdRange:=wdPar.Range;
wdRange := wordApp.ActiveDocument.Content;
//该方法用于将指定区域折叠到起始位置或结束位置。
wdRange.Collapse(wdCollapseEnd);

iRow := RzRichEdit_ReportBottom.Lines.Count;
iCol := 1;
wrdtable := wordDoc.Tables.Add(wdRange,iRow, iCol);
for I := 0 to RzRichEdit_ReportBottom.Lines.Count -1 do
begin
wrdtable.Cell(I, 1).Range.Text := RzRichEdit_ReportBottom.Lines.Strings[I];
end;

wordApp.Visible := True;
if AnsiSameText(aFileType, 'doc') then
begin
wordDoc.saveas(aFileName, wdFormatDocument);
end
else if AnsiSameText(aFileType, 'rtf') then
begin
str := aFileName;
str := ChangeFileExt(str , '.rtf');
wordDoc.saveas(str, wdFormatRTF);
end;

end;

delphi 712 Word 2的更多相关文章

  1. Delphi读取Word

    Delphi读取Word现在关于往Word中写入数据的方法比较多,现在专门开个贴子,希望大家把自己读取Word内容的心得体会说一下,包括读取word文档中,有几个段落,如何读取第几个段落,读取有拼音的 ...

  2. delphi控制 word的几种方法--转

    对几种方法的难易程度的判别 a.通过Delphi的控件TOleContainer 将Word嵌入 这是最简单的Ole嵌入,能够直接将Word文档调用,只需要使用ToleContainer.Run就可以 ...

  3. Delphi 统计Word文档中的字数

    急待解决的问题就是如何用delphi实现word中的统计字数 另外想多了解一些关于操作word的相关内容 比如用ole动态创建的和TWordApplication的偏重点在哪里,有什么不同等等…… 用 ...

  4. delphi控制word 标题 字符和位置

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  5. Delphi 712操作word

    //导出Wordprocedure TFrm_Computing.ExportWord;var wordApp, WordDoc, WrdSelection, wrdtable, wrdtable1, ...

  6. 用Delphi进行word开发

    使用以CreateOleObjects方式调用Word 实际上还是Ole,但是这种方式能够真正做到完全控制Word文件,能够使用Word的所有属性,包括自己编写的VBA宏代码.------------ ...

  7. Delphi对Word的基本操作

    一.Delphi程序启动Word 采用CreateOleObjects的方法来启动Word,调用VBA代码,具体实现过程为: 首先使用GetActiveOleObject('Word.Applicat ...

  8. Delphi 运行Word VBA 宏 删除软回车

    Sub 整理网页()'整理网页:删除软回车.删除空白段.使段落文字两端对齐Selection.WholeStory        Selection.Find.ClearFormatting    S ...

  9. delphi 操作 word

        uses  ComObj,word2000   procedure TForm1.ExportWord(); var FWord :Variant; FDoc :Variant; i,Row: ...

随机推荐

  1. mysql 支持中文,防止程序乱码的方法

    1. 查看你的mysql的字符设置 mysql> show variables like 'character%'; +--------------------------+---------- ...

  2. MyBatis笔记——Mapper动态代理

    前提概要 Mapper接口开发方法只需要程序员编写Mapper接口(相当于Dao接口),由Mybatis框架根据接口定义创建接口的动态代理对象,代理对象的方法体同上边Dao接口实现类方法. Mappe ...

  3. centos 安装jdk

    不要使用yum 安装openjdk,他妈的就是一坑货 首先到官网下载jdk,http://www.oracle.com/technetwork/java/javase/downloads/jdk7-d ...

  4. jQuery deferred when用法

    一.什么是deferred对象? 开发网站的过程中,我们经常遇到某些耗时很长的javascript操作.其中,既有异步的操作(比如ajax读取服务器数据),也有同步的操作(比如遍历一个大型数组),它们 ...

  5. framwork NHibernate

    NHibernate 一.NHibernate 1.HQL  curd语句总结 . 查询整个映射对象所有字段 ? //直接from查询出来的是一个映射对象,即:查询整个映射对象所有字段 String ...

  6. 同一Session中的aspx页面的并发限制

    项目中客户端采用WebBrowser展示aspx页面,用户有可能打开带多个带WebBrowser的winform窗体.此时,如果其中一个的WebBrowser的aspx页面响应较长的话,其他窗体中的W ...

  7. win7下制作ubuntu系统安装启动盘和U盘安装ubuntu全过程

    在我搞坏了两个系统之后,一切都得从头开始了,这回好了,电脑就是一台裸机了.没办法,重新下win7吧.这个要先做一个win7的启动盘,然后再安装,只能说我技术不行,没能把win7搞定.让大神给装的win ...

  8. 【转】Android Gson的使用

    Android Gson 2014 年 05 月 22 日 android 目前的客户端大都有和服务端进行交互,而数据的格式基本就是json了,于是在Android开发中就经常用到json解析,方便的 ...

  9. iOS9 class dump header

    获取系统私有API,网上有很多资料总结了一下就三种方式: 使用class-dump可以提取系统私有API列表 使用class-dump+DumpFrameworks.pl,这个可以一次性提取所有系统F ...

  10. POJ 1976 A Mini Locomotive【DP】

    题意:给出一列火车,可以由三个火车头拉,每个火车头最多拉m节车厢(这m节车厢需要保持连续),再给出n节车厢,每节车厢的人数,问最多能够载多少人到终点. 可以转化为三个长度相等的区间去覆盖n个数,使得这 ...