成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

C#操作Word學(xué)習(xí)實例淺析

開發(fā) 后端
C#操作Word學(xué)習(xí)實例主要向你介紹了C#操作Word學(xué)習(xí)中的一個練習(xí),希望對你了解和學(xué)習(xí)C#操作Word有所幫助。

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

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

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

【編輯推薦】

  1. C#操作Word表的實例淺析
  2. C#操作Word表格的常見操作
  3. C#操作Word表格的彪悍實例
  4. C#操作Word實用實例淺析
  5. C#操作Word的一點認識
責(zé)任編輯:仲衡 來源: itpub.net
相關(guān)推薦

2009-08-19 09:42:52

C#操作Word書簽

2009-08-19 11:13:49

C#操作Word

2009-08-19 11:28:41

C#操作Word

2009-08-19 10:25:14

C#操作Word

2009-08-28 17:34:14

讀取word文檔

2009-09-01 13:13:28

C#打開Word文檔

2009-08-18 13:49:21

C# 操作Excel

2009-08-18 16:04:12

C# 操作Excel

2009-08-31 18:38:59

C#寫文件

2009-08-26 13:48:31

C#打印條碼

2009-08-20 11:07:07

C#共享內(nèi)存

2009-08-27 13:30:11

C# interfac

2009-08-19 10:46:48

C#操作Word表格

2009-08-19 16:30:55

C#操作Access數(shù)

2009-08-19 14:12:23

C#操作注冊表

2009-08-18 17:42:12

C#操作符重載

2009-08-17 13:34:02

C#異步操作

2009-08-17 17:49:20

C# 枚舉

2009-09-09 13:57:28

C# XML解析

2009-08-27 17:59:56

C#接口定義
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 久久在线看 | 国产高清一区二区三区 | 国产丝袜一区二区三区免费视频 | 综合久久久 | 日本精品一区二区三区四区 | 日韩一区二区免费视频 | 国产在线视频一区 | 国产成人精品999在线观看 | 在线观看中文字幕视频 | 九九伦理电影 | 国产精品久久久久aaaa九色 | 超碰97人人人人人蜜桃 | 国产大学生情侣呻吟视频 | 国产精品久久久久久久久久三级 | 成人不卡在线 | 中文字幕成人免费视频 | 亚洲第一福利网 | 欧美亚洲国产成人 | 久久精品久久久久久 | 久久婷婷香蕉热狠狠综合 | 久久久久久国产精品 | 精品区| 国产精品自产拍 | 麻豆久久久9性大片 | 国产在线www | 国产一区二区三区在线 | 欧美精品网站 | 亚洲图片一区二区三区 | 日韩在线免费 | 91av在线免费 | 97精品久久 | 黄色网址在线免费观看 | 99热在线播放 | 精品日韩在线 | 亚洲成人免费视频在线 | 欧美一区二区三区的 | 黄色一级电影免费观看 | 欧美日韩久久久 | 在线观看中文字幕dvd播放 | 中文字幕在线一区二区三区 | 天堂一区二区三区 |