C#在软件中调用Word打印程序的方法

Spire.Doc是一个国产的Office API库,利用这个库只需要三行代码即可实现打印调用。

准备工作

首先,下载Spire.Doc功能类库 ,点击这里下载 ;

然后,在后端代码引入命名空间。

using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;

打印实现

 Document document = new Document();            document.LoadFromFile(@"............DataTemplate.docx");            //打印设置            PrintDialog dialog = new PrintDialog();            dialog.AllowCurrentPage = true;            dialog.AllowSomePages = true;            dialog.UseEXDialog = true;            try            {                document.PrintDialog = dialog;                dialog.Document = document.PrintDocument;                dialog.Document.Print();            }            catch (Exception ex)            {                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);            }

为什么不管什么操作都要实例化document并加载呢为既然是接口,内容必然要通过符合spire的标准去与接口对接的呀,因此不要嫌弃麻烦啦。

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年1月13日
下一篇 2022年1月13日

相关推荐

发表回复

登录后才能评论