用C#把資料庫中的記錄按格式寫入Word文件中。
阿新 • • 發佈:2019-01-31
使用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);