使用了如下方法,但不行:--加载
  OleContainer1.DestroyObject;
  OleContainer1.CreateObjectFromFile(‘D:\A.doc’, False);--打印预览
OleContainer1.OleObject.Application.ActiveDocument.PrintPreview;--报错:
Project Project1.exe raised exception class EIntfCastError with message 'Interface not supported'. Process stopped. Use Step or Run to continue.--调试时查看OleObject,没有值,直接异常了

解决方案 »

  1.   


    procedure TForm1.Button1Click(Sender: TObject);
    begin
      OleContainer1.DestroyObject;
      OleContainer1.CreateObjectFromFile('D:\A.doc', false);
      OleContainer1.DoVerb(ovShow);
      OleContainer1.Run;
      OleContainer1.OleObject.Application.ActiveDocument.PrintOut;
    end;
      

  2.   

    感谢1楼,能正常打印,但有个新问题:每次加载后都在窗口顶端显示了一个Word工具条,并且OleContainer进入了编辑模式,怎么去掉工具条和编辑模式?
      

  3.   


    procedure TForm1.Button1Click(Sender: TObject);
    begin
      OleContainer1.DestroyObject;
      OleContainer1.CreateObjectFromFile('D:\A.doc', false);
      OleContainer1.DoVerb(ovShow);
      OleContainer1.Run;
      OleContainer1.OleObject.Application.ActiveDocument.Protect(2);
      OleContainer1.OleObject.application.CommandBars['Standard'].Visible:=false;
      OleContainer1.OleObject.application.CommandBars['Formatting'].Visible:=false;
      OleContainer1.OleObject.application.CommandBars['Reviewing'].Visible:=false;
      OleContainer1.OleObject.Application.ActiveDocument.PrintOut;
    end;