Nowadays, we are most likely to receive or create electronic reports in office file formats, such as .docx, .xlsx, .pptx and .pdf. It’s quite often that programmers are requested to build a .NET application that can view and print office files, so that their colleagues or customers can access the documents too.
This article presents how to view and print Word, Excel, PowerPoint and PDF Documents in a Windows Forms Application via a powerful component Spire.OfficeViewer. To create your own Office document viewer, you need firstly integrate Spire.OfficeViewer controls to Toolbox in your Visual Studio. Here is how to.
- Download Spire.OfficeViewer and install it on system
- Right-click on Toolbox panel, click ‘Add Tab’ to add a new tab
- Right-click the new tab and select ‘Choose Items…’
- Choose ‘.NET Framework Components’ tab
- Click ‘Browse…’ button
- Choose ‘Spire.OfficeViewer.Forms.dll’ in open file dialog
- Click ‘OK’, then the controls will be successfully added to Toolbox
Drag ‘ OfficeViewer’ control to form1 and it looks like:
Run the program, you’re able to get an Office viewer like below screenshot. Look at the toolbar, it provides many more functions other than Open and Print.
Click Open button to open an office file from disk.
It is extremely easy to build an Offer viewer using this control, right? If you want to custom the toolbar with specified functions, just remove ‘OfficeViewer’ control and drag ‘DocumentViewer’ control to the form1, and then create your own toolbar using the Common Controls provided by VS, but you need to figure out the code inside the toolbar.