我怎么能以统一的方式打印从.NET Office文档? [英] How can I print Office documents from .NET in a uniform manner?

查看:222
本文介绍了我怎么能以统一的方式打印从.NET Office文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用微软的互操作的对象,我可以通过编程打印Word或Excel文档。

有没有更简单的,统一以编程方式打印所有类型的文档(txt文件,名为.doc,.xls的,.PDF等。)?

解决方案

Microsoft使用DDE默认

从办公用品打印。 转到工具/文件夹选项/文件类型,然后查找.XLS例如,点击高级。 你将看到的动作,其中之一是打印的列表。 这里面是Excel用于打印,然后关闭您的文档,并且这些命令中的一个存在于Office套件每个产品的DDE命令。 不幸的是DDE使用SendMessage函数的API,但在这里一个库,包装这些功能为你:

HTTP://ndde.$c$cplex.com/发布/ ProjectReleases.aspx?ReleaseId = 4828

它不再被更新,但还是应该做你需要,如果你只需要打印文件的通用方法。

如果您使用的是互操作,而且已经有theinstance的应用程序打开,然后只需调用相应的打印输出功能。例如用于Word,它是:

 对象nullobj = Missing.Value;
doc.PrintOut(REF nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj,裁判nullobj);
 

显然,这两种互操作和DDE是很不理想的解决方案,但办公室仍是基于相同的Win32的核心,它是在90年代。

一旦他们重新code它管理code,我们将有一个不错的组通用的接口,用于创建,打印和查看办公文件!

干杯,  杰森

Using Microsoft interOp objects, I can programmatically print a Word or Excel document.

Is there any simpler and uniform way to programmatically print all types of documents (.txt, .doc, .xls, .pdf etc.)?

解决方案

Microsoft uses DDE by default to print from office products. Go to Tools/Folder Options/File Types, then lookup .XLS for example and click 'Advanced'. You will see a list of actions, one of which is 'Print'. Inside this is the DDE command that Excel uses to print then close your document, and one of these commands exists for each product in the Office suite. Unfortunately DDE uses the SendMessage APIs, but there was a library here that wraps those functions up for you:

http://ndde.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=4828

It's no longer being updates but should still do what you require if you only want a generic way of printing the documents.

If you're using Interop and already have theinstance of the application open, then just call the appropriate PrintOut function. e.g. for Word, it's:

object nullobj = Missing.Value;
doc.PrintOut(ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);

Clearly, both interop and DDE are far from ideal solutions, but Office is still based upon the same Win32 core that it was in the 90's.

Once they recode it in managed code we will have a nice common set of interfaces for creating, printing and viewing office documents!

Cheers, Jason

这篇关于我怎么能以统一的方式打印从.NET Office文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆