Search code examples
wpfexcelms-wordflowdocumentxps

Simplest way to modify a document "template" and print via WPF?


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.


Solution

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