来自 C# 的邮件合并或类似合并的功能
我需要打印几千张带有一些文本字段(名称、位置等)以及条形码图像的贴纸。
每位员工都会获得两张独特的贴纸,每张贴纸有 4 张,因此每张贴纸有 2 名员工。
我已经拥有将条形码生成为 Image
的所有代码,并且员工详细信息存储在对象的 List
中。
如果可能的话,我想避免直接使用 MSWord,因为我的开发环境与目标环境有很大不同,并且我过去曾因这种差异而遇到过问题。 (Win7-64、MSOffice2010 与 WinXP-32、MSOffice2003)。
实现这一目标的最佳方法是什么?
如果我将文档保存为 XML 格式,并用唯一的标记替换邮件合并字段,我可以用我的实际值替换这些标记(我什至可以用 base-64 编码的图像字节替换二进制图像数据),那么这可以工作,但很笨重。对于初学者来说,我必须保存 XML 文件,然后以某种方式将其打印为对用户透明的(不希望 Word 显示)。另外,XML 模板只有一页,但我可能有几十页要打印。我可以将每一页单独发送到打印机,但这并不理想。
还有其他建议吗?
I need to print a few thousand stickers with a few text fields (name, position, etc) as well as a barcode image.
Each staff member gets two unique stickers, and the sticker paper has 4 per sheet so that's 2 staff per sheet.
I already have all the code to generate the barcode as an Image
, and the staff details are stored in a List
of object.
If possible, I'd like to avoid using MSWord directly since my development environment is quite different from the target environment and I've had issues in the past from the disparity. (Win7-64, MSOffice2010 vs. WinXP-32, MSOffice2003).
What's the best way to accomplish this?
If I save the document as an XML format and replace the mail merge fields with unique tokens which I can replace with my actual values (and I can even replace the binary image data with base-64 encoded image bytes) then that works but it's clunky. For starters, I'd have to save the XML file and then somehow print it transparent to the user (don't want Word showing up). Also, the XML template is 1 page, but I might have several dozen to print. I can send each page to the printer individually but that's not exactly ideal.
Any other suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会使用 DevXpress XtraReports,因为我过去在类似场景中使用过它,并取得了很好的效果。如果您更喜欢 Crystal 或 Telerik 等其他引擎,则同样简单,只需拖动页面详细信息部分中的某些字段并将对象列表指定为数据源即可。 DevXpress 还有一个带有内置邮件合并功能的 RichTextBox。最后,如果您决定使用单词,请不要忘记您可以自动化并使用它,同时保持它不可见,这样用户就不会看到它。
I would use DevXpress XtraReports as I have used it in the past in similar scenarios with great results. If you prefer other engines like Crystal or Telerik is the same, as easy as dragging some fields in the page details section and assign your object list as datasource. DevXpress has also a RichTextBox with builtin mailmerge feature. at last if you decide for word do not forget that you can automate and use it while keeping it invisible so users wont see it.