C#創建Word文檔實例解析
作者:changjiangzhibin
C#創建Word文檔的具體實現是怎么樣子的呢?C#創建Word文檔需要用到什么方法呢?那么本文就向你介紹具體的實例實現,希望對你的學習有所幫助。
C#創建Word文檔是我們經常在實際開發應用中碰到的實用性開發實例,那么具體的實現過程是什么呢?我們下面通過一個C#創建Word文檔實例向你介紹具體的步驟。
C#創建Word文檔實例:
- using MSExcel = Microsoft.Office.Interop.Excel;
- using System.IO;
- using System.Refletion;
- //C#創建Word文檔
- Class Program
- {
- static void Main(string[] args)
- {
- string path; //C#創建Word文檔之文件路徑
- string strContent;//文本內容
- MSWord.Application wordApp;提要
- //C#創建Word文檔之word應用程序
- MSWord.document wordDoc;//word文檔
- path = @"c:\test.docx";
- wordApp = new MSWord.applicationClass();
- if(File.Exists(path))
- {
- File.Delete(path);
- }
- Object nothing = Missing.Value;
- wordDoc = wordApp.Documents.Add(
- ref nothing,ref nothing,ref nothing,ref nothing);
- strContent = "你好!\n";
- wordDoc.Paragraphs.Last.Rang.Text = strContent;
- object format = MSWord.WdSaveFormat.wdFormatDocumentDefault;
- wordDoc.SaveAs(ref path,ref format,
- 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);
- wordDoc.Close(ref nothing,ref nothing,ref nothing);
- wordApp.Quit(ref nothing,ref nothing,ref nothing);
- }
- //C#創建Word文檔
- }
C#創建Word文檔的基本內容和實現實例就向你介紹到這里,希望對你了解和學習C#創建Word文檔有所幫助。
【編輯推薦】
責任編輯:仲衡
來源:
CSDN博客