新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#創(chuàng)建Word文檔實例解析
C#創(chuàng)建Word文檔是我們經(jīng)常在實際開發(fā)應用中碰到的實用性開發(fā)實例,那么具體的實現(xiàn)過程是什么呢?我們下面通過一個C#創(chuàng)建Word文檔實例向你介紹具體的步驟。

C#創(chuàng)建Word文檔實例:
- using MSExcel = Microsoft.Office.Interop.Excel;
- using System.IO;
- using System.Refletion;
- //C#創(chuàng)建Word文檔
- Class Program
- {
- static void Main(string[] args)
- {
- string path; //C#創(chuàng)建Word文檔之文件路徑
- string strContent;//文本內(nèi)容
- MSWord.Application wordApp;提要
- //C#創(chuàng)建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#創(chuàng)建Word文檔
- }
C#創(chuàng)建Word文檔的基本內(nèi)容和實現(xiàn)實例就向你介紹到這里,希望對你了解和學習C#創(chuàng)建Word文檔有所幫助。
【編輯推薦】
- 詳解C#讀取word內(nèi)容操作
- C#讀取Word文件實例詳解
- C#讀取Word學習經(jīng)驗總結
- 淺析C#打開Word文檔實例
- 淺析C#Word文檔替換操作
本文名稱:C#創(chuàng)建Word文檔實例解析
轉(zhuǎn)載來源:http://www.dlmjj.cn/article/djehjop.html


咨詢
建站咨詢
