请教打印问题:TOleContainer加载Word文件后,如何调用打印?

yuetianbao 2018-10-27 03:12:59
使用了如下方法,但不行:

--加载
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,没有值,直接异常了
...全文
190 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wdonghai 2018-11-12
  • 打赏
  • 举报
回复

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;
yuetianbao 2018-11-09
  • 打赏
  • 举报
回复
感谢1楼,能正常打印,但有个新问题:每次加载后都在窗口顶端显示了一个Word工具条,并且OleContainer进入了编辑模式,怎么去掉工具条和编辑模式?
wdonghai 2018-10-29
  • 打赏
  • 举报
回复

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;

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧