ImageGear for .NET
Adding Office Support
Send Feedback
ImageGear for .NET User Guide > Getting Started > ImageGear for .NET Visual Studio 2010 Tutorials > ImageGear for .NET VB.NET Tutorial > Adding Office Support

Glossary Item Box

Once the base of the tutorial application is completed, you can extend it with Office support using the following steps:

  1. First, you need to add a reference to the ImageGear for .NET Office Assembly.
    1. In the Solution Explorer, right-click on Project, and choose Add Reference.
    2. Choose the Browse tab, navigate to "ImageGear for .NET v21\Bin" directory, select ImageGear21.Formats.Office.dll, and click OK.

    You should now have the ImageGear21.Formats.Office assembly listed under References in the Solution Explorer.

  2. Next, add the Office using statement. Open the code for Form1.vb by right-clicking on the form and clicking View Code. At the top of the code add the following statement:
    VB.NET Example Copy Code
    Imports ImageGear.Formats.Office;
  3. Add the following statements in Form1_Load method right after the ImGearCommonFormats.Initialize() call:
    VB.NET Example Copy Code
    ' Add support for Word files
    ImGearFileFormats.Filters.Add(ImGearOffice.CreateWordFormat())
  4. Under the File menu, add the Load Document menu item. Double-click it to create a handler.
  5. Copy the code from the Load Page menu handler for the Load Document menu handler.
  6. Add the following fields to Form1 class:
    VB.NET Example Copy Code
    Private igDocument As ImGearDocument
    Private currPageNumber As Integer = -1
  7. 7. Add the following method to Form1 class:
    VB.NET Example Copy Code
    Private Sub UpdateMainView()
    ImGearPageView1.Page = igPage
    ImGearPageView1.Update()
    End Sub
  8. In LoadDocumentToolStripMenuItem_Click find the following code:
    VB.NET Example Copy Code
    igPage = ImGearFileFormats.LoadPage(stream, 0)

    and replace it with:

    VB.NET Example Copy Code
    igDocument = ImGearFileFormats.LoadDocument(stream, 0, -1)
    currPageNumber = 0
    igPage = igDocument.Pages(currPageNumber)
    igPageDisplay = New ImGearPageDisplay()
    ImGearPageView1.Display = igPageDisplay

    Also replace the following code:

    VB.NET Example Copy Code
    If Not igPage Is Nothing AndAlso Not igPage.DIB Is Nothing Then
    ' create a new page display
    igPageDisplay = New ImGearPageDisplay(igPage)
    ' associate the page display with the page view
    ImGearPageView1.Display = igPageDisplay
    ' cause the page view to repaint
    ImGearPageView1.Invalidate()
    End If

    with:

    VB.NET Example Copy Code
    If Not igPage Is Nothing Then
    UpdateMainView()
    End If
  9. To enable navigation between Office document pages do the following:
    1. Under the View menu, add ‘First Page’, ‘Previous Page’, ‘Next Page’, ‘Last Page’ menu items. Double-click them to create handlers.
    2. b. In FirstPageToolStripMenuItem_Click add the following code:
      VB.NET Example Copy Code
      currPageNumber = 0
      igPage = igDocument.Pages(currPageNumber)
      UpdateMainView()
    3. In PreviousPageToolStripMenuItem_Click add the following code:
      VB.NET Example Copy Code
      If (currPageNumber - 1 >= 0) Then
      currPageNumber -= 1
      igPage = igDocument.Pages(currPageNumber)
      UpdateMainView()
      End If
    4. In nextPageToolStripMenuItem_Click add the following code:
      VB.NET Example Copy Code
      If (currPageNumber + 1 < igDocument.Pages.Count) Then
      currPageNumber += 1
      igPage = igDocument.Pages(currPageNumber)
      UpdateMainView()
      End If
    5. In lastPageToolStripMenuItem_Click add the following code:
      VB.NET Example Copy Code
      currPageNumber = igDocument.Pages.Count - 1
      igPage = igDocument.Pages(currPageNumber)
      UpdateMainView()

Now you are ready to compile and run the finished application working with Office documents.

©2013. Accusoft Corporation. All Rights Reserved.