c# code to search text/string in word doc and get page number

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif I am using Visual studio 2005(Framework 2.0).My project is window application and using c# language. We are having word templates created in office
2003, 2007 and 2010.
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif I want to search text (string) in word template (.dot/.doc/.docx).This text/string is exist in two places in word doc :
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif 1) table
<table border="0" cellpadding="0" cellspacing="0" width="736" style="width:552pt; border-collapse:collapse
<tbody>
<tr style="height:16.9pt
<td valign="top" width="105" style="border-right:rgb(51,51,153) 1pt solid; padding-right:5.4pt; border-width:78.6pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Question Title
</td>
<td valign="top" width="88" style="border-right:1pt solid; padding-right:5.4pt; border-width:66.1pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Issue no
</td>
<td valign="top" width="119" style="border-right:1pt solid; padding-right:5.4pt; border-width:89.6pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Change description
</td>
<td valign="top" width="98" style="border-right:1pt solid; padding-right:5.4pt; border-width:73.3pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Page no
</td>
<td valign="top" width="98" style="border-right:1pt solid; padding-right:5.4pt; border-width:73.3pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Title
</td>
<td valign="top" width="98" style="border-right:1pt solid; padding-right:5.4pt; border-width:73.3pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Modified By
</td>
<td valign="top" width="130" style="border-right:1pt solid; padding-right:5.4pt; border-width:97.75pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif date
</td>
</tr>
<tr style="height:41.95pt
<td valign="top" width="105" style="border-right:1pt solid; padding-right:5.4pt; border-width:78.6pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span lang="FR" style="font-size:9pt; font-family:Verdana,sans-serif «QUESTION_TITLE»
</td>
<td valign="top" width="88" style="border-right:1pt solid; padding-right:5.4pt; border-width:66.1pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span lang="FR" style="font-size:9pt; font-family:Verdana,sans-serif «Issue_no»
</td>
<td valign="top" width="119" style="border-right:1pt solid; padding-right:5.4pt; border-width:89.6pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span lang="FR" style="font-size:9pt; font-family:Verdana,sans-serif xyz
</td>
<td valign="top" width="98" style="border-right:1pt solid; padding-right:5.4pt; border-width:73.3pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span lang="FR" style="font-size:9pt; font-family:Verdana,sans-serif «QUESTION_MODIFICATION_NAME»
</td>
<td valign="top" width="130" style="border-right:1pt solid; padding-right:5.4pt; border-width:97.75pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:8pt; color:black; font-family:Arial,sans-serif «QUESTION_MODIFICATION_DATE»
</td>
</tr>
</tbody>
</table>
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif 2) title/subtitle
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif 1.2.1 xyz
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif I want the page no and title/subtitle to copy into table.
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif For an example table is exist on page 1 and having column value as
xyz. Title/Subtitle 1.2.1 is exist on page no 3 with value
xyz .
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif Now I want to update table by page no and title/subtitle of word doc :
<table border="0" cellpadding="0" cellspacing="0" width="736" style="width:552pt; border-collapse:collapse
<tbody>
<tr style="height:16.9pt
<td valign="top" width="105" style="border-right:rgb(51,51,153) 1pt solid; padding-right:5.4pt; border-width:78.6pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Question Title
</td>
<td valign="top" width="88" style="border-right:1pt solid; padding-right:5.4pt; border-width:66.1pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Issue no
</td>
<td valign="top" width="119" style="border-right:1pt solid; padding-right:5.4pt; border-width:89.6pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Change description
</td>
<td valign="top" width="98" style="border-right:1pt solid; padding-right:5.4pt; border-width:73.3pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Page no
</td>
<td valign="top" width="98" style="border-right:1pt solid; padding-right:5.4pt; border-width:73.3pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Title
</td>
<td valign="top" width="98" style="border-right:1pt solid; padding-right:5.4pt; border-width:73.3pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif Modified By
</td>
<td valign="top" width="130" style="border-right:1pt solid; padding-right:5.4pt; border-width:97.75pt; height:16.9pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:7.5pt; color:gray; font-family:Arial,sans-serif date
</td>
</tr>
<tr style="height:41.95pt
<td valign="top" width="105" style="border-right:1pt solid; padding-right:5.4pt; border-width:78.6pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span lang="FR" style="font-size:9pt; font-family:Verdana,sans-serif «QUESTION_TITLE»
</td>
<td valign="top" width="88" style="border-right:1pt solid; padding-right:5.4pt; border-width:66.1pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span lang="FR" style="font-size:9pt; font-family:Verdana,sans-serif «Issue_no»
</td>
<td valign="top" width="119" style="border-right:1pt solid; padding-right:5.4pt; border-width:89.6pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span lang="FR" style="font-size:9pt; font-family:Verdana,sans-serif «QUESTION_MODIFICATION_DESCRIPT»
</td>
<td valign="top" width="98" style="border-right:1pt solid; padding-right:5.4pt; border-width:73.3pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif 3
</td>
<td valign="top" width="98" style="border-right:1pt solid; padding-right:5.4pt; border-width:73.3pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif 1.2.1
</td>
<td valign="top" width="98" style="border-right:1pt solid; padding-right:5.4pt; border-width:73.3pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span lang="FR" style="font-size:9pt; font-family:Verdana,sans-serif «QUESTION_MODIFICATION_NAME»
</td>
<td valign="top" width="130" style="border-right:1pt solid; padding-right:5.4pt; border-width:97.75pt; height:41.95pt
<p style="margin-bottom:12pt; line-height:normal <span lang="EN-US" style="font-size:8pt; color:black; font-family:Arial,sans-serif «QUESTION_MODIFICATION_DATE»
</td>
</tr>
</tbody>
</table>
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif I am not able to find c# code to search text/string(xyz) in word doc and modify table with page no(3) and title(1.2.1) in word doc.
<p style="margin-bottom:12pt; line-height:normal <span style="font-size:9pt; font-family:Verdana,sans-serif Please help me to find c# code. <hr class="sig Nitin Varshneya

View the full article
 
Back
Top