reading text from .doc/.docx BookMarks

Technical support for Spire.Doc

Moderator: iceblue support

reading text from .doc/.docx BookMarks

Postby valaranip » Thu Oct 06, 2011 6:40 am

Hi,

I have a problem in reading text from word document (.doc/.docx) bookmarks. Please help to provide some sample code in C# to read the text from Bookmarks in document.

I can go through the bookmarks as follows: The code is:-

Document document = new Document();
document.LoadFromFile(@"c:\workspace\test.doc");
document.LoadFromFile(@textBox1.Text);

//This can read the whole text from a .doc file; However I need to specifically extract text from bookmarks.
this.rtbText.Text = document.GetText();

foreach (Bookmark selection in document.Bookmarks)
{
///Need to add the code here to read the text from corresponding bookmark- from start to end.
}

Please help.

Thank you,
Prashant.
Last edited by valaranip on Fri Oct 07, 2011 1:03 am, edited 1 time in total.
valaranip
 
Posts: 2
Joined: Tue Oct 04, 2011 2:11 am

Re: reading text from .doc/.docx BookMarks

Postby Tina.Lin » Sun Oct 09, 2011 7:55 am

hello Prashant,

Sorry for any inconveniences caused by us and thank you for your patience with our reply.

If you want to get the text between markbookstart and bookmarkend, you can try the code as below:
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(@"..\..\bookmark.doc",FileFormat.Doc);
            foreach (Bookmark bookmark in doc.Bookmarks)
            {
                BookmarkStart bookmarkStart = bookmark.BookmarkStart;
                IDocumentObject nextNode = bookmarkStart.NextSibling;
                StringBuilder buffer = new StringBuilder();
                while (nextNode is ParagraphBase && nextNode != bookmark.BookmarkEnd)
                {
                    if (nextNode is TextRange)
                    {
                        buffer.Append((nextNode as TextRange).Text);
                        Console.WriteLine(buffer);
                    }
                    nextNode = nextNode.NextSibling;             
                }
            }
            Console.ReadKey();

If you still have any question, please don’t hesitate to contact us for any thing at any time.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar
Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Re: reading text from .doc/.docx BookMarks

Postby valaranip » Thu Oct 13, 2011 8:00 am

Hi Tina,

Thanks a lot for your reply. It is ok now.

Prashant.
valaranip
 
Posts: 2
Joined: Tue Oct 04, 2011 2:11 am


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests