C#创建Word文件,并且写入数据的程序

来源:互联网 发布:淘宝数据库架构 编辑:程序博客网 时间:2024/05/19 02:04

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";
        }
备注:以上程序运行完全正常,项目中具体需要时,更改下操作就可以了。

原创粉丝点击