Delphi通过OLE对word进行单元格合并操作
2017-09-20 14:19
501 查看
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进行单元格合并操作
- delphi通过OLE对word进行单元格合并操作
- 在Delphi中使用CreateOleObject方法对WORD文件进行操作
- Delphi Ole操作Word,判断是否有打开的文档,并且给关闭
- java平台下通过jacob对excel,word进行打印等操作
- java平台下通过jacob对excel,word进行打印等操作
- C#操作word:将rtf中的ole对象通过MathType转换成MathML
- 在Delphi中使用CreateOleObject方法对WORD文件进行操作
- java平台下通过jacob对excel,word进行打印等操作
- Delphi Ole操作Word,判断是否有打开的文档,并且给关闭
- Delphi中通过OLE来操作Excel
- DELPHI通过ACTIVESYNC连接到移动设备,并进行文件的复制,删除等操作!
- 通过ole 操作Excel
- Delphi之通过ADOX操作access数据库
- word正在等候其他应用程序完成OLE操作
- 通过java程序对xml文件进行简单操作
- EEPROM通过IIC协议进行读写操作
- Delphi开发学习二:使用ADOQuery控件对SQL数据库表进行操作
- 演示:通过触发器对数据库进行级联操作
- 通过LDAP在AD域控上进行添加、删除、修改、查询等各种操作