日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
.NET操作Word的實(shí)現(xiàn):usingWord

.NET操作Word可以用using Word來(lái)實(shí)現(xiàn)。基本上,vs.net將會(huì)自動(dòng)將 庫(kù)文件轉(zhuǎn)化為DLL組件,這樣我們只要在源碼中創(chuàng)建該組件對(duì)象即可達(dá)到操作Word的目的。

公司主營(yíng)業(yè)務(wù):做網(wǎng)站、網(wǎng)站制作、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)建站是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。創(chuàng)新互聯(lián)建站推出豐寧免費(fèi)做網(wǎng)站回饋大家。

要實(shí)現(xiàn),我們就需要Word的對(duì)象庫(kù)文件“MSWORD.OLB”(word 2000為MSWORD9.OLB),通常安裝了Office Word后,你就可以在office安裝目錄的Office10文件夾下面找到這個(gè)文件,當(dāng)我們將這個(gè)文件引入到項(xiàng)目后,我們就可以在源碼中使用各種操作函數(shù)來(lái)操作Word。具體做法是打開(kāi)菜單欄中的項(xiàng)目>添加引用>瀏覽,在打開(kāi)的“選擇組件”對(duì)話框中找到MSWORD.OLB后按確定即可引入此對(duì)象庫(kù)文件。

在CS代碼文件中對(duì)命名空間的應(yīng)用,如:using Word;.NET操作Word范例如下:

 
 
 
  1. using System;   
  2. using System.Drawing;   
  3. using System.Collections;   
  4. using System.ComponentModel;   
  5. using System.Windows.Forms;   
  6. using Word;   
  7.  
  8. namespace ExamSecure   
  9. {   
  10.  ///    
  11.  /// ItemToDoc 的摘要說(shuō)明。   
  12.  ///    
  13.  public class ItemToDoc : System.Windows.Forms.Form   
  14.  {   
  15.   object strFileName;   
  16.   Object Nothing;   
  17.   Word.ApplicationClass myWordApp=new Word.ApplicationClass();   
  18.   Word.Document myWordDoc;   
  19.   string strContent="";   
  20.  
  21.   private System.ComponentModel.Container components = null;   
  22.  
  23.   public ItemToDoc()   
  24.   {   
  25.    //   
  26.    // Windows 窗體設(shè)計(jì)器支持所必需的   
  27.    //   
  28.    InitializeComponent();   
  29.  
  30.    //   
  31.    // TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼   
  32.    //   
  33.   }   
  34.   [STAThread]   
  35.   static void Main()    
  36.   {   
  37.    System.Windows.Forms.Application.Run(new ItemToDoc());   
  38.   }   
  39.   ///    
  40.   /// 清理所有正在使用的資源。   
  41.   ///    
  42.   protected override void Dispose( bool disposing )   
  43.   {   
  44.    if( disposing )   
  45.    {   
  46.     if(components != null)   
  47.     {   
  48.      components.Dispose();   
  49.     }   
  50.    }   
  51.    base.Dispose( disposing );   
  52.   }   
  53.  
  54.   #region Windows Form Designer generated code   
  55.   ///    
  56.   /// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改   
  57.   /// 此方法的內(nèi)容。   
  58.   ///    
  59.   private void InitializeComponent()   
  60.   {   
  61.    //    
  62.    // ItemToDoc   
  63.    //    
  64.    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);   
  65.    this.ClientSize = new System.Drawing.Size(292, 273);   
  66.    this.Name = "ItemToDoc";   
  67.    this.Text = "ItemToDoc";   
  68.    this.Load += new System.EventHandler(this.ItemToDoc_Load);   
  69.  
  70.   }   
  71.   #endregion   
  72.  
  73.   private void ItemToDoc_Load(object sender, System.EventArgs e)   
  74.   {   
  75.    WriteFile();   
  76.   }   
  77.   private void WriteFile()   
  78.   {   
  79.      
  80.    strFileName=System.Windows.Forms.Application.StartupPath+"\\試題庫(kù)【"+GetRandomString()+"】.doc";   
  81.    Object Nothing=System.Reflection.Missing.Value;   
  82.    myWordDoc=myWordApp.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing);   
  83.       
  84.    #region 將數(shù)據(jù)庫(kù)中讀取得數(shù)據(jù)寫入到word文件中   
  85.  
  86.    strContent="試題庫(kù)\n\n\r";   
  87.    WriteFile(strContent);   
  88.       
  89.    strContent="試題庫(kù)";   
  90.    WriteFile(strContent);   
  91.  
  92.  
  93.    #endregion    
  94.       
  95.    //將WordDoc文檔對(duì)象的內(nèi)容保存為DOC文檔   
  96.    myWordDoc.SaveAs(ref strFileName,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,ref Nothing);   
  97.    //關(guān)閉WordDoc文檔對(duì)象   
  98.    myWordDoc.Close(ref Nothing, ref Nothing, ref Nothing);   
  99.    //關(guān)閉WordApp組件對(duì)象   
  100.    myWordApp.Quit(ref Nothing, ref Nothing, ref Nothing);   
  101.   }   
  102.  
  103.   ///    
  104.   /// 獲取一個(gè)隨即字符串   
  105.   ///    
  106.   ///    
  107.   private string GetRandomString()   
  108.   {   
  109.    DateTime iNow=DateTime.Now;   
  110.    string strDate=iNow.ToString("yyyyMMddHHmmffff");   
  111.       
  112.    Random ran=new Random();   
  113.    int iRan=Convert.ToInt32(10000*ran.NextDouble());   
  114.    string strRan=iRan.ToString();   
  115.    //位數(shù)不足則補(bǔ)0      
  116.    int iRanlen=strRan.Length;   
  117.    for(int i=0;i<4-iRanlen;i++)   
  118.    {   
  119.     strRan="0"+strRan;   
  120.    }   
  121.    return strDate+strRan;   
  122.   }   
  123.  
  124.  
  125.   ///    
  126.   /// 將字符串寫入到Word文件中   
  127.   ///    
  128.   /// 要寫入的字符串   
  129.   private void WriteFile(string str)   
  130.   {   
  131.    myWordDoc.Paragraphs.Last.Range.Text=str;   
  132.   }   
  133.  
  134.  
  135.  }   
  136. }   

以上就是.NET操作Word的實(shí)現(xiàn)代碼。

【編輯推薦】

  1. ASP.NET新手問(wèn)題總結(jié)
  2. 深入研究Repeater控件:最大的靈活性
  3. DataList控件入門介紹
  4. DataGrid Web控件運(yùn)作機(jī)制探秘
  5. 小議ASP.NET數(shù)據(jù)Web控件之間的相似性

網(wǎng)頁(yè)題目:.NET操作Word的實(shí)現(xiàn):usingWord
文章URL:http://www.5511xx.com/article/djjjpee.html