用C#把数据库中的记录按格式写入Word文档中

来源:互联网 发布:常用算法时间复杂度 编辑:程序博客网 时间:2024/05/29 10:26
 

使用Word的COM组件。

Word._Application app = new Word.ApplicationClass();   
app.Visible = false;
    
object nothing = System.Reflection.Missing.Value;
object temp = Environment.CurrentDirectory + @"/resume.doc";   //文档模板

Word.Document doc = app.Documents.Open(ref temp,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);//打开模板

doc.Tables[1].Cell(1,2).Range.Text  = ""; // 给单元格添加内容

//给单元格插入图片
doc.Tables[1].Cell(1,5).Range.InlineShapes.AddPicture(ImgPath,ref nothing,ref nothing,ref nothing);