View and Print Office Files in Windows Forms Application

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:

2016-11-07_160901

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.

2016-11-07_162015

Click Open button to open an office file from disk.

2016-11-07_163716

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.

Advertisements

Author: janewdaisy

.NET Program Beginner. Share methods about how to use C#/VB.NET to export data, operate Word, Excel, PDF and other useful skills.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s