Blog信息 |
blog名称:注册会计师(注会)练习软件 日志总数:398 评论数量:116 留言数量:27 访问次数:3265593 建立时间:2005年6月6日 |

| |
[delpih编程]【转】delpih 生成word文档 软件技术
吕向阳 发表于 2009/4/2 13:58:28 |
最近帮同学用Delphi 7写的一个数据库应用中的一个功能是将查询的结
果导出到一个Word文档中保存。虽然Delphi 7的Servers面板中提供了
TWordApplication和TWordDocument组件,但是帮助中却几乎没有写它
们的使用方法。于是在中国期刊网上down了许多的相关文章来看,只可
惜几乎都是用Delphi 5写的(Delphi 7中不能兼容),而且都只是简单
的介绍了一下,甚是郁闷。在经过一天的摸索之后终于用Delphi 7实现
了这个功能。代码如下:
//uses Word2000, ComObj;
//WordApp: TWordApplication;
//WordDoc: TWordDocument;
procedure TfrmDetails.btnExportClick(Sender: TObject); //单击
“导出“按钮
var
V:Variant;
Template,NewTemplate,DocumentType,Visible:OleVariant;
itemIndex:OleVariant;
fileName:Olevariant;
NoPrompt,OriginalFormat:OleVariant;
RouteDocument,SaveChanges:OleVariant;
begin
//指定文档的路径和文件名
fileName:='C:\LogAdmin\doc\'+'值班日志'+Trim
(DBTextID.Caption)+'.doc';
//如果该日志的对应Word文档已经存在则提示是否覆盖
if FileExists(fileName)=true then
begin
Beep;
if Application.MessageBox('文档已经存在,是否覆盖?','警
告',MB_OKCANCEL)=IDCANCEL then
Abort;
end;
//测试当前是否运行了Word 2000
try
V:=GetActiveOleObject('Word.Application');
except
//未运行则运行之
V:=CreateOleObject('Word.Basic');
end;
try
//连接到Word 2000
WordApp.Connect;
except
Beep;
MessageDlg('不能生成文档,请确认是否安装了Word
2000!',mtError,[mbOK],0);
Abort;
end;
//显示Word 2000
WordApp.Visible:=true;
//给调用Add函数使用的实参赋值
Template:=EmptyParam;
NewTemplate:=False;
DocumentType:=wdNewBlankDocument;
Visible:=true;
//调用Add函数
WordApp.Documents.Add
(Template,NewTemplate,DocumentType,Visible);
//连接到新建的文档
itemIndex:=1;
WordDoc.ConnectTo(WordApp.Documents.Item(itemIndex));
//文档另存为
WordDoc.SaveAs(fileName);
//开始向Word文档中写入内容
with WordApp.Selection do
begin
Font.Size:=20;
Font.Bold:=2;
Paragraphs.Alignment:=wdAlignParagraphCenter;
TypeText('值班日志详细内容');
TypeParagraph; //换行
TypeParagraph;
Font.Size:=12;
Font.Bold:=0;
Paragraphs.Alignment:=wdAlignParagraphLeft;
TypeText('编号: '+DBTextID.Caption);
TypeParagraph;
TypeText('日期: '+DBTextDate.Caption);
TypeParagraph;
TypeText('温度: '+DBTextT.Caption);
TypeParagraph;
TypeText('湿度: '+DBTextH.Caption);
TypeParagraph;
TypeText('天气: '+DBTextWeather.Caption);
TypeParagraph;
TypeText('值班人: '+DBTextName.Caption);
TypeParagraph;
TypeText('值班时间:'+DBTextTime.Caption);
TypeParagraph;
TypeText('有无异常:'+lbException.Caption);
TypeParagraph;
TypeText('使用工具:');
TypeParagraph;
TypeText(DBMemoTool.Text);
TypeParagraph;
TypeText('现场环境:');
TypeParagraph;
TypeText(DBMemoEnv.Text);
TypeParagraph;
TypeText('记录一: ');
TypeParagraph;
TypeText(DBMemoR1.Text);
TypeParagraph;
TypeText('记录二: ');
TypeParagraph;
TypeText(DBMemoR2.Text);
TypeParagraph;
TypeText('记录三: ');
TypeParagraph;
TypeText(DBMemoR3.Text);
TypeParagraph;
TypeText('备注: ');
TypeParagraph;
TypeText(DBMemoMemo.Text);
TypeParagraph;
end;
//保存文档
NoPrompt:=false;
OriginalFormat:=wdOriginalDocumentFormat;
WordApp.Documents.Save(NoPrompt,OriginalFormat);
//关闭文档
SaveChanges:=wdSaveChanges;
OriginalFormat:=wdOriginalDocumentFormat;
RouteDocument:=false;
WordApp.Documents.Close
(SaveChanges,OriginalFormat,RouteDocument);
//断开和Word 2000的连接
WordApp.Disconnect;
MessageDlg('日志内容导出成功!保存
为'+fileName,mtInformation,[mbOK],0);
//关闭窗体
frmDetails.Close;
end;
|
|
[delpih编程]tms控件 TColumnComboBox 的程序中增加显示行与列(多列显示的combobox) 软件技术
吕向阳 发表于 2009/3/30 21:40:00 |
tms控件 TColumnComboBox 的程序中增加显示行与列
(多列显示的combobox)
procedure TForm1.Button1Click(Sender: TObject);
begin
com1.Columns.Add;//增加显示列1
com1.Columns.Add;//增加显示列2
com1.ComboItems.Add;//增加显示行1
com1.ComboItems.Items[0].Strings.add('001'); //为行1列1 赋值
com1.ComboItems.Items[0].Strings.add('aaa');//为行1列2赋值
com1.ComboItems.Add;//增加显示行2
com1.ComboItems.Items[1].Strings.add('002');//为行2列1 赋值
com1.ComboItems.Items[1].Strings.add('ccb');//为行2列2 赋值
end;
procedure TForm1.com1Change(Sender: TObject);
begin
showmessage(com1.ColumnItems[com1.ItemIndex,0]);//取出选中的返
回值
end;
|
|
[delpih编程]delphi 6控件重名不能安装的解决 软件技术
吕向阳 发表于 2009/3/30 11:17:25 |
delphi中经常会出现安装控件时,原有旧控件存在,新控件与原控件重
名不允话安装的情况。
只要知道相关的控件包名称,再进入
C:\Program Files\Borland\Delphi6\Projects\Bpl路径找到相关的文
件删除即可。
再次进入delphi时会提示该包已不存在,是否查找等提示,按NO进入后
再安装新控件则不存在问题了
|
|
[delpih编程]COMBOBOx同时显示两列数据 软件技术
吕向阳 发表于 2009/3/30 9:14:58 |
objItemEx=Class
public
caption:string;
value:string;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
objItem:ObjItemEx;
i:integer;
begin
for i:=1 to 26 do
begin
objitem:=ObjItemEx.Create;
objitem.caption:='Caption' + inttostr(i);
objitem.value:='value' + inttostr(i);
combobox1.Items.AddObject('ComboBox' + inttostr
(i),objitem);
end;
combobox1.ItemIndex:=0;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
objItem:ObjItemEx;
begin
objitem:=(combobox1.Items.Objects[combobox1.ItemIndex]
as ObjItemEx);
showmessage(objitem.caption);
showmessage(objitem.value );
end;
|
|
|