1.引用word 组件
2.定义word
Word.Application app = new Word.Application();
Word.Document doc = new Word.Document();
app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
object Obj_FileName = “filename”;
object Visible = false;
object ReadOnly = false;
//打开文件
doc = app.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref Visible,
ref missing, ref missing, ref missing,
ref missing);
doc.Activate();
3.写word文档
//写word文档
Word.Table tbl = doc.Tables[1];
tbl.Cell(1,2).Range.Text=‘’;
4.拷贝数据
Word.Bookmark myBookmark;
object oBookmark = "a";
myBookmark=doc.Bookmarks.get_Item(ref oBookmark);
myBookmark.Select();
myBookmark.Range.Copy();
5.粘贴数据
object oMyWordStrat= doc.Content.End-1;
Word.Range rang=doc.Range(ref oMyWordStrat,ref oMyWordStrat);
rang.InsertBreak(ref missing);
rang.Paste();
6.保存
doc.Save();
object IsSave = false;
doc.Close(ref IsSave,ref missing,ref missing);
7.退出应用
object IsSave = false;
app.Quit(ref IsSave,ref missing,ref missing);
app = null;
2.定义word
Word.Application app = new Word.Application();
Word.Document doc = new Word.Document();
app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
object Obj_FileName = “filename”;
object Visible = false;
object ReadOnly = false;
//打开文件
doc = app.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref Visible,
ref missing, ref missing, ref missing,
ref missing);
doc.Activate();
3.写word文档
//写word文档
Word.Table tbl = doc.Tables[1];
tbl.Cell(1,2).Range.Text=‘’;
4.拷贝数据
Word.Bookmark myBookmark;
object oBookmark = "a";
myBookmark=doc.Bookmarks.get_Item(ref oBookmark);
myBookmark.Select();
myBookmark.Range.Copy();
5.粘贴数据
object oMyWordStrat= doc.Content.End-1;
Word.Range rang=doc.Range(ref oMyWordStrat,ref oMyWordStrat);
rang.InsertBreak(ref missing);
rang.Paste();
6.保存
doc.Save();
object IsSave = false;
doc.Close(ref IsSave,ref missing,ref missing);
7.退出应用
object IsSave = false;
app.Quit(ref IsSave,ref missing,ref missing);
app = null;