I’m a Dutch developer, evaluating apose.Word for possible usage in our next project.
What I need to know is how I can read pieces of text out of a word-document?
Do I need to do this with form-fields? Are there other possibilities?
I just want to make some Word template document with form-fields, or sections or whatever
sor of possible ‘text blocks’.
I just need to be able to read out those text blocks (like form fields).
Is this possible? And if so, how? Is need some example code for this. I couldn’t find it in the demo’s.
So far, I tried this code below, but I get an error message 'System.Exception: Cannot find a document field that wraps this form field.'
I’ve just created some test document in Word2002 with some (text)formfields in it (and 1 checkbox-formfield).
Dim word As word = New word
Dim doc As Document = word.Open(MapPath(".") + “…\Documents\testform.doc”) 'word.Open(“d:\docs\testform.doc”)
Dim s As String = doc.Range.Text() ’ goes fine
Dim i As Integer = doc.Range.FormFields.Count ’ error on this line
Dim s3 As String = doc.Range.FormFields(“Text1”).Result ’ also error on this line
1. If you only need to retrieve small pieces of text and form fields are suitable for your purpose, then yes, you can use form fields and retrieve data from them using Aspose.Word. Your code is correct. The exception is thrown probably because of some undocumented feature or combination of data in the document that Aspose.Word does not yet support. Please email the document to email@example.com for examination.
2. If you need to search and retrieve bigger blocks of text (that cannot fit into form fields) you can use Range.Text to retrieve text of a document (Document.Range.Text) or a section Document.Sections.Range.Text and then search inside the returned string.
3. Later we will introduce better find and replace API because it was requested by so many customers. It might be available some time in August, but with Aspose licensing policy you will be able to upgrade for free at any time.
Aspose.Word 1.6.1 with a fix is available http://www.aspose.com/forums/ShowPost.aspx?PostID=8134#8225.
I just came through your problem.
1. You can have bookmark in the document.
ex., here i have given a bookmark name as BMFirstName, u can access the text in the bookmark by Doc.Bookmarks.item(bookmark name).range.text
Dim WordDoc As New Word.Application()
Dim Doc As New Word.Document()
Doc = WordDoc.Documents.Open(StrResfile)
TxtFirstName.Text = Trim( Doc.Bookmarks.Item(“BMFirstName”).Range.Text)
2. You can read complete document text by
Note. close the word,document while unloading ur form
i have done plenty with vb/vb.net with msword / msexcell. u can ask me help at any stage. Don’t hesitate to ask more
Thirugnanam / .net Developer India