修改文档“模板”的最简单方法是并通过 WPF 打印?

发布于 2024-10-17 21:52:25 字数 567 浏览 4 评论 0原文

情况

我有一个 WPF 程序,我想使用一些数据打印多个文档。目前,这些文档以 Excel 电子表格和 Word 文档的形式存在。

我尝试过

以zip格式打开XPS文件(从Excel保存为XPS)并拉出页面(它仅包含一个页面)并将其放入带有网格的窗口中,只是为了测试。我的天啊!!找不到资源,到处都是红色的曲线。 XPS 中指定的字体在 odttf 文件中表示,WPF 似乎不喜欢该文件。将其重命名为 .ttf 似乎不起作用。布局显示正确,网格线等等,所以这是有希望的。

我真正不想做的是

手动将文件重新创建为流程文档、XPS 或其他 XAML 对象。 Excel 电子表格文档的布局非常复杂。 Word 文档还不错。

所以我实际上只需要知道:从我正在使用的两个输入(Word 文档、Excel 电子表格)中,我如何最好地将它们转换为可以轻松从 WPF 打印的格式。目前,我有一些代码片段,可以让我打开 Excel、打开电子表格、将数据放入指定的单元格、打印、发出关闭命令、检查程序是否卸载并在必要时终止它。但我不想再这样做了。它很混乱并且可能有错误,并且需要安装 Office Interop 程序集和其他东西。

The Situation

I have a WPF program that I want to print several documents from using some data. Currently these documents exist as an Excel Spreadsheet and a Word Document.

What I have tried

Opened XPS file (Saved as XPS from Excel) as a zip and pulled out the Page (it only consists of a single page) and slapped it into a Window with a grid, just for a test. OMG!! The resources that could not be found and red squiglies every where. Fonts that are specified in the XPS are represented in a odttf file which WPF does not seem to like. Renaming it to .ttf doesn't appear to work. The layout appeared correctly, grid lines and what not, so that is hopeful.

What I really would rather not have to do

Recreate the files as flow document, XPS, or other XAML objects by hand. The layout is pretty involved for the Excel Spreadsheet document. The Word doc is not so bad.

So really I just need to know: From the two inputs that I am using (Word Document, Excel Spreadsheet) how best would I get these into a format that I could easily print from WPF. Currently I have some code snippets that would allow me to open Excel, open the spreadsheet, put the data into the specified cells, print, issue a close command, check that the program unload and kill it if necessary. I don't want to do that anymore though. It is messy and can be buggy as well as requiring the Office Interop assemblies and other stuff to be installed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

夜还是长夜 2024-10-24 21:52:25

我找到了一篇文章 这里解释了一些我以前没有意识到的事情。

I found an article here which explains some things that I had previously not realized.

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