Delphi与Word(三)取得Word文件的数据
2003-06-04 17:16
543 查看
//取得Word文件的数据
procedure getWordStr;
var WordApp: TWordApplication;
??? WordDoc: TWordDocument;
??? DocInx,oFileName,CfCversions,oReadOnly,AddToRctFiles,PswDocument,
??? PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat: OleVariant;
??? i,iRow,iCol:integer;
??? myCell:Cell;
??? myRow:Row;
begin
? memo1.Lines.Clear ;
??? // ===== 创建对象 =====
??? if not Assigned(WordApp) then?????????????????????????
??? begin
????? WordApp:= TWordApplication.Create(nil);
????? WordApp.Visible := false;
??? end;
??? if not Assigned(WordDoc) then
????? WordDoc:= TWordDocument.Create(nil);
? try
??? DocInx:=1;
??? oFileName := 'd:/test.doc';
??? oReadOnly:=true;
??? CfCversions := EmptyParam;
??? AddToRctFiles:= EmptyParam;
??? PswDocument:= EmptyParam;
??? PswTemplate:= EmptyParam;
??? oRevert:= EmptyParam;
??? WPswDocument:= EmptyParam;
??? WPswTemplate:= EmptyParam;
??? oFormat:= EmptyParam;????
??? // ===== 打开文件 =====????????????????????????
??? WordApp.Documents.open(oFileName,CfCversions,oReadOnly,AddToRctFiles,
?????? PswDocument,PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat);
??? // ===== 关联文件 =====
??? WordDoc.ConnectTo(WordApp.Documents.Item(DocInx));
??? //方法(1): 取整个文本的字符内容,包含表格
??? s := WordDoc.Range.text;?
??? //方法(2): 取 1 -- 4 位的字符 ,包含表格
??? myRange:=WordDoc.Range;
??? myRange.Start:=0;
??? myRange.End_ :=4;
? finally
??? if Assigned(WordDoc) then????????????? // ===== 关闭文件 =====
??? begin
????? WordDoc.Close;
????? WordDoc.Disconnect;
????? WordDoc.Destroy;
????? WordDoc := nil;
??? end;
??? if Assigned(WordApp) then????????????? // ===== 关闭Word =====
??? begin
????? WordApp.Quit;
????? WordApp.Disconnect;
????? WordApp.Destroy;
????? WordApp := nil;
??? end;
? end;
end;
procedure getWordStr;
var WordApp: TWordApplication;
??? WordDoc: TWordDocument;
??? DocInx,oFileName,CfCversions,oReadOnly,AddToRctFiles,PswDocument,
??? PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat: OleVariant;
??? i,iRow,iCol:integer;
??? myCell:Cell;
??? myRow:Row;
begin
? memo1.Lines.Clear ;
??? // ===== 创建对象 =====
??? if not Assigned(WordApp) then?????????????????????????
??? begin
????? WordApp:= TWordApplication.Create(nil);
????? WordApp.Visible := false;
??? end;
??? if not Assigned(WordDoc) then
????? WordDoc:= TWordDocument.Create(nil);
? try
??? DocInx:=1;
??? oFileName := 'd:/test.doc';
??? oReadOnly:=true;
??? CfCversions := EmptyParam;
??? AddToRctFiles:= EmptyParam;
??? PswDocument:= EmptyParam;
??? PswTemplate:= EmptyParam;
??? oRevert:= EmptyParam;
??? WPswDocument:= EmptyParam;
??? WPswTemplate:= EmptyParam;
??? oFormat:= EmptyParam;????
??? // ===== 打开文件 =====????????????????????????
??? WordApp.Documents.open(oFileName,CfCversions,oReadOnly,AddToRctFiles,
?????? PswDocument,PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat);
??? // ===== 关联文件 =====
??? WordDoc.ConnectTo(WordApp.Documents.Item(DocInx));
??? //方法(1): 取整个文本的字符内容,包含表格
??? s := WordDoc.Range.text;?
??? //方法(2): 取 1 -- 4 位的字符 ,包含表格
??? myRange:=WordDoc.Range;
??? myRange.Start:=0;
??? myRange.End_ :=4;
? finally
??? if Assigned(WordDoc) then????????????? // ===== 关闭文件 =====
??? begin
????? WordDoc.Close;
????? WordDoc.Disconnect;
????? WordDoc.Destroy;
????? WordDoc := nil;
??? end;
??? if Assigned(WordApp) then????????????? // ===== 关闭Word =====
??? begin
????? WordApp.Quit;
????? WordApp.Disconnect;
????? WordApp.Destroy;
????? WordApp := nil;
??? end;
? end;
end;
相关文章推荐
- Delphi与Word(三) 取得Word文件的数据
- Delphi与Word(二) 取得Word 表格中的数据
- Delphi与Word(二)取得Word 表格中的数据
- 使用Delphi获取Word文件中的数据
- 取得Word文件的数据
- delphi中TRVOfficeConverter的使用。保存word文件出错,问题??
- 一些关于从数据库导出数据到word、excel、.txt文本文件的代码
- ★ 如何将网页数据输出为Excel或Word文件
- 操作Word模板文件.dot 结合具体数据 生成Word文档 .doc
- 很好用的数据库数据字典【可导出为word , excel文件】
- Delphi判断文件是否正在被使用(CreateFile也可以只是为了读取数据,而不是创建)
- delphi中转换office word文件为HTML文件,或者其它类型的文件的一些总结
- java实现把数据库数据导出成word文件实现文件下载功能
- 将网页数据输出为Excel或Word文件
- 如何将网页数据输出为Excel或Word文件
- Delphi中取得和设置硬盘上文件的创建日期、修改日期、访问日期、文件属性
- 配置文件操作(获取路径、及取得相应数据)
- 记录使用freemarker生成word的模板ftl文件以及word的遍历数据
- 如何将WEB页面中的数据保存为一个word文件
- Qt的Model/View Framework解析(数据是从真正的“肉(raw)”里取得,Model提供肉,所以读写文件、操作数据库、网络通讯等一系列与数据打交道的工作就在model中做了)