将值从列表传递到MS-Word表
本文关键字:MS-Word 列表 | 更新日期: 2023-09-27 18:01:26
我有一个存储在list中的值列表。我需要将所有列表值传递到MS-Word中的表中。表也应该随着列表的大小而增长。我在windows窗体c#中实现这个。
希望我能从你那边得到一些想法。
提前感谢…:)
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
}
希望对大家有所帮助