1、利用Word文档模板创建Word文档
object filedot = "....//Member.dot";
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref filedot, ref Nothing, ref Nothing, ref Nothing);
WordApp.Visible = true;
2、获取表格,填充内容
Microsoft.Office.Interop.Word.Selection selection=WordApp.Selection;
Microsoft.Office.Interop.Word.Tables newTables = WordDoc.Tables;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];//得到表1
3、移动光标
object count = 1;
object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//左、右、上移类似
4、在表格中插入行
WordApp.Selection.InsertRowsBelow(ref count);
5、在表格中填充内容
newTable.Cell(row, col).Range.Text="";
6、获取表格中的内容
string s = newTable.Cell(row, col).Range.Text;
7、文件保存
object filename = "....//保存.doc"; //文件保存路径和文件名
WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);