Microsoft Word 互操作自动化 FilePrintSetup 错误
我收到“打印机出现错误”。当在带有 Word 2010 的 Windows 7 上使用自动化将打印作业发送到打印机时。相同的代码在带有 Word 2007 的 Windows XP 盒子上运行良好。我不确定是 Windows 7 还是 Word 2010 导致了该错误。
感谢任何帮助,
using Microsoft.Office.Interop.Word;
.....
object oWordbasic = wordDoc.Application.WordBasic;
object[] argValues = new object[] { value, 1 }; //first arg is a printer name
String[] argNames = new String[] { "Printer", "DoNotSetAsSysDefault", };
//Error Here
oWordbasic.GetType().InvokeMember("FilePrintSetup", System.Reflection.BindingFlags.InvokeMethod, null, oWordbasic, argValues, null, null, argNames);
我收到以下错误
System.Reflection.TargetInvocationException was caught
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at PBP.ABC.Framework.Wrappers.Microsoft.Word.WordDocument.set_ActivePrinterName(String value) in
InnerException: System.Runtime.InteropServices.COMException
HelpLink=wdmain11.chm#24696
Message=There is a printer error.
Source=Microsoft Word
ErrorCode=-2146827168
InnerException:
如果我省略了打印机参数,则调用可以工作,但不会打印到指定的打印机。它将打印到默认打印机。
谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能对你有用 - 这是我在 Word 中必须执行的操作,才能在不更改活动打印机的情况下进行打印,我收到错误,发现有时 Word 只喜欢打印机名称,有时还想要端口。
...要获取打印机名称和端口,请使用 InstalledPrinter,如下所示
}
...然后在实例化 Word 后,我有类似这样的内容来设置打印机:
Might work for you - this is what I had to do in Word to print without changing the active printer, I was getting an error and found that sometimes Word liked just the printer name and other times wanted to also have the port.
... to get the printer names and ports use InstalledPrinter as below
}
...then after instantiating Word I have something like this to set the printer:
没有找到解决问题的方法。放入 if 条件以不同方式处理 Word 2010 并使用非托管代码进行打印。 链接 概述了如何执行此操作
Did not find a way to fix the issue. Put in a if condition to handle Word 2010 differently and use unmanaged code to print. Link outlines how to do this