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进行单元格合并操作的更多相关文章

  1. 关于.net Microsoft.Office.Interop.Word组建操作word的问题,如何控制word表格单元格内部段落的样式。

    控制word表格单元格内部文字样式.我要将数据导出到word当中,对于word表格一个单元格中的一段文字,要设置不同的样式,比如第一行文字作为标题要居中,加粗,第二行为正常的正文. 代码如下 publ ...

  2. 001-poi-excel-基础、单元格使用操作

    一.概述 Apache POI是Apache软件基金会的开源项目,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. .NET的开发人员则可以利用NPOI (POI ...

  3. PHPWord中文乱码、单元格合并、动态表格模板解决方案合集

    摘要:  最近一个项目开发要用到PHP技术导出Word文档,采用PHPWord插件,版本为0.6.2 beta,CodePlex已停止维护.网上还有另外一个版本的PhpWord,项目类名大小写上略有不 ...

  4. ExtJS 4.2 Grid组件的单元格合并

    ExtJS 4.2 Grid组件本身并没有提供单元格合并功能,需要自己实现这个功能. 目录 1. 原理 2. 多列合并 3. 代码与在线演示 1. 原理 1.1 HTML代码分析 首先创建一个Grid ...

  5. NPOI 教程 - 2.1单元格合并

    来源:http://liyingchun343333.blog.163.com/blog/static/3579731620091018212990/ 合并单元格在制作表格时很有用,比如说表格的标题就 ...

  6. asp.net使用控件datagrid实现表头单元格合并

    合并的要点: 1.datagid的单元格合并原理是table中tr,td的布局实现; 2.合并的时机实在其datagridcreate事件中实现; 3.认识一个对象TableCellCollectio ...

  7. DataGridView单元格合并

    本文章转载:http://www.cnblogs.com/xiaofengfeng/p/3382094.html 图: 代码就是如此简单 文件下载:DataGridView单元格合并源码 也可以参考: ...

  8. devexpress实现单元格合并以及依据条件合并单元格

    1.devexpress实现单元格合并非常的简单,只要设置属性[AllowCellMerge=True]就可以了,实现效果如下图: 2.但是在具体要求中并非需要所有的相同单元格都合并,可能需要其他的条 ...

  9. SNF快速开发平台MVC-表格单元格合并组件

    1.   表格单元格合并组件 1.1.      效果展示 1.1.1.    页面展现表格合并单元格 图 4.1 1.1.2.    导出excel合并单元格 图 4.2 1.2.      调用说 ...

随机推荐

  1. 你所不知道的ref

    在c#中有个关键字叫ref,它的作用是使参数按引用传递,基本用法如下: class RefExample { static void Method(ref int i) { i = ; } stati ...

  2. 通过jq更改img的src值

    $(".help_ul li:eq(1) img")[0].src; $(".help_ul li:eq(1) img").attr('src','images ...

  3. nginx配置location [=|~|~*|^~] /uri/ { … }用法

    版权声明:https://github.com/wusuopubupt ====== nginx location语法 基本语法:location [=|~|~*|^~] /uri/ { … } = ...

  4. 第二天就跳票 将wikipedia上的英文词条翻译为中文 手动

    忙着改简历一整天,刚说完一天一博,就要跳票了. 还是写点东西吧. 今天又翻译了一个维基百科上的条目,刚过一天就忘了怎么弄,还得回头翻帖子.在这先记一下,省的以后找不到. 1.注册个wiki账号,轻松过 ...

  5. asp.net单点登录(SSO)解决方案

    前些天一位朋友要我帮忙做一单点登录,其实这个概念早已耳熟能详,但实际应用很少,难得最近轻闲,于是决定通过本文来详细描述一个SSO解决方案,希望对大家有所帮助.SSO的解决方案很多,但搜索结果令人大失所 ...

  6. leetcode6 Reverse Words in a String 单词取反

    Reverse Words in a String  单词取反 whowhoha@outlook.com Question: Given an input string s, reverse the ...

  7. 【NGUI】屏幕自适应(不用UIStretch,用UIRoot)---------------good

    原地址:http://blog.csdn.net/lzhq1982/article/details/18814023 这篇文章是转载的,之前用UIStretch做屏幕自适应,但一直有两个硬伤让我难受, ...

  8. Grok debugger

    http://www.cnblogs.com/vovlie/p/4227027.html http://it.taocms.org/10/5802.htm

  9. POJ 3393 Lucky and Good Months by Gregorian Calendar

    http://poj.org/problem?id=3393 题意 : 对于这篇长长的英语阅读,表示无语无语再无语,花了好长时间,终于读完了.题目中规定每周的周六日为假日,其他为工作日,若是一个月的第 ...

  10. Nginx开启Gzip压缩大幅提高页面加载速度(转)

    转自:http://www.cnblogs.com/mitang/p/4477220.html 刚刚给博客加了一个500px相册插件,lightbox引入了很多js文件和css文件,页面一下子看起来非 ...