asp.net 產生word__.net

來源:互聯網
上載者:User
/// <SUMMARY></SUMMARY>   
       /// word 應用對象   
       ///    
       private Microsoft.Office.Interop.Word.Application _wordApplication;   
  
       /// <SUMMARY></SUMMARY>   
       /// word 檔案對象   
       ///    
       private Microsoft.Office.Interop.Word.Document _wordDocument;    
       /// <SUMMARY></SUMMARY>   
       /// 建立文檔   
       ///    
       public void CreateAWord()   
       {   
           //執行個體化word應用對象   
           this._wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();   
           Object myNothing = System.Reflection.Missing.Value;   
  
           this._wordDocument = this._wordApplication.Documents.Add(ref myNothing, ref myNothing, ref myNothing, ref myNothing);   
       }   
       /// <SUMMARY></SUMMARY>   
       /// 添加頁首   
       ///    
       /// <PARAM name="pPageHeader" />   
       public void SetPageHeader(string pPageHeader)   
       {   
           //添加頁首   
           this._wordApplication.ActiveWindow.View.Type =Microsoft .Office .Interop .Word.WdViewType.wdOutlineView;   
           this._wordApplication.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;   
           this._wordApplication.ActiveWindow.ActivePane.Selection.InsertAfter(pPageHeader);   
           //設定中間對齊   
           this._wordApplication.Selection.ParagraphFormat.Alignment =Microsoft .Office .Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;   
           //跳出頁首設定   
           this._wordApplication.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;   
       }   
       /// <SUMMARY></SUMMARY>   
       /// 插入文字   
       ///    
       /// <PARAM name="pText" />文本資訊   
       /// <PARAM name="pFontSize" />字型打小   
       /// <PARAM name="pFontColor" />字型顏色   
       /// <PARAM name="pFontBold" />字型粗體   
       /// <PARAM name="ptextAlignment" />方向   
       public void InsertText(string pText, int pFontSize, Microsoft.Office.Interop.Word.WdColor pFontColor, int pFontBold, Microsoft.Office.Interop.Word.WdParagraphAlignment ptextAlignment)   
       {   
           //設定字型樣式以及方向   
           this._wordApplication.Application.Selection.Font.Size = pFontSize;   
           this._wordApplication.Application.Selection.Font.Bold = pFontBold;   
           this._wordApplication.Application.Selection.Font.Color= pFontColor;   
           this._wordApplication.Application.Selection.ParagraphFormat.Alignment = ptextAlignment;   
           this._wordApplication.Application.Selection.TypeText(pText);   
       }   
  
  
       /// <SUMMARY></SUMMARY>   
       /// 換行   
       ///    
       public void NewLine()   
       {   
           //換行   
           this._wordApplication.Application.Selection.TypeParagraph();   
       }
       /// <SUMMARY></SUMMARY>   
       /// 插入一個圖片   
       ///    
       /// <PARAM name="pPictureFileName" />   
       public void InsertPicture(string pPictureFileName)   
       {   
           object myNothing = System.Reflection.Missing.Value;   
           //圖片置中顯示   
           this._wordApplication.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;   
           this._wordApplication.Application.Selection.InlineShapes.AddPicture(pPictureFileName, ref myNothing, ref myNothing, ref myNothing);   
       }
       /// <SUMMARY></SUMMARY>   
       /// 儲存檔案    
       ///    
       /// <PARAM name="pFileName" />儲存的檔案名稱   
       public void SaveWord(string pFileName)   
       {   
           object myNothing = System.Reflection.Missing.Value;   
           object myFileName = pFileName;   
           object myWordFormatDocument =Microsoft .Office .Interop .Word.WdSaveFormat.wdFormatDocument;   
           object myLockd = false;   
           object myPassword = "";   
           object myAddto = true;   
           try  
           {   
               this._wordDocument.SaveAs(ref myFileName, ref myWordFormatDocument, ref myLockd, ref myPassword, ref myAddto, ref myPassword,   
                   ref myLockd, ref myLockd, ref myLockd, ref myLockd, ref myNothing, ref myNothing, ref myNothing,    
                   ref myNothing, ref myNothing, ref myNothing);   
           }   
           catch  
           {   
               throw new Exception("匯出word文檔失敗!");   
           }   
       }   
   } 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.