开发者

Load Word Excel into WPF

开发者 https://www.devze.com 2022-12-13 21:17 出处:网络
I would like to load a Word or Excel document into a window of a WPF application so that users can view or edit the document within the application. Is there any way to achie开发者_运维知识库ve that?T

I would like to load a Word or Excel document into a window of a WPF application so that users can view or edit the document within the application. Is there any way to achie开发者_运维知识库ve that?


To simplify things what you can do is print the document to XPS which comes with office or Windows (can't remember which) as a printer of the name "Microsoft XPS Document Writer".

Once you have the document, this can be displayed using a view of:

<DocumentViewer Name="docContent"/>

And simply set the document.

System.Windows.Xps.Packaging.XpsDocument doc
    = new System.Windows.Xps.Packaging.XpsDocument(
    "myDoc.xps", System.IO.FileAccess.Read);
docContent.Document = doc.GetFixedDocumentSequence();

For this to work you only need to reference "ReachFramework".

As for edit support you can use the XPS manipulation strategies provided by the XPS specification.


You add web browser control from toolbox and then load the Word document in it. You can even open any document that browser support e.g. Word, Excel, PDF, SWF etc...

Example Load Word

webBrowser1.Navigate("C:\\word.doc");

Example Load Excel

webBrowser1.Navigate("C:\\excel.xls");


SpreadsheetGear for .NET comes with a .NET Windows Forms control which can easily be used in WPF applications to view and edit Excel documents.

You can download a free trial here if you want to try it yourself.

Disclaimer: I own SpreadsheetGear LLC

0

精彩评论

暂无评论...
验证码 换一张
取 消