关于word 打印的问题

hanzhaoever 2011-03-29 05:05:10
引用Microsoft.Office.Interop.Word后
然后调用PrintOut 方法
运行后 跟断点 发现到PrintOut 是长时间没有反映
应该不是打印机的问题 打印测试页是正常的
上一段代码

object background = false;
object filename = "C:\\tem.doc";

wDoc.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

wDoc.PrintOut(ref background, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing);

...全文
109 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
蓝色风影 2011-03-30
  • 打赏
  • 举报
回复
用Microsoft.Office.Interop.Word后要注意版本问题.我之前做2003没有问题,2007有问题
hanzhaoever 2011-03-30
  • 打赏
  • 举报
回复
找到 编号无效 的错误原因 我参数有问题
刚才在csdn上搜了一下 C#word 看来我的问题得到答案的希望渺茫
hanzhaoever 2011-03-30
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lw402365015 的回复:]
先定个点
[/Quote]

wDoc.PrintOut(ref background, ref missing, ref filename, ref missing, ref missing, ref missing, ref missing, ref
行 79: missing, ref missing, ref a1, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
行 80:

就算是打印这报的错误 !
lw402365015 2011-03-30
  • 打赏
  • 举报
回复
先定个点
hanzhaoever 2011-03-30
  • 打赏
  • 举报
回复
System.Runtime.InteropServices.COMException: 编号无效

现在报这个错误!!
hanzhaoever 2011-03-30
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wxr0323 的回复:]
换个打印机试下。。

必须安装office的.net开发包。
在工程的reference中添加com组件:Microsoft Word 11.0 Object Library
[/Quote]

按装.net的开发包 这个是什么 我在网上搜了一下 也,没有这东西的下载
是不是不安装就没有 com组件?
hanzhaoever 2011-03-30
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 rpwlp888 的回复:]
用Microsoft.Office.Interop.Word后要注意版本问题.我之前做2003没有问题,2007有问题
[/Quote]

我现在用的是2003 别的都没问题 就是在打印的时候长时间没有响应
也不报错
子夜__ 2011-03-29
  • 打赏
  • 举报
回复
换个打印机试下。。

必须安装office的.net开发包。
在工程的reference中添加com组件:Microsoft Word 11.0 Object Library
打印的代码如下:
Microsoft.Office.Interop.Word.Application app = null;
Microsoft.Office.Interop.Word.Document doc = null;
object missing = System.Reflection.Missing.Value;
object templateFile = Application.StartupPath + @"\表单模版.doc";
try
{
app = new Microsoft.Office.Interop.Word.ApplicationClass();
doc = app.Documents.Add(ref templateFile, ref missing, ref missing, ref missing);
try
{
foreach (Microsoft.Office.Interop.Word.Bookmark bm in doc.Bookmarks)
{
bm.Select();
string item = bm.Name;
if (item.Equals("in_time"))
{
bm.Range.Text = table.inTime == null ? "" : table.inTime.ToString();
}
else if (item.Equals("car_id"))
{
bm.Range.Text = table.carID == null ? "" : table.carID.ToString();
}
}
}
catch
{
}
//打印
doc.PrintOut(ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, this.Text);
}
//销毁word进程
finally
{
object saveChange = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
if (doc != null)
doc.Close(ref saveChange, ref missing, ref missing);
if (app != null)
app.Quit(ref missing, ref missing, ref missing);
}

hanzhaoever 2011-03-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 haa17 的回复:]
http://msdn.microsoft.com/library/en-us/vbawd10/html/womthPrintOut.asp
参考下这个。
[/Quote]
Background Optional Variant. Set to True to have the macro continue while Microsoft Word prints the document.

不太了解这句话的意思 和宏有什么关系


haa17 2011-03-29
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/library/en-us/vbawd10/html/womthPrintOut.asp

参考下这个。

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧