We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

WordDocument.Find doesn''t work?!

Thread ID:

Created:

Updated:

Platform:

Replies:

55734 Feb 3,2007 08:35 PM UTC Feb 10,2007 05:57 AM UTC ASP.NET Web Forms (Classic) 6
loading
Tags: DocIO
Henrik Brinch
Asked On February 3, 2007 08:35 PM UTC

Dear Sirs,

I have a problem:

I need to find text with a given pattern within a document and then replace it with some text.

Obviously one would use the Replace functionality, this works but this requires I know exactly the text to replace.

E.g. I want to find something like for each of these occurrences found in the document I will extract the "xxxx" part to determine what to insert at that position in the document.

I've tried to develop this using the WordDocument.Find method ... however I simply can't make it work!!!

It always returns a TextRangesHolder with no items found (though I've managed to make it return an item, if I only search after a text with one character!). What am I doing wrong here?

I've event tried the FindAndReplace sample, where I can see in li. 310:

FindRange = doc.Find( textBoxReplace.Text.Trim() , matchCase , wholeWord );

is performed. So I set a breakpoint on this line and load the word document... the same result... nothing is ever found.

I'm pretty clueless here.

Best Regards,
- Henrik Brinch, TriGemini
DENMARK

Henrik Brinch
Replied On February 3, 2007 09:22 PM UTC

I think I've narrowed it down to:

Find() doesn't work when trying to find text within Tables!

Best Regards,
- Henrik Brinch, TriGemini
DENMARK

Henrik Brinch
Replied On February 4, 2007 04:02 PM UTC

I've managed to achieve what I want, with the help of the source and a little workarounds. However it would be NICE if the Items property on the Paragraph wasn't protected but public (my trick is done with some reflection).

private void GetParagraphs(IParagraphCollection paragraphs, ArrayList result)
{
PropertyInfo piPara = typeof(Paragraph).GetProperty("Items", BindingFlags.NonPublic|BindingFlags.Instance);

foreach(Paragraph paragraph in paragraphs)
{
IParagraphItemCollection paraColl = piPara.GetValue(paragraph, null) as IParagraphItemCollection;

foreach(IParagraphItem paraItem in paraColl)
{
if(paraItem is WTable)
{
WTable tabItem = paraItem as WTable;

foreach(WTableRow tabRow in tabItem.Rows)
{
foreach(WTableCell tabCell in tabRow.Cells)
{
GetParagraphs(tabCell.Paragraphs, result);
}
}
}

}

result.Add(paragraph);
}
}

private void GetAllParagraphcs(IDocument doc, ArrayList result)
{
foreach(Section section in doc.Sections)
{
GetParagraphs(section.Paragraphs, result);
}
}


So now I can just make:

ArrayList paragraphs = new ArrayList();
GetAllParagraphcs(doc, paragraphs);

foreach(Paragraph paragraph in paragraphs)
{
paragraph.Replace("", "This is replaced", false, false);
}

This will also replace within tables!

Now I could of course make my own compiled version of the library, but I would prefer if you in a comming release make the Items property public or at least somehow provide the functionality so it will be possible to Find/Replace within tables.

Best Regards,
Henrik Brinch, TriGemini
DENMARK

Dhivya K [Syncfusion]
Replied On February 5, 2007 02:09 PM UTC

Hi DenMark,

Thank you for your interest in Essential DocIO.

Thanks for your detailed description and instant updates regarding this issue. Thanks for sharing your ideas and suggestions too.

We have some issues in finding and replacing text inside the tables. However, these are fixed internally now and will be available in our next release. Could you please provide me your sample template document so that I can test it with our internal version and provide you with an update regarding this issue. Also, could you please create a direct trac incident so that the files can be kept confidential.

Regards,
Dhivya.

Henrik Brinch
Replied On February 5, 2007 06:34 PM UTC

Hi Dhiva,

Actually it is a very simple document, with a couple of tables (not nested). There is some "tags" in some of the cells that I have to find.

My problems are not over :-( Now I'm able to insert text into "tags" whereever in a document, however it would be nice if I could generate a table and insert at the position of my tag (simple) text (and then just replace the tag with empy text). This I just can't seem to achieve. Is it in any way possible to find the parent section/paragraph of a TextRange/TextRangeHolder?

Best Regards,
- Henrik Brinch, TriGemini


>Hi DenMark,

Thank you for your interest in Essential DocIO.

Thanks for your detailed description and instant updates regarding this issue. Thanks for sharing your ideas and suggestions too.

We have some issues in finding and replacing text inside the tables. However, these are fixed internally now and will be available in our next release. Could you please provide me your sample template document so that I can test it with our internal version and provide you with an update regarding this issue. Also, could you please create a direct trac incident so that the files can be kept confidential.

Regards,
Dhivya.

Administrator [Syncfusion]
Replied On February 10, 2007 05:57 AM UTC

Hi TriGemini,

Currently we do not provide support to find the text and replace it with tables. We already have a feature request [Fr# 1028] regarding this issue. Here is the feature request link:

http://www.syncfusion.com/support/features/docio/Default.aspx?ToDo=view&questId=1028

I will consult with the development team regarding this feature and will update you the status of this feature with in a week.

Kindly let me know if you have any other questions.

Thanks,
Melba

Melba Winshia [Syncfusion]
Replied On February 10, 2007 05:57 AM UTC

Hi Henrick,

Currently we do not provide support to find the text and replace it with tables. We already have a feature request [Fr# 1098] regarding this issue. Here is the feature request link:

http://www.syncfusion.com/support/features/docio/Default.aspx?ToDo=view&questId=1028

I will consult with the development team regarding this feature and will update you the status of this feature with in a week.

Kindly let me know if you have any other questions.

Thanks,
Melba

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;