Basically i have a Microsoft document in word in this format called biodata.docx:
| Name | Linda |
| DOB | 13 jan 2010 |
| Address | 1 nowhere street |
Basically, i want tobe able to upload this document in word, and display the contents in an asp.net form where each text box reads data from a diffent row.
i need help

Posted May 11, 2012, 10:25 PM EDT
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
object WordFile = @"C:\Users\muralidharand\Documents\Name.docx";
object RdOnly = false;
object Visible = true;
object Missing = System.Reflection.Missing.Value;
Document Doc = WordApp.Documents.Open(ref WordFile, ref Missing, ref RdOnly, ref Missing, ref Missing,
ref Missing, ref Missing, ref Missing, ref Missing, ref Missing,
ref Missing, ref Visible, ref Missing, ref Missing, ref Missing,
ref Missing);
Microsoft.Office.Interop.Word.Table mytable = Doc.Tables[1];
foreach (Microsoft.Office.Interop.Word.Row item in mytable.Rows)
{
TableRow row = new TableRow();
for(int i =1;i
TableCell tablecell = new TableCell();
Microsoft.Office.Interop.Word.Cell cell = item.Cells[i];
if (i == 1)
{
tablecell.Text = cell.Range.Text;
}
else
{
TextBox text = new TextBox();
text.Text = cell.Range.Text;
tablecell.Controls.Add(text);
}
row.Cells.Add(tablecell);
}
Table1.Rows.Add(row);
}
WordApp.Documents.Close(ref Missing, ref Missing, ref Missing);
Doc = null;
WordApp = null;
Hope this helps you.
uyoyo Edosio5 reputationPosted May 15, 2012, 6:15 AM EDT
Thank you very much this code worked.
I noticed that when i upload a word document with alot of text large number of words in tables it throws an error "index out of range" but if the data in the table is few the code works.
Posted May 15, 2012, 7:30 AM EDT
uyoyo Edosio5 reputationPosted May 15, 2012, 7:54 AM EDT
Posted May 15, 2012, 8:13 AM EDT
There is a small change in the code that is used to determine to display the textbox or label.
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
object WordFile = @"C:\Users\muralidharand\Documents\Name.docx";
object RdOnly = false;
object Visible = true;
object Missing = System.Reflection.Missing.Value;
Document Doc = WordApp.Documents.Open(ref WordFile, ref Missing, ref RdOnly, ref Missing, ref Missing,
ref Missing, ref Missing, ref Missing, ref Missing, ref Missing,
ref Missing, ref Visible, ref Missing, ref Missing, ref Missing,
ref Missing);
Microsoft.Office.Interop.Word.Table mytable = Doc.Tables[1];
foreach (Microsoft.Office.Interop.Word.Row item in mytable.Rows)
{
TableRow row = new TableRow();
for(int i =1;i
{
TableCell tablecell = new TableCell();
Microsoft.Office.Interop.Word.Cell cell = item.Cells[i];
if (i == 1 || i==2)
{
tablecell.Text = cell.Range.Text;
}
else
{
TextBox text = new TextBox();
text.Text = cell.Range.Text;
tablecell.Controls.Add(text);
}
row.Cells.Add(tablecell);
}
Table1.Rows.Add(row);
}
WordApp.Documents.Close(ref Missing, ref Missing, ref Missing);
Doc = null;
WordApp = null;
venk y46 reputationPosted Oct 31, 2012, 2:37 AM EDT
thanks for your posts,
its realy very useful to me.
keep it up,
thanks,
venkat.
Rafael Montero2 reputationPosted Jun 21, 2013, 5:30 PM EDT