偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

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

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

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

  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í)實(shí)例淺析
  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ù)庫(kù)中讀取得數(shù)據(jù)寫(xiě)入到word文件中   
  42.  
  43. strContent = "你好nnr";   
  44. myWordDoc.Paragraphs.Last.Range.Text = strContent;   
  45.  
  46. strContent = "這是測(cè)試程序";   
  47. myWordDoc.Paragraphs.Last.Range.Text = strContent;   
  48.  //C#操作Word學(xué)習(xí)實(shí)例淺析
  49.  
  50. #endregion   
  51.  
  52. //將WordDoc文檔對(duì)象的內(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文檔對(duì)象   
  59. myWordDoc.Close(ref Nothing, ref Nothing, ref Nothing);   
  60. //關(guān)閉WordApp組件對(duì)象   
  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í)實(shí)例淺析
  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í)實(shí)例淺析
  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í)實(shí)例的基本內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#操作Word有所幫助。

【編輯推薦】

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

2009-08-19 11:13:49

C#操作Word

2009-08-19 09:42:52

C#操作Word書(shū)簽

2009-08-19 10:25:14

C#操作Word

2009-08-19 11:28:41

C#操作Word

2009-09-01 13:13:28

C#打開(kāi)Word文檔

2009-08-28 17:34:14

讀取word文檔

2009-08-18 13:49:21

C# 操作Excel

2009-08-31 18:38:59

C#寫(xiě)文件

2009-08-18 16:04:12

C# 操作Excel

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-18 17:42:12

C#操作符重載

2009-08-19 14:12:23

C#操作注冊(cè)表

2009-08-19 16:30:55

C#操作Access數(shù)

2009-08-17 13:34:02

C#異步操作

2009-08-27 17:59:56

C#接口定義

2009-08-19 17:44:15

C#操作文本文件

2009-08-17 17:49:20

C# 枚舉
點(diǎn)贊
收藏

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