delphi通过OLE对word进行单元格合并操作

uses comobj, word2000
procedure TForm1.Button2Click(Sender: TObject);
var
WordApp, WordDoc,table: OleVariant;
fileName : string;
begin
WordApp := CreateOleObject('Word.Application');
WordDoc := WordApp.Documents.Add;
try
WordDoc.PageSetup.LeftMargin := 0.39*72; // 1 英寸 = 72 磅
WordDoc.PageSetup.RightMargin := 0.39*72; // 1 英寸 = 72 磅
WordDoc.PageSetup.TopMargin := 1*72; // 1 英寸 = 72 磅
WordDoc.PageSetup.BottomMargin := 1*72; // 1 英寸 = 72 磅
WordDoc.PageSetup.PaperSize := wdPaperA4; //A4纸
WordApp.Selection.Font.Name := '黑体';
WordApp.Selection.Font.Size := 22;//二号字体 单位:磅
WordApp.Selection.Font.Bold := True;//字体加粗
WordApp.Selection.Font.Color := wdColorBlue;//字体颜色
WordApp.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter; //段落中文本居中
WordApp.Selection.ParagraphFormat.LineSpacingRule := wdLineSpaceSingle;//单倍行距
WordApp.Selection.TypeText('学生对教师教学工作总体评价');
WordApp.Selection.TypeParagraph;//回车
WordApp.Selection.TypeParagraph;//回车
table := WordApp.ActiveDocument.Tables.Add(WordApp.ActiveDocument.Paragraphs.item(3).Range,2,5); //往第三段增加一表格(2行5列)
WordApp.Selection.Font.Name := '宋体';
WordApp.Selection.Font.Size := 9;
WordApp.Selection.Font.Bold := False;
WordApp.Selection.Font.Color := wdColorBlack;
table.cell(1,1).VerticalAlignment := wdCellAlignVerticalCenter;
WordApp.Selection.TypeText('教师姓名');
table.Cell(1, 1).Merge(table.Cell(2, 1));
table.Cell(1, 2).Merge(table.Cell(1, 5));
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.Font.Name := '宋体';
WordApp.Selection.Font.Color := wdColorBlue;
WordApp.Selection.Font.Bold := True;
WordApp.Selection.Font.Size := 12;
WordApp.Selection.TypeText('对 教 师 教 学 工 作 的 综 合 评 价');
WordApp.Selection.TypeParagraph;
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.Font.Name := '宋体';
WordApp.Selection.Font.Color := wdColorBlack;
WordApp.Selection.Font.Bold := True;
WordApp.Selection.Font.Size := 12;
WordApp.Selection.TypeText('A');
WordApp.Selection.TypeParagraph;
WordApp.Selection.Font.Size := 9;
WordApp.Selection.Font.Bold := False;
WordApp.Selection.TypeText('非常满意');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.Font.Name := '宋体';
WordApp.Selection.Font.Color := wdColorBlack;
WordApp.Selection.Font.Bold := True;
WordApp.Selection.Font.Size := 12;
WordApp.Selection.TypeText('B');
WordApp.Selection.TypeParagraph;
WordApp.Selection.Font.Size := 9;
WordApp.Selection.Font.Bold := False;
WordApp.Selection.TypeText('满意');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.Font.Name := '宋体';
WordApp.Selection.Font.Color := wdColorBlack;
WordApp.Selection.Font.Bold := True;
WordApp.Selection.Font.Size := 12;
WordApp.Selection.TypeText('C');
WordApp.Selection.TypeParagraph;
WordApp.Selection.Font.Size := 9;
WordApp.Selection.Font.Bold := False;
WordApp.Selection.TypeText('基本满意');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.Font.Name := '宋体';
WordApp.Selection.Font.Color := wdColorBlack;
WordApp.Selection.Font.Bold := True;
WordApp.Selection.Font.Size := 12;
WordApp.Selection.TypeText('D');
WordApp.Selection.TypeParagraph;
WordApp.Selection.Font.Size := 9;
WordApp.Selection.Font.Bold := False;
WordApp.Selection.TypeText('不满意');
WordApp.Selection.MoveRight(wdCell,1);//新增一行
WordApp.Selection.Font.Name := '宋体';
WordApp.Selection.Font.Color := wdColorBlack;
WordApp.Selection.Font.Bold := false;
WordApp.Selection.Font.Size := 10.5;
WordApp.Selection.TypeText('教师A');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.Font.Name := '宋体';
WordApp.Selection.Font.Color := wdColorBlack;
WordApp.Selection.Font.Bold := true;
WordApp.Selection.Font.Size := 12;
WordApp.Selection.TypeText('94');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.TypeText('6');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.TypeText('0');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.TypeText('0');
WordApp.Selection.MoveRight(wdCell,1);//新增一行
WordApp.Selection.Font.Name := '宋体';
WordApp.Selection.Font.Color := wdColorBlack;
WordApp.Selection.Font.Bold := false;
WordApp.Selection.Font.Size := 10.5;
WordApp.Selection.TypeText('教师B');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.Font.Name := '宋体';
WordApp.Selection.Font.Color := wdColorBlack;
WordApp.Selection.Font.Bold := true;
WordApp.Selection.Font.Size := 12;
WordApp.Selection.TypeText('92');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.TypeText('8');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.TypeText('0');
WordApp.Selection.MoveRight(wdCell,1);
WordApp.Selection.TypeText('0');
table.Rows.Alignment := wdAlignRowCenter;//表格居中
table.Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleSingle;
table.Borders.Item(wdBorderRight).LineStyle:=wdLineStyleSingle;
table.Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle;
table.Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleSingle;
table.Borders.Item(wdBorderHorizontal).LineStyle:=wdLineStyleSingle;
table.Borders.Item(wdBorderVertical).LineStyle:=wdLineStyleSingle;
fileName := ExtractFilePath(ParamStr(0)) + '总体总评.doc';
WordDoc.saveas(fileName);
finally
WordDoc.Saved := True;
WordDoc.Close;
WordApp.Quit;
end;
ShowMessage('ok');
end;
delphi通过OLE对word进行单元格合并操作的更多相关文章
- 关于.net Microsoft.Office.Interop.Word组建操作word的问题,如何控制word表格单元格内部段落的样式。
控制word表格单元格内部文字样式.我要将数据导出到word当中,对于word表格一个单元格中的一段文字,要设置不同的样式,比如第一行文字作为标题要居中,加粗,第二行为正常的正文. 代码如下 publ ...
- 001-poi-excel-基础、单元格使用操作
一.概述 Apache POI是Apache软件基金会的开源项目,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. .NET的开发人员则可以利用NPOI (POI ...
- PHPWord中文乱码、单元格合并、动态表格模板解决方案合集
摘要: 最近一个项目开发要用到PHP技术导出Word文档,采用PHPWord插件,版本为0.6.2 beta,CodePlex已停止维护.网上还有另外一个版本的PhpWord,项目类名大小写上略有不 ...
- ExtJS 4.2 Grid组件的单元格合并
ExtJS 4.2 Grid组件本身并没有提供单元格合并功能,需要自己实现这个功能. 目录 1. 原理 2. 多列合并 3. 代码与在线演示 1. 原理 1.1 HTML代码分析 首先创建一个Grid ...
- NPOI 教程 - 2.1单元格合并
来源:http://liyingchun343333.blog.163.com/blog/static/3579731620091018212990/ 合并单元格在制作表格时很有用,比如说表格的标题就 ...
- asp.net使用控件datagrid实现表头单元格合并
合并的要点: 1.datagid的单元格合并原理是table中tr,td的布局实现; 2.合并的时机实在其datagridcreate事件中实现; 3.认识一个对象TableCellCollectio ...
- DataGridView单元格合并
本文章转载:http://www.cnblogs.com/xiaofengfeng/p/3382094.html 图: 代码就是如此简单 文件下载:DataGridView单元格合并源码 也可以参考: ...
- devexpress实现单元格合并以及依据条件合并单元格
1.devexpress实现单元格合并非常的简单,只要设置属性[AllowCellMerge=True]就可以了,实现效果如下图: 2.但是在具体要求中并非需要所有的相同单元格都合并,可能需要其他的条 ...
- SNF快速开发平台MVC-表格单元格合并组件
1. 表格单元格合并组件 1.1. 效果展示 1.1.1. 页面展现表格合并单元格 图 4.1 1.1.2. 导出excel合并单元格 图 4.2 1.2. 调用说 ...
随机推荐
- Runtime 实现 动态添加属性
利用动态加载为对象添加一个 block 点击属性; .h 文件 #import <UIKit/UIKit.h> @interface UIView (Tap) /** * 动态添加手势 * ...
- 使用maven配置基本Mybatis
Mybatis 也称为是ibatis,主要体现在普通.底层SQL查询.存储过程.高级映射的持久化框架! 优点: 1.消除了几乎所 ...
- JS创建类和对象
JavaScript 创建类/对象的几种方式 在JS中,创建对象(Create Object)并不完全是我们时常说的创建类对象,JS中的对象强调的是一种复合类型,JS中创建对象及对对象的访问是极其灵活 ...
- java小提示:标示符常见命名规则、常用ASCII
标示符常见命名规则: A:包:全部小写B:类或者接口:首字母大写:StudentC:方法或者接口:首字母小写,第二个单词开始开始,每个单词首字母大写:studentAgeD:常量:全部大写,多个单词之 ...
- Linux下去掉^M的方法
cat -A filename 就可以看到windows下的断元字符 ^M 要去除他,最简单用下面的命令: dos2unix filename 第二种方法: sed -i 's/^M//g ...
- Executing a script from Nagios event handler fails to run
I have Nagios running on a webserver. For this one Nagios service check in particular, if it fails, ...
- Maven打包时囊括本地依赖的jar包
在开发中,偶尔会遇到一个问题:某些比较冷门的包,maven服务器上没有,而我们又必须用,通常情况下会在项目中建立一个lib文件夹.将这些包copy进去并加入buildpath,开发就可以继续了,如下图 ...
- 深入理解ClassLoader(四)—类的父委托加载机制
上几次我们介绍到了JVM内部的几个类加载器,我们来重新画一下这个图,再来看一下他们之间的关系.
- live555源码研究(二)------TaskScheduler类
一.TaskScheduler类作用 1,他是使用环境的一部分. 2,他提供了对socket触发事件的管理. 二.类TaskScheduler继承关系图 二.TaskScheduler成员函数 1,s ...
- 使用QGridLayout布局实现翻页效果
http://blog.csdn.net/u013704336/article/details/51474942