C#創(chuàng)建Word文檔實(shí)例解析
作者:changjiangzhibin
C#創(chuàng)建Word文檔的具體實(shí)現(xiàn)是怎么樣子的呢?C#創(chuàng)建Word文檔需要用到什么方法呢?那么本文就向你介紹具體的實(shí)例實(shí)現(xiàn),希望對你的學(xué)習(xí)有所幫助。
C#創(chuàng)建Word文檔是我們經(jīng)常在實(shí)際開發(fā)應(yīng)用中碰到的實(shí)用性開發(fā)實(shí)例,那么具體的實(shí)現(xiàn)過程是什么呢?我們下面通過一個C#創(chuàng)建Word文檔實(shí)例向你介紹具體的步驟。
C#創(chuàng)建Word文檔實(shí)例:
- 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應(yīng)用程序
- 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)容和實(shí)現(xiàn)實(shí)例就向你介紹到這里,希望對你了解和學(xué)習(xí)C#創(chuàng)建Word文檔有所幫助。
【編輯推薦】
責(zé)任編輯:仲衡
來源:
CSDN博客