Pregunta

I have a list of values stored in a List. I need to pass all the list values to a table in MS-Word. The table should also grow as per the list size. I am implementing this in windows forms C#.

Hope I can get ideas from your side.

Thanks in advance.. :)

¿Fue útil?

Solución

List<string> YourList = new List<string>();
//fill your list 

object oMissing = System.Reflection.Missing.Value;        
// get your table or create a new one like this
// the number '2' is the rows number 
Microsoft.Office.Interop.Word.Table myTable = oWordDoc.Add(myRange, 2,numberOfColumns)
int rowCount = 2; 
//add a row for each item in a collection.
foreach( var s in YourList)
{
   myTable.Rows.Add(ref oMissing)
   // do somethign to the row here. add strings etc. 
   myTable.Rows.[rowCount].Cells[1].Range.Text = "Content of column 1";
   myTable.Rows[rowCount].Cells[2].Range.Text = "Content of column 2";
   myTable.Rows[rowCount].Cells[3].Range.Text = "Content of column 3";
   //etc
}

I hope this helps

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top