如何使用 Winforms 或 WPF 构建表单完成/文档合并应用程序?
我需要构建一个应用程序,它接受用户输入数据(例如姓名、地址、金额等),然后将其与预加载的文档模板(订单表格)合并,然后打印此合并的文档。我可以在这个项目中使用 Windows 窗体或 WPF。
关于如何最好地解决这个问题有什么建议吗?我有 Winforms 开发经验,但不知道如何将数据合并到文档中进行打印。
I need to build an application that accepts user input data (such as name, address, amount, etc.) and then merges it with a pre-loaded document template (order form) and then prints this merged document. I can use Windows Forms or WPF for this project.
Any suggestions on how best to approach this? I'm experienced with Winforms development, but don't have any idea how to handle merging the data to the document for printing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WPF 非常适合于此。
您可以从 WPF UI 元素(例如页面或用户控件)创建文档模板。设置模板就像在 VS 设计器中设置任何 UI 一样。确定您的数据将以什么形式存储(这将是您的 DataContext),然后绑定其公共属性。然后,您可以将合并的模板放入固定页面并将其添加到 XPS 文档中。您可以非常轻松地打印它或将其保存到磁盘。
简化算法:
我正在执行与此类似的操作,并且效果很好。只需转到我的个人资料并阅读我所有的问题即可。它们涵盖了整个过程的大部分难点。
WPF works great for this.
You can create document templates from WPF UI elements such as a Page or a UserControl. Set up the template like you'd set up any UI in the VS designer. Determine what shape your data will be stored in (this will be your DataContext), then bind against its public properties. Then you can drop your merged template into a FixedPage and add it to an XPS document. You can print that very easily or save it to disk.
Simplified algorithm:
I'm doing something similar to this and it works well. Just go to my profile and read all my questions. They cover most of the hard bits of the whole procedure.
您需要使用邮件合并。邮件合并是一种从数据库、电子表格或其他形式的结构化数据中获取数据并将其插入到信件、邮件标签和姓名标签等文档中的方法。从本文开始。
You need to use Mail Merge. A mail merge is a method of taking data from a database, spreadsheet, or other form of structured data, and inserting it into documents such as letters, mailing labels, and name tags. Start from this article.