日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#操作Word學(xué)習(xí)實(shí)例淺析

C#操作Word學(xué)習(xí)實(shí)例:首先引入類庫,Microsoft.Office.Interop.Word,然后進(jìn)行編程。代碼如下:

超過十多年行業(yè)經(jīng)驗(yàn),技術(shù)領(lǐng)先,服務(wù)至上的經(jīng)營模式,全靠網(wǎng)絡(luò)和口碑獲得客戶,為自己降低成本,也就是為客戶降低成本。到目前業(yè)務(wù)范圍包括了:成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì),成都網(wǎng)站推廣,成都網(wǎng)站優(yōu)化,整體網(wǎng)絡(luò)托管,小程序定制開發(fā),微信開發(fā),重慶App定制開發(fā),同時(shí)也可以讓客戶的網(wǎng)站和網(wǎng)絡(luò)營銷和我們一樣獲得訂單和生意!

 
 
 
  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.ComponentModel; 
  4. using System.Data; 
  5. using System.Drawing; 
  6. using System.Text; 
  7. using System.Windows.Forms; 
  8. using Microsoft.Office.Interop.Word; 
  9. namespace WordTest 
  10. public partial class Form1 : Form 
  11. object strFileName; 
  12. Object Nothing; 
  13. Microsoft.Office.Interop.Word.Application myWordApp =
  14.  new Microsoft.Office.Interop.Word.ApplicationClass(); 
  15. Document myWordDoc; 
  16. string strContent = ""; 
  17. public Form1() 
  18. InitializeComponent(); 
  19. }   //C#操作Word學(xué)習(xí)實(shí)例淺析
  20. private void button1_Click(object sender, EventArgs e) 
  21. createWord(); 
  22. //openWord(); 
  23. private void createWord() 
  24. strFileName = System.Windows.Forms.Application.StartupPath + "test.doc"; 
  25. if (System.IO.File.Exists((string)strFileName)) 
  26. System.IO.File.Delete((string)strFileName); 
  27. Object Nothing = System.Reflection.Missing.Value; 
  28. myWordDoc = myWordApp.Documents.Add(ref Nothing, 
  29. ref Nothing, ref Nothing, ref Nothing); 
  30. #region 將數(shù)據(jù)庫中讀取得數(shù)據(jù)寫入到word文件中 
  31. strContent = "你好nnr"; 
  32. myWordDoc.Paragraphs.Last.Range.Text = strContent; 
  33. strContent = "這是測試程序"; 
  34. myWordDoc.Paragraphs.Last.Range.Text = strContent; 
  35.  //C#操作Word學(xué)習(xí)實(shí)例淺析
  36. #endregion 
  37. //將WordDoc文檔對(duì)象的內(nèi)容保存為DOC文檔 
  38. myWordDoc.SaveAs(ref strFileName, ref Nothing, 
  39. ref Nothing, ref Nothing, ref Nothing, ref Nothing,
  40.  ref Nothing, ref Nothing, ref Nothing, ref Nothing,
  41.  ref Nothing, ref Nothing, ref Nothing, ref Nothing,
  42.  ref Nothing, ref Nothing); 
  43. //關(guān)閉WordDoc文檔對(duì)象 
  44. myWordDoc.Close(ref Nothing, ref Nothing, ref Nothing); 
  45. //關(guān)閉WordApp組件對(duì)象 
  46. myWordApp.Quit(ref Nothing, ref Nothing, ref Nothing); 
  47. this.richTextBox1.Text = strFileName + "rn" + "創(chuàng)建成功"; 
  48. private void openWord() 
  49. {   //C#操作Word學(xué)習(xí)實(shí)例淺析
  50. fontDialog1.ShowDialog(); 
  51. System.Drawing.Font font = fontDialog1.Font; 
  52. object filepath = "D:asp.docx"; 
  53. object oMissing = System.Reflection.Missing.Value; 
  54. myWordDoc = myWordApp.Documents.Open(ref filepath,
  55.  ref oMissing, ref oMissing, ref oMissing,
  56.  ref oMissing, 
  57. ref oMissing, ref oMissing, ref oMissing,
  58.  ref oMissing, ref oMissing, ref oMissing, 
  59. ref oMissing, ref oMissing, ref oMissing,
  60.  ref oMissing, ref oMissing); 
  61. myWordDoc.Content.Font.Size = font.Size; 
  62. myWordDoc.Content.Font.Name = font.Name; 
  63. myWordDoc.Save(); 
  64. richTextBox1.Text = myWordDoc.Content.Text; 
  65.  //C#操作Word學(xué)習(xí)實(shí)例淺析
  66. myWordDoc.Close(ref oMissing, ref oMissing, ref oMissing); 
  67. myWordApp.Quit(ref oMissing, ref oMissing, ref oMissing); 

C#操作Word學(xué)習(xí)實(shí)例的基本內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#操作Word有所幫助。


網(wǎng)站欄目:C#操作Word學(xué)習(xí)實(shí)例淺析
網(wǎng)站路徑:http://www.dlmjj.cn/article/ccsgdsg.html