自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

淺析C#打開Word文檔實(shí)例

開發(fā) 后端
C#打開Word文檔需要使用什么類呢?具體的C#打開Word文檔實(shí)現(xiàn)過程以及步驟和注意事項(xiàng)是什么呢?希望本文介紹的內(nèi)容隨你有所幫助。

C#打開Word文檔內(nèi)容并顯示是如何實(shí)現(xiàn)的呢?讓我們通過C#打開Word文檔的實(shí)現(xiàn)代碼來學(xué)習(xí)C#打開Word文檔的具體過程和注意事項(xiàng)以及在C#打開Word文檔過程中涉及到的類的使用,希望對(duì)你有所幫助。

C#打開Word文檔實(shí)例如下:

  1. //在項(xiàng)目引用里添加上對(duì)Microsoft Word 11.0 object library的引用  
  2.  
  3. private void button1_Click(object sender, System.EventArgs e)  
  4. {  
  5. //調(diào)用打開文件對(duì)話框獲取要打開的文件WORD文件,RTF文件,文本文件路徑名稱  
  6. OpenFileDialog opd = new OpenFileDialog();  
  7. opd.InitialDirectory = \"c:\\\\\";  
  8. opd.Filter =   
  9. \"Word文檔(*.doc)|*.doc|文本文檔(*.txt)|  
  10. *.txt|RTF文檔(*.rtf)|*.rtf|所有文檔(*.*)|*.*\";  
  11. opd.FilterIndex = 1;  
  12.  
  13. if (opd.ShowDialog() ==   
  14. DialogResult.OK && opd.FileName.Length > 0)  
  15. {  
  16.  
  17. //建立Word類的實(shí)例,缺點(diǎn):不能正確讀取表格,圖片等等的顯示  
  18. Word.ApplicationClass app = new Word.ApplicationClass();  
  19. Word.Document doc = null;  
  20. object missing = System.Reflection.Missing.Value;  
  21.  
  22. object FileName = opd.FileName;  
  23. object readOnly = false;  
  24. object isVisible = true;  
  25. object index = 0;  
  26. try 
  27. {  
  28. doc = app.Documents.Open(  
  29. ref FileName, ref missing, ref readOnly,  
  30. ref missing, ref missing,   
  31. ref missing, ref missing, ref missing,  
  32. ref missing, ref missing,   
  33. ref missing, ref isVisible, ref missing,  
  34. ref missing, ref missing, ref missing);  
  35.  
  36. doc.ActiveWindow.Selection.WholeStory();  
  37. doc.ActiveWindow.Selection.Copy();  
  38. //從剪切板獲取數(shù)據(jù)  
  39. IDataObject data=Clipboard.GetDataObject();  
  40. this.richTextBox1.Text=  
  41. data.GetData(DataFormats.Text).ToString();  
  42.  
  43. }  
  44. finally 
  45. {  
  46. if (doc != null)  
  47. {  
  48. doc.Close(ref missing, ref missing, ref missing);  
  49. doc = null;  
  50. }  
  51.  
  52. if (app != null)  
  53. {  
  54. app.Quit(ref missing, ref missing, ref missing);  
  55. app = null;[Page]  
  56. }  
  57. }  
  58.  
  59. }  
  60.  
  61. }  
  62.  

C#打開Word文檔的具體實(shí)現(xiàn)的基本內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#打開Word文檔有所幫助。

【編輯推薦】

  1. C#項(xiàng)目初期準(zhǔn)備工作淺析
  2. C#項(xiàng)目的創(chuàng)建過程詳解
  3. 詳解C#讀取word內(nèi)容操作
  4. C#讀取Word文件實(shí)例詳解
  5. C#讀取Word學(xué)習(xí)經(jīng)驗(yàn)總結(jié)
責(zé)任編輯:仲衡 來源: e800.com.cn
相關(guān)推薦

2009-08-28 17:34:14

讀取word文檔

2009-08-19 09:42:52

C#操作Word書簽

2009-08-19 11:13:49

C#操作Word

2009-08-19 11:34:06

C#操作Word

2009-08-12 15:26:38

C#讀取XML文檔

2009-09-01 13:51:51

C#創(chuàng)建Word文檔

2009-08-19 11:28:41

C#操作Word

2009-08-19 10:25:14

C#操作Word

2009-08-27 13:30:11

C# interfac

2009-09-27 10:43:13

C#合并多個(gè)WORD文

2009-08-17 17:49:20

C# 枚舉

2009-09-09 13:57:28

C# XML解析

2009-08-18 13:49:21

C# 操作Excel

2009-08-27 17:59:56

C#接口定義

2009-09-01 13:25:25

C#Word文檔替換

2009-08-19 10:16:15

C#操作Word

2009-08-18 16:04:12

C# 操作Excel

2009-08-27 17:11:44

C# Fluent I

2009-08-31 18:38:59

C#寫文件

2009-09-03 14:55:34

C#計(jì)算時(shí)間間隔
點(diǎn)贊
收藏

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