日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WinForm之创建word并操作文档

發布時間:2025/3/15 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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并操作文档的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。