WinForm之创建word并操作文档
生活随笔
收集整理的這篇文章主要介紹了
WinForm之创建word并操作文档
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
private?void?button1_Click(object?sender,?EventArgs?e){if?(textBox1.Text?==?""?||?textBox2.Text?==?""?||?textBox3.Text?==""){MessageBox.Show("請輸入創建Word文檔的名稱、路徑和內容",?"信息提示",?System.Windows.Forms.MessageBoxButtons.OK,?System.Windows.Forms.MessageBoxIcon.Warning);}else{//初始化wordApp?=?new?MSWord.ApplicationClass();object?Nothing?=?Missing.Value;worddoc?=?wordApp.Documents.Add(ref?Nothing,?ref?Nothing,?ref?Nothing,?ref?Nothing);object?format?=?MSWord.WdSaveFormat.wdFormatDocument;//定義圖片文件的路徑string?PicPath?=?textBox3.Text;//向Word文件中插入圖片的位置Object?range?=?worddoc.Paragraphs.Last.Range;//定義插入圖片是否為外部連接Object?linktofile?=?false;Object?savedocument?=?true;//插入圖片worddoc.InlineShapes.AddPicture(PicPath,?ref?linktofile,?ref?savedocument,?ref?range);//保存文檔path?=?textBox2.Text+"\\"?+?textBox1.Text;worddoc.SaveAs(ref?path,?ref?format,?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);//關閉worddoc文檔對象worddoc.Close(ref?Nothing,?ref?Nothing,?ref?Nothing);//關閉wordApp組對象wordApp.Quit(ref?Nothing,?ref?Nothing,?ref?Nothing);MessageBox.Show("Word文檔被成功創建",?"信息提示",?System.Windows.Forms.MessageBoxButtons.OK,?System.Windows.Forms.MessageBoxIcon.Information);}}
總結
以上是生活随笔為你收集整理的WinForm之创建word并操作文档的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 爸爸拉合弦飞鸽传书源代码
- 下一篇: 走几步回头看看企业即时通讯