从表单打印Word文档 [英] Printing Word document from a form

查看:200
本文介绍了从表单打印Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用VB.Net编写的VSTO Word插件,它启动一个Windows窗体(来自自定义功能区按钮)。



我有一个该表单上的按钮执行以下操作:

I have a VSTO Word addin written in VB.Net, that launches a Windows form (from a custom ribbon button).

I have a button on that form that does the following:


  • 使用一些文本创建一个新的Word文档。
  • 打印新创建的文档(命令是:wordDoc.PrintOut(Copies:= numCopies,Background:= True,Append:= False))
  • 关闭文档(wordDoc.Close(SaveChanges:= Word.WdSaveOptions.wdDoNotSaveChanges))\
  • 但是没有关闭表格。我有另一个按钮来关闭表单。

我的问题是在关闭表单之前文档不会在打印机上打印。我已经尝试将background参数设置为true,但这没有帮助。是否可以在不关闭表格的情况下打印文件?
b


问候委员b
维克拉姆

My problem is the document doesn't print at the printer until I close the form. I have tried setting background parameter to true, but that hasn't helped. Is it possible to print the document without closing the form?

Regards
Vikram

推荐答案

您好,我不确定您的问题是什么,但您可以使用Word组件
打印Word
文档关闭表单。

Private Sub btn_Print_Click(sender As Object, e As EventArgs)
	' Instantiated an object of Spire.Doc.Document
	Dim doc As New Document()
	'Load word document
	doc.LoadFromFile("sample.doc")
	' Instantiated System.Windows.Forms.PrintDialog object.
	Dim dialog As New PrintDialog()
	dialog.AllowPrintToFile = True
	dialog.AllowCurrentPage = True
	dialog.AllowSomePages = True
	dialog.UseEXDialog = True
	doc.PrintDialog = dialog
	Dim printDoc As PrintDocument = doc.PrintDocument
	'Interaction printing 
	If dialog.ShowDialog() = DialogResult.OK Then
		printDoc.Print()
	End If
End Sub


这篇关于从表单打印Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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