使用Delphi获取Word文件中的数据
2008-06-11 00:00
405 查看
//delphi7、Office2003下编译通过
//参考http://dev.csdn.net/article/18/18811.shtm,并做了修改
//取得Word文件的数据 需要uses OleCtnrs;
procedure TForm1.getWordStr;
var
WordA : TWordApplication;
WordDoc: TWordDocument;
DocInx,oFileName,CfCversio ,oReadOnly,AddToRctFiles, wDocument,
wTemplate,oRevert,WwDocument,WwTemplate,oFormat,olevar: OleVariant;
i,iRow,iCol:integer;
myCell:Cell;
myRow:Row;
s:string;
myRange: Range;
begin
// ===== 创建对象 =====
if not Assigned(WordA ) then
begin
WordA := TWordApplication.Create(nil);
WordA .Visible := false;
end;
if not Assigned(WordDoc) then
WordDoc:= TWordDocument.Create(nil);
try
DocInx:=1;
oFileName := 'c:/1.doc';
oReadOnly:=true;
CfCversio := EmptyParam;
AddToRctFiles:= EmptyParam;
wDocument:= EmptyParam;
wTemplate:= EmptyParam;
oRevert:= EmptyParam;
WwDocument:= EmptyParam;
WwTemplate:= EmptyParam;
oFormat:= EmptyParam ;
// ===== 打开文件 =====
WordA.Documents.Open(oFileName,CfCversio ,oReadOnly,AddToRctFiles,wDocument, wTemplate,oRevert,WwDocument,WwTemplate,oFormat,olevar,olevar,olevar,olevar,olevar);
// ===== 关联文件 =====
// WordDoc.ConnectTo(WordA.Documents.Item(DocInx));
WordA.Selection.WholeStory;
WordA.Selection.Copy;
Richedit1.PasteFromClipboard;
s:=Richedit1.Text ;
//s:= WordA.Selection.Text;
Showmessage(s);
finally
if Assigned(WordDoc) then // ===== 关闭文件 =====
begin
WordDoc.Close;
WordDoc.Disconnect;
WordDoc.Destroy;
WordDoc := nil;
end;
if Assigned(WordA ) then // ===== 关闭Word =====
begin
WordA .Quit;
WordA .Disconnect;
WordA .Destroy;
WordA := nil;
end;
end;
end;
//参考http://dev.csdn.net/article/18/18811.shtm,并做了修改
//取得Word文件的数据 需要uses OleCtnrs;
procedure TForm1.getWordStr;
var
WordA : TWordApplication;
WordDoc: TWordDocument;
DocInx,oFileName,CfCversio ,oReadOnly,AddToRctFiles, wDocument,
wTemplate,oRevert,WwDocument,WwTemplate,oFormat,olevar: OleVariant;
i,iRow,iCol:integer;
myCell:Cell;
myRow:Row;
s:string;
myRange: Range;
begin
// ===== 创建对象 =====
if not Assigned(WordA ) then
begin
WordA := TWordApplication.Create(nil);
WordA .Visible := false;
end;
if not Assigned(WordDoc) then
WordDoc:= TWordDocument.Create(nil);
try
DocInx:=1;
oFileName := 'c:/1.doc';
oReadOnly:=true;
CfCversio := EmptyParam;
AddToRctFiles:= EmptyParam;
wDocument:= EmptyParam;
wTemplate:= EmptyParam;
oRevert:= EmptyParam;
WwDocument:= EmptyParam;
WwTemplate:= EmptyParam;
oFormat:= EmptyParam ;
// ===== 打开文件 =====
WordA.Documents.Open(oFileName,CfCversio ,oReadOnly,AddToRctFiles,wDocument, wTemplate,oRevert,WwDocument,WwTemplate,oFormat,olevar,olevar,olevar,olevar,olevar);
// ===== 关联文件 =====
// WordDoc.ConnectTo(WordA.Documents.Item(DocInx));
WordA.Selection.WholeStory;
WordA.Selection.Copy;
Richedit1.PasteFromClipboard;
s:=Richedit1.Text ;
//s:= WordA.Selection.Text;
Showmessage(s);
finally
if Assigned(WordDoc) then // ===== 关闭文件 =====
begin
WordDoc.Close;
WordDoc.Disconnect;
WordDoc.Destroy;
WordDoc := nil;
end;
if Assigned(WordA ) then // ===== 关闭Word =====
begin
WordA .Quit;
WordA .Disconnect;
WordA .Destroy;
WordA := nil;
end;
end;
end;
相关文章推荐
- 使用VBA从海量Excel文件中模糊获取数据并生成新表(附实例) - (三) VBA模糊查找数据
- WebService,ASMX文件使用XML格式数据传递参数、验证与获取XML格式返回值的一种方式
- 使用oledb获取Excel文件第一个工作表数据
- JS使用ajax从xml文件动态获取数据显示的方法
- ajax--将获取到的文件内的数据转化成json格式并使用---输入提示
- 使用VBA从海量Excel文件中模糊获取数据并生成新表(附实例) - (四) 结合病人病例,批量汇总实例
- delphi中TRVOfficeConverter的使用。保存word文件出错,问题??
- Delphi判断文件是否正在被使用(CreateFile也可以只是为了读取数据,而不是创建)
- 使用oledb获取Excel文件第一个工作表数据
- 在DELPHI中使用ADO直接访问Excel数据文件(收藏)
- 使用GridView来获取xml文件数据
- 使用NSURLSession获取网络数据和下载文件
- 使用JDBC获取数据库数据,并生成json格式文件(省市区三级联动)
- Json文件 使用rapidjson获取Json数据
- 使用python获取webservice数据并输出到文件
- Python数据获取-文件、word、Excel、数据库
- 使用GridView来获取xml文件数据
- Delphi与Word(三)取得Word文件的数据
- Delphi与Word(三) 取得Word文件的数据
- 使用oledb获取Excel文件第一个工作表数据