博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Delphi之word报表
阅读量:7040 次
发布时间:2019-06-28

本文共 3100 字,大约阅读时间需要 10 分钟。

先上图:

delphi实现代码如下:

procedure TForm1.ToolButton12Click(Sender: TObject);var myTable: Table;oleCount,oleUnit: Olevariant; begin //以下打开word新的文档tryWordApplication1.Connect;WordApplication1.Caption := '打印故障记录';WordApplication1.Visible := true;exceptMessageDlg('也许word没有安装,请重试', mtError, [mbOk], 0);end; WordDocument1.ConnectTo(WordApplication1.Documents.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam));WordDocument1.Activate;//设置页面大小和左右间距 //600磅=21cm,850磅=29.7cm,是标准A4纸张大小,每磅0.035cm, WordDocument1.PageSetup.PageWidth := 600;WordDocument1.PageSetup.PageHeight := 850;WordDocument1.PageSetup.LeftMargin := 50;WordDocument1.PageSetup.RightMargin := 50;//设置标题内容和字体WordApplication1.Selection.Font.Size := 15;WordApplication1.Selection.Font.Name := '黑体';WordApplication1.Selection.Font.Color := clBlack;WordApplication1.Selection.Font.Bold := 1;WordApplication1.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter;WordApplication1.Selection.TypeText('故障记录');//设置正文内容和字体 WordApplication1.Selection.Font.Size := 11;WordApplication1.Selection.Font.Name := '宋体';WordApplication1.Selection.Font.Color := clBlack;WordApplication1.Selection.Font.Bold := 0;WordApplication1.Selection.TypeParagraph;WordApplication1.Selection.TypeParagraph;WordApplication1.Selection.ParagraphFormat.Alignment := wdAlignParagraphJustify;//以下插入表格 oleUnit := wdLine;oleCount := 3; MyTable := WordApplication1.Selection.Tables.Add(WordApplication1.Selection.Range,3,2,EmptyParam,EmptyParam);MyTable.Cell(1,1).Height := 20;MyTable.Cell(1,1).Range.Text := '试验日期:' +form4.adoQuery1.FieldByName('试验时间').AsString;MyTable.Cell(1,2).Range.Text := '试验人员:' +form4.adoQuery1.FieldByName('试验人员1').AsString+'/'+form4.adoQuery1.FieldByName('试验人员2').AsString;MyTable.Cell(2,1).Height := 20;MyTable.Cell(3,1).Height := 20;MyTable.Cell(4,1).Height := 20;MyTable.Cell(2,1).Range.Text := '最大加速度:';MyTable.Cell(2,2).Range.Text := iplot1.Channel[2].DataCursorYText;MyTable.Cell(3,1).Range.Text := '最大拉力:';MyTable.Cell(3,2).Range.Text := iplot1.Channel[0].DataCursorYText;//下移2行添加新的表格,因为上下的列数不一样WordApplication1.Selection.MoveDown(oleUnit,oleCount,EmptyParam);MyTable := WordApplication1.Selection.Tables.Add(WordApplication1.Selection.Range,6,1,EmptyParam,EmptyParam);MyTable.Cell(4,1).Height := 20;MyTable.Cell(5,1).Height := 20;MyTable.Cell(6,1).Height := 20;MyTable.Cell(7,1).Height := 20;MyTable.Cell(8,1).Height := 20;MyTable.Cell(9,1).Height := 20;MyTable.Cell(4,1).Range.Text := '采样频率:'+'20000';MyTable.Cell(5,1).Range.Text := '加速度传感器1信息:'+form4.adoQuery1.FieldByName('加速度传感器1编号').AsString;  MyTable.Cell(6,1).Range.Text := '加速度传感器2信息:'+form4.adoQuery1.FieldByName('加速度传感器2编号').AsString;MyTable.Cell(7,1).Range.Text := '加速度传感器3信息:'+form4.adoQuery1.FieldByName('加速度传感器3编号').AsString;MyTable.Cell(8,1).Range.Text := '力传感器1信息:'+form4.adoQuery1.FieldByName('力传感器1编号').AsString;MyTable.Cell(9,1).Range.Text := '力传感器1信息:'+form4.adoQuery1.FieldByName('力传感器1编号').AsString;end;

该代码在按钮响应函数中写入,其中需包含

uses WordXP
WordApplication1:表示WordApplication控件
WordDocument1:表示WordDocument控件 还需要WordFont控件描述字体。

转载于:https://www.cnblogs.com/kevin-tyc/p/3326926.html

你可能感兴趣的文章
jar包制作
查看>>
华为服务器RH2288H V2连接 华为存储S2600T
查看>>
ActiveMQ快速入门
查看>>
HTTP请求头和响应头部包括的信息有哪些?
查看>>
Spring学习总结(2)——Spring的常用注解
查看>>
JSON
查看>>
贝叶斯相关(概率论)论文
查看>>
在ECS上搭建阿里云数据库RDS的只读实例
查看>>
Go语言开发(二十一)、GoMock测试框架
查看>>
Java基础学习总结(2)——接口
查看>>
MyBatis学习总结(三)——优化MyBatis配置文件中的配置
查看>>
Linux实用工具
查看>>
北大高材生被华为辞退:用不用你,与能力无关!
查看>>
21分钟Mysql入门教程
查看>>
Java的Struts多模块的应用
查看>>
自定义缓存类
查看>>
C++11: Multi-Thread思考.
查看>>
RFID设备管理C#客户端学习笔记之1:布局
查看>>
sads
查看>>
NodeJs 开始篇
查看>>