[WPF] What control should I use to embed Excel in my app

théo Bainée 21 Reputation points
2020-08-18T09:58:14.647+00:00

Hello, thanks for reading,

I am upgrading an app from VB6 to VB.NET using WPF, in this old VB6 app there was "OLE" objects allowing the app to show Excel graph, sheets, and more.
In WPF i couldn't find any similar objects, so i found this tuto allowing me to indeed embed an Excel sheet in my app :
https://www.codeproject.com/Articles/15760/How-to-Integrate-Excel-in-a-Windows-Form-Applicati
And it works. It uses the WebBrowser object from WPF controls. But after using it for a bit it really seems like it is not made to open local documents and more for web browsing (as the name implies).

So here is my question : Is there a WFP object made for embeding Excel, word ect... (With for exemple methods for opening and closing properly the app) or should i go on with the WebBrowser Object?

Thanks again for reading,
Have a good day
Théo

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,690 questions
{count} votes

Accepted answer
  1. DaisyTian-1203 11,616 Reputation points
    2020-08-25T06:11:21.83+00:00

    You can use DocumentViewer to show the Excel. In order to show Excel content you could either convert the content into FlowDocument or XPS format.I will show my steps to open excel in WPF.(txt for code)
    Step 1 :Add Microsoft.Office.Interop.Excel in the Project Nuget.
    Step 2 :The code for MainWindow.xaml

    20133-capture2.png

    Step 3 :The code for MainWindow.xaml.cs
    20123-capture3.png

    Here is the result picture:
    20104-capture.png


1 additional answer

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2020-08-20T00:24:09.493+00:00

    There is spreadsheet gear. Depending on the size of your spreadsheets you might have to buy a license

    https://www.nuget.org/packages/SpreadsheetGear/

    0 comments No comments