如何在delphi中读取word文档!!!!
比如我指定路径,文件名,我在按某个按钮是实现这篇文档的读取!!!!!

解决方案 »

  1.   

    打开word文件。
        var
        MSWord: Variant;
        str:string; 
        begin
            MSWord:= CreateOLEObject('Word.Application');//
            MSWord.Documents.Open('d:\Program Files\Common Files\Sfa\'+str, True);//
            MSWord.Visible:=1;//
    wmessage('');
        end;(代理服务器有问题,不能发长的留言,请原谅) 
    --------------------------------------
    看!
    那支正飞向太阳的蛾子.....
    就是我!
    --------------------------------------
      

  2.   

    try
        MSExcel:=CreateOLEObject('Word.Application');
        FileName:= ExtractFilePath(Application.ExeName) + '年度统计.doc';
        MSExcel.WorkBooks.Open(FileName);
        MSExcel.Visible:=False;
        //进程条
        Gauge1.Visible := True;
          Gauge1.Hide;
      Except
        Gauge1.Hide;
        Exit;
      end;  MSExcel.Visible:=True;
    end;
      

  3.   


    按钮事件中加入var
        V: OleVariant;begin
    if OpenDialog1.Execute then
        begin
            try
                Screen.Cursor := crHourGlass;
                V := CreateOleObject('word.Application');
                V.Visible := true;
                V.Caption := 'FAQ Document';
                V.Documents.Add(EmptyParam, false,0,0);
                V.Documents.Open(OpenDialog1.FileName);
                Screen.Cursor := crDefault;
            except
                Screen.Cursor := crDefault;
                ShowMessage('Not found World,Microsoft world is Installed?');
                exit;
            end;
        end
        else
        begin
            if Application.MessageBox('Are you want to create a new document?',Pchar(App_title),MB_YESNO)=IDNO then
                exit;
            try
                Screen.Cursor := crHourGlass;
                V := CreateOleObject('Word.Application');
                V.Visible := true;
                V.Caption := 'FAQ Document';
                V.Documents.Add(EmptyParam, false,0,0);
                V.Documents.add;
                Screen.Cursor := crDefault;
            except
                Screen.Cursor := crDefault;
                ShowMessage('Not found World,Microsoft world is Installed?');
                exit;
            end;
        end;
    end;