如何在c#中打开和打印word文件 [英] how to open and print word file in c#

查看:136
本文介绍了如何在c#中打开和打印word文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


i试图在richtextbox上打开word文件,但我想要

所以我想问一下如何打开word文件并打印出来

请帮帮我

hi i tried to open word file on richtextbox but i faild
so i want to ask for how to open word file and print it by anyway
please help me

推荐答案

有几种方法可以做到这一点。例如:

- 您可以使用互操作 [ ^ ]

- 打开文件

- 打印它

- 关闭

- 您可以创建一个宏,可以通过命令行参数(/ m)运行,请参阅: http://support.microsoft.com/kb/210565 [ ^ ]



一个示例文章: Word 2007自动化 [ ^ ]
There are several ways of doing this. For example:
- you can use interop [^]to
- open the document
- print it
- close
- you can create a macro, which can be run by command line arguments (/m), see: http://support.microsoft.com/kb/210565[^]

One example article: Word 2007 Automation[^]


除非它是RTF文档,否则你不太可能在 RichTextBox 控件中打开它。您最好遵循Mika的建议打开文档并通过自动化直接打印。



或者你可以使用shell的print命令直接在打印模式下启动文档。但这可能不太灵活,可能涉及用户交互(因为会弹出一个对话框)。
Unless it's an RTF document, it's unlikely that you will be able to open it in a RichTextBox control. You'd be better off following Mika's suggestions to open the document and print it directly via automation.

Alternatively you can use the shell's "print" command to directly launch the document in print-mode. But that may be less flexible and could involve user interaction (since a dialog would pop up).


你试过的是代码吗?



检查出来......



------------------------- --------



Did you try is code?

Check it out...

---------------------------------

using OpenOfficeLib.Printer; 
using OpenOfficeLib.Connection; 
using OpenOfficeLib.Document; 
using unoidl.com.sun.star.lang; 
using unoidl.com.sun.star.uno; 
using unoidl.com.sun.star.frame; 
namespace Onr1 
{ 
class Program 
{ 
static void Main(string[] args) 
{ 
XComponentContext xComponentContext = Connector.GetComponentContext(); 
XMultiServiceFactory xMultiServiceFactory = Connector.GetMultiServiceFactory(xComponentContext); 
XDesktop xDesktop = Connector.GetDesktop(xMultiServiceFactory); 
string myFileToPrint = Component.PathConverter(@"c:\xml\annegod.rtf"); 
XComponent xComponent = Component.LoadDocument( 
(XComponentLoader)xDesktop, myFileToPrint, "_blank"); 
Printer.Print(xComponent); 
} 
} 
}





------------ ------------



我希望这能给你一些想法..



------------------------

I hope this gave you some idea..


这篇关于如何在c#中打开和打印word文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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