procedure TMainFrm.Button1Click(Sender: TObject);
var
WordApplication1: TWordApplication;
Filename,AddToRecentFiles,Visible:olevariant;
begin
{联接WORD}
wordapplication1.connect;
wordapplication1.visible := true;
FileName := 'D:\workdir\文档\项目经理\Proj1.doc';
AddToRecentFiles:='';
Visible := false;
WordApplication1.Documents.Add (FileName,Visible,AddToRecentFiles,Visible);
end以上的代码,最后一句出现"类型不匹配的错误"?
var
WordApplication1: TWordApplication;
Filename,AddToRecentFiles,Visible:olevariant;
begin
{联接WORD}
wordapplication1.connect;
wordapplication1.visible := true;
FileName := 'D:\workdir\文档\项目经理\Proj1.doc';
AddToRecentFiles:='';
Visible := false;
WordApplication1.Documents.Add (FileName,Visible,AddToRecentFiles,Visible);
end以上的代码,最后一句出现"类型不匹配的错误"?
解决方案 »
- 包含数字变量的sql查询怎么写 SOS
- 请教webbrowser问题2
- 给我儿子起个好名字
- 有DeleteDir这个函数吗?
- 我说明了一个记录类型,然后我定义一个动态记录数组。怎样来分配,怎样来选择性的释放一个记录数组中的一个元素
- 求报表控件ReportMachine3.22版下载
- 为什么招Delphi程序员这么难呀?
- 请问在哪里可以找到devexpress的全套控件
- 提供中华人民共和国区域代码(全国所有城市)。
- 以下代码报错:"Canvas does not allow drawing!",是怎么回事?
- 求小数位四舍五入的函数!!!????????!!!!!!!!!!!
- delphi里有没有类似于VB的模糊字符串比较如: if str like "*元/盒" then
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;
expression.Add(Template, NewTemplate, DocumentType, Visible)expression 必需。该表达式返回一个 Documents 对象。Template Variant 类型,可选。新文档使用的模板名。如果忽略此参数,则使用 Normal 模板。NewTemplate Variant 类型,可选。如果为 True,则将文档作为模板打开。默认值是 False。DocumentType Variant 类型,可选。可以是下列 WdNewDocumentType 常量之一:wdNewBlankDocument、wdNewEmailMessage、wdNewFrameset 或 wdNewWebPage。默认值为 wdNewBlankDocument。Visible Variant 类型,可选。如果为 True,将在可见窗口打开文档;如果为 False,Microsoft Word 会打开此文档并将文档窗口的 Visible 属性设为 False。该属性的默认值为 True。
==================================================
取自word帮助文档,再好好研究研究把~~~
NewTemplate: 新建文档的类型,True表示为模板,False表示为文档
DocumentType: 文档类型,默认为空白文档
Visible: 窗口是否可见WordApp.Documents.Add(fileName, newTemplate, docType, isVisible)
WordApp,WordDoc,WordTable:OleVariant;
begin
WordApp:=CreateOleObject('Word.Application');
WordApp.Visible:=True;
WordDoc:=WordApp.Documents.Add;
WordApp.Selection.Range.Text :='HELLO';
WordDoc.saveas('c:\a.doc');
wordapp.quit;
end;