S
Stitch 2.0
Hi all,
I'm desperatly trying to add an HTML Table into a Word document using
C#.
For example:
Here is the table I want to insert:
<table>
<tr>
<td>some text here</td>
</tr>
<tr>
<td>some other text here</td>
</tr>
</table>
Currently I am using the following code to do it:
object fileToOpen = (object) @"C:\input.doc";
app = new MSWord.ApplicationClass();
doc = new MSWord.Document();
doc = app.Documents.Open(ref fileToOpen, ref Missing, ref Missing, ref
Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref
Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref
Missing, ref Missing,ref Missing);
bookmarkName = (object) "myBookmark";
rng = doc.Bookmarks.get_Item(ref bookmarkName).Range;
MSWord.Table oTable;
oTable = doc.Tables.Add(rng, 1 , 1, ref Missing, ref Missing);
Table.Cell(1,1).Range.Text = "<table><tr><td>some text
here</td></tr><tr><td>some other text here</td></tr></table>";
object fileToSave = (object) @"C:\output.doc";
doc.SaveAs(ref fileToSave, ref Missing, ref Missing, ref Missing, ref
Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref
Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref
Missing, ref Missing);
Unfortunately, the resulting document only contains a single string:
some text heresome other text here
Meaning, word simply ignores the HTML tags and inserts the text only.
Any ideas on how to solve this?
I tried to google for a solutions, but couldn't find one...
And, by the way, it's Word 2003 we're using here.
Thanks in Advance,
Stitch
I'm desperatly trying to add an HTML Table into a Word document using
C#.
For example:
Here is the table I want to insert:
<table>
<tr>
<td>some text here</td>
</tr>
<tr>
<td>some other text here</td>
</tr>
</table>
Currently I am using the following code to do it:
object fileToOpen = (object) @"C:\input.doc";
app = new MSWord.ApplicationClass();
doc = new MSWord.Document();
doc = app.Documents.Open(ref fileToOpen, ref Missing, ref Missing, ref
Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref
Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref
Missing, ref Missing,ref Missing);
bookmarkName = (object) "myBookmark";
rng = doc.Bookmarks.get_Item(ref bookmarkName).Range;
MSWord.Table oTable;
oTable = doc.Tables.Add(rng, 1 , 1, ref Missing, ref Missing);
Table.Cell(1,1).Range.Text = "<table><tr><td>some text
here</td></tr><tr><td>some other text here</td></tr></table>";
object fileToSave = (object) @"C:\output.doc";
doc.SaveAs(ref fileToSave, ref Missing, ref Missing, ref Missing, ref
Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref
Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref
Missing, ref Missing);
Unfortunately, the resulting document only contains a single string:
some text heresome other text here
Meaning, word simply ignores the HTML tags and inserts the text only.
Any ideas on how to solve this?
I tried to google for a solutions, but couldn't find one...
And, by the way, it's Word 2003 we're using here.
Thanks in Advance,
Stitch