Click here to Skip to main content
14,775,221 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
Am trying to display the contents of word document paragraph by paragraph in the textbox. i tried a code and it is displaying everything at a time and displaying the last paragraph. But i want to display the contents with manual interruption.
For example if i click on next button it should display the next paragraph and if i click on previous button it should display the previous paragraph.
Please suggest me a code.
Thanks in advance

Email ID: removed
Posted
Updated 29-Aug-12 4:54am
v2
Comments
[no name] 29-Aug-12 9:55am
   
Posting your email address is an invitation to spammers and I have removed it.

1 solution

When you load your word document, you should probably break document up into a List<string> where each item in the list contains a single paragraph. Then all you have to do is navigate through the items in the List and show them.

Update:
Dim currentIndex As Int
Dim list As New List(Of String)

currentIndex = 0

For Each p In currentDocument.Paragraphs
   list.Add(p.range.text)
Next p

TextBox.Text = list[currentIndex]

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
   currentIndex = currentIndex + 1
   TextBox.Text = list[currentIndex]
End Sub

There are probably some syntax errors in this snippet as I don't do any VB.Net development anymore, but I think this will give you the idea. You'll also have to make sure to validate to make sure that things like the currentIndex and such are within a valid range before trying to apply them.
   
v2
Comments
vinay597 29-Aug-12 10:10am
   
Can you please suggest me how to break the document into list.
Am trying this code.
For Each p In currentDocument.Paragraphs
TextBox.Text = p.range.text
Next p
Am trying this code but it is displaying the last paragraph.
when i change the code TextBox.Text = p.range.text into messagebox.show(p.range.text)...It is displaying one by one but i want the same type in textbox and when i click on next button it should go to the next paragraph.
Please drop me the code..Thanks
vinay597 29-Aug-12 11:14am
   
Thanks for the code........Its working..
one more question...
is there any code to delete the empty lines because the code is working but it is displaying the empty lines
For example
if there is an empty line after a paragraph it is displaying that empty line if i click on next....Actually am new to .net and am building a project..
fjdiewornncalwe 29-Aug-12 13:50pm
   
Just wrap the list.Add(p.range.text) in a if string.IsNullOrWhitespace(p.range.text) call. That will strip out the empty paragraphs that come in.
vinay597 30-Aug-12 7:20am
   
In the same code is there any logic to delete all the paragraphs up to a particular paragraph...and i want to start the display from that particular paragraph
fjdiewornncalwe 30-Aug-12 11:44am
   
What do you think you could do to achieve that? Remember that you are building a list of paragraphs. If you are doing that then you can count them at the same time and just keep the ones you want to. See where that thought takes you.
vinay597 30-Aug-12 23:22pm
   
i thought in the same way..but that particular point(paragraph) comes at one point in one doc and in another place in another document....so i want to capture with the some particular text in that document..and i want to display all the contents after that.
fjdiewornncalwe 31-Aug-12 8:45am
   
Instead of just counting the paragraphs, there is nothing stopping you from just wrapping the list.Add(p.range.text) in the code you need to use to identify the paragraph in question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900