none
Using OpenXml sdk 2 to find a keywords in Word document RRS feed

  • Question

  • I've been assigned a task to develop a program that uses the new OpenXml sdk 2.0.  The program searches a Word document for a particular keyword and returns the page numbers and line numbers that the keyword appears in the document.  Does the sdk provide such functions?  Sample codes are much appreciated.
    - Andy
    Wednesday, October 13, 2010 6:57 AM

Answers

  • Hi Andy,

    As such Open XML SDK is used to read/write into a document. It is not the replacement of the object model.

    Basically:

    The Open XML SDK is NOT a replacement for the Office Object Model; and provides no abstraction on top of the file formats
    You need to understand the structure of the file formats to leverage the SDK, it doesn't hide it from you
    The SDK does NOT provide functionality to convert Open XML Formats to and from other formats, like HTML or XPS
    The SDK does NOT guarantee document validity of Open XML Formats when developers use the SDK or if the developer chooses to manipulate the underlying xml directly
    The SDK does NOT provide application behaviors such as layout (ex. pagination of WordprocessingML documents) or recalculation functionality

    If the pagination is done by the Word application and you see the page number is present in the document, then you can use Open XML SDK to read the text. But it doesnt provide you a method to tell you that this text is available on this page. You may need to write code to check the page breaks and see where the text is. But the point is, pagination will be done by the Word engine only.

    Here are the some links for your reference:

    Creating a Simple Search and Replace Utility for Word 2007 Open XML Format Documents
    http://msdn.microsoft.com/en-us/library/cc974107(office.12).aspx

    How to: Search and Replace Text in a Document Part
    http://msdn.microsoft.com/en-us/library/bb508261.aspx

    Mastering Text in Open XML WordprocessingML Documents
    http://msdn.microsoft.com/en-us/library/ff686712.aspx

    HTH,
    Ankush

     


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Ankush Microsoft Online Community Support

    • Edited by Ankush_Bhatia Wednesday, October 13, 2010 10:50 AM Added the links
    • Proposed as answer by Ankush_Bhatia Wednesday, October 13, 2010 10:50 AM
    • Marked as answer by Bessie Zhao Tuesday, November 9, 2010 9:08 AM
    Wednesday, October 13, 2010 10:49 AM