如何使用 Winforms 或 WPF 构建表单完成/文档合并应用程序?

发布于 2024-08-26 12:20:25 字数 169 浏览 3 评论 0原文

我需要构建一个应用程序,它接受用户输入数据(例如姓名、地址、金额等),然后将其与预加载的文档模板(订单表格)合并,然后打印此合并的文档。我可以在这个项目中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼泪也成诗 2024-09-02 12:20:26

WPF 非常适合于此。

您可以从 WPF UI 元素(例如页面或用户控件)创建文档模板。设置模板就像在 VS 设计器中设置任何 UI 一样。确定您的数据将以什么形式存储(这将是您的 DataContext),然后绑定其公共属性。然后,您可以将合并的模板放入固定页面并将其添加到 XPS 文档中。您可以非常轻松地打印它或将其保存到磁盘。

简化算法:

  • 创建数据输入表单。
  • 创建一个将保存表单中的数据的类型(将此类型称为 Foo)
  • 创建一个与 Foo 绑定的页面模板(当 Foo 实例是 DataContext 时)
  • 将表单绑定到 Foo 的实例
  • 让用户填写表单(并且从而 Foo 的实例)
  • 创建模板的实例(假设它是一个 Page)
  • Set Page.DataContext = fooInstance;
  • 将页面添加到固定页面,然后将其添加到固定文档
  • 将固定文档保存到 XPS 文档
  • 保存 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:

  • Create a data entry form.
  • Create a type that will hold data from the form (call this type Foo)
  • Create a Page template that binds against Foo (when a Foo instance is the DataContext)
  • Bind the form to an instance of Foo
  • Have the user fill in the form (and thereby the instance of Foo)
  • Create an instance of your template (assume its a Page)
  • Set Page.DataContext = fooInstance;
  • Add the Page to a FixedPage, then add this to a Fixed Document
  • Save the FixedDocument to an XPS document
  • Save the XPS document or send it to a PrintQueue

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.

半枫 2024-09-02 12:20:26

您需要使用邮件合并。邮件合并是一种从数据库、电子表格或其他形式的结构化数据中获取数据并将其插入到信件、邮件标签和姓名标签等文档中的方法。从本文开始。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文