EDN Admin
Well-known member
Hi
i want to find an specific placeHolder in the word docs and replace it with a formatted table and some texts, someThing like this :
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; object source = System.IO.Path.Combine(Application.StartupPath, <span style="color:#A31515; "test3.docx");
<span style="color:Blue; object dest = System.IO.Path.Combine(Application.StartupPath, <span style="color:#A31515; "test3_modified.docx");
<span style="color:Blue; object missing = System.Reflection.Missing.Value;
<span style="color:Blue; object endOfDoc = <span style="color:#A31515; "\endofdoc"; <span style="color:Green; /* endofdoc is a predefined bookmark */
<span style="color:Green; // setup Word.Application class.
Microsoft.Office.Interop.Word.Application wordApp = <span style="color:Blue; new Microsoft.Office.Interop.Word.ApplicationClass();
<span style="color:Green; // setup Word.Document class well use
Microsoft.Office.Interop.Word.Document wordDoc = <span style="color:Blue; null;
<span style="color:Blue; object readOnly = <span style="color:Blue; false;
<span style="color:Blue; object isVisible = <span style="color:Blue; false;
<span style="color:Green; // set word to be not visible
wordApp.Visible = <span style="color:Blue; false;
<span style="color:Green; // open the word document
wordDoc = wordApp.Documents.Open(<span style="color:Blue; ref source, <span style="color:Blue; ref missing, <span style="color:Blue; ref readOnly, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing,
<span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref isVisible, <span style="color:Blue; ref missing,
<span style="color:Blue; ref missing, <span style="color:Blue; ref missing);
<span style="color:Green; // activate the document
wordDoc.Activate();
<span style="color:Green; //Insert a 3 x 5 table, fill it with data, and make the first row bold and italic.
Microsoft.Office.Interop.Word.Range wrdRng = wordDoc.Bookmarks.get_Item(<span style="color:Blue; ref endOfDoc).Range;
wrdRng = wordDoc.Paragraphs[1].Range;
Microsoft.Office.Interop.Word.Table oTable = wordDoc.Tables.Add(wrdRng, 3, 5, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing);
oTable.Borders.Enable = 1; <span style="color:Green; // set type of border (solid=1)
oTable.Range.ParagraphFormat.SpaceAfter = 6;
<span style="color:Blue; int r, c;
<span style="color:Blue; string strText;
<span style="color:Blue; for (r = 1; r <= 3; r++)
{
<span style="color:Blue; for (c = 1; c <= 5; c++)
{
strText = <span style="color:#A31515; "r" + r + <span style="color:#A31515; "c" + c;
oTable.Cell(r, c).Range.Text = strText;
oTable.Cell(r, c).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Cell(r, c).VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
}
}
oTable.Rows[1].Range.Font.Bold = 1;
oTable.Rows[1].Range.Font.Italic = 1;
oTable.Rows[1].SetHeight(50, Microsoft.Office.Interop.Word.WdRowHeightRule.wdRowHeightExactly);
<span style="color:Green; // save the document to correct destination
wordDoc.SaveAs(<span style="color:Blue; ref dest, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing,
<span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing,
<span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing);
<span style="color:Green; // close the document
wordDoc.Close(<span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing);
MessageBox.Show(<span style="color:#A31515; "File Modified!");
[/code]
<br/>
i want to replace above result with an specific placeHolder in the given word docs. can anyBody help me to accomplish this ?
thanks in advance <hr class="sig http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
View the full article
i want to find an specific placeHolder in the word docs and replace it with a formatted table and some texts, someThing like this :
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; object source = System.IO.Path.Combine(Application.StartupPath, <span style="color:#A31515; "test3.docx");
<span style="color:Blue; object dest = System.IO.Path.Combine(Application.StartupPath, <span style="color:#A31515; "test3_modified.docx");
<span style="color:Blue; object missing = System.Reflection.Missing.Value;
<span style="color:Blue; object endOfDoc = <span style="color:#A31515; "\endofdoc"; <span style="color:Green; /* endofdoc is a predefined bookmark */
<span style="color:Green; // setup Word.Application class.
Microsoft.Office.Interop.Word.Application wordApp = <span style="color:Blue; new Microsoft.Office.Interop.Word.ApplicationClass();
<span style="color:Green; // setup Word.Document class well use
Microsoft.Office.Interop.Word.Document wordDoc = <span style="color:Blue; null;
<span style="color:Blue; object readOnly = <span style="color:Blue; false;
<span style="color:Blue; object isVisible = <span style="color:Blue; false;
<span style="color:Green; // set word to be not visible
wordApp.Visible = <span style="color:Blue; false;
<span style="color:Green; // open the word document
wordDoc = wordApp.Documents.Open(<span style="color:Blue; ref source, <span style="color:Blue; ref missing, <span style="color:Blue; ref readOnly, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing,
<span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref isVisible, <span style="color:Blue; ref missing,
<span style="color:Blue; ref missing, <span style="color:Blue; ref missing);
<span style="color:Green; // activate the document
wordDoc.Activate();
<span style="color:Green; //Insert a 3 x 5 table, fill it with data, and make the first row bold and italic.
Microsoft.Office.Interop.Word.Range wrdRng = wordDoc.Bookmarks.get_Item(<span style="color:Blue; ref endOfDoc).Range;
wrdRng = wordDoc.Paragraphs[1].Range;
Microsoft.Office.Interop.Word.Table oTable = wordDoc.Tables.Add(wrdRng, 3, 5, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing);
oTable.Borders.Enable = 1; <span style="color:Green; // set type of border (solid=1)
oTable.Range.ParagraphFormat.SpaceAfter = 6;
<span style="color:Blue; int r, c;
<span style="color:Blue; string strText;
<span style="color:Blue; for (r = 1; r <= 3; r++)
{
<span style="color:Blue; for (c = 1; c <= 5; c++)
{
strText = <span style="color:#A31515; "r" + r + <span style="color:#A31515; "c" + c;
oTable.Cell(r, c).Range.Text = strText;
oTable.Cell(r, c).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Cell(r, c).VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
}
}
oTable.Rows[1].Range.Font.Bold = 1;
oTable.Rows[1].Range.Font.Italic = 1;
oTable.Rows[1].SetHeight(50, Microsoft.Office.Interop.Word.WdRowHeightRule.wdRowHeightExactly);
<span style="color:Green; // save the document to correct destination
wordDoc.SaveAs(<span style="color:Blue; ref dest, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing,
<span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing,
<span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing);
<span style="color:Green; // close the document
wordDoc.Close(<span style="color:Blue; ref missing, <span style="color:Blue; ref missing, <span style="color:Blue; ref missing);
MessageBox.Show(<span style="color:#A31515; "File Modified!");
[/code]
<br/>
i want to replace above result with an specific placeHolder in the given word docs. can anyBody help me to accomplish this ?
thanks in advance <hr class="sig http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
View the full article