public void CreateWordFile()
{
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWrod = new Microsoft.Office.Interop.Word.Application();
oWrod.Visible = true;
Microsoft.Office.Interop.Word._Document oDoc = oWrod.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//Add new table
object start = 0;
object end = 0;
Microsoft.Office.Interop.Word.Range tableLocation = oDoc.Range(ref start, ref end);
oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);
oDoc.Tables[1].Cell(1, 1).Range.Text = "test0";
oDoc.Tables[1].Cell(2, 2).Range.Text = "Test8989898989";
}
备注:以上程序运行完全正常,项目中具体需要时,更改下操作就可以了。
C#创建Word文件,并且写入数据的程序
最新推荐文章于 2024-07-17 20:02:36 发布