天天看點

用Word寫部落格園文章

用Word寫部落格園文章
用Word寫部落格園文章
用Word寫部落格園文章

http://www.cnblogs.com/dunitian/services/metablogapi.aspx

用Word寫部落格園文章
用Word寫部落格園文章
用Word寫部落格園文章
用Word寫部落格園文章

效果如下:

啦啦啦啦啦啦我是賣報的小行家

用Word寫部落格園文章

/// <summary>

/// Word轉換成PDF

/// </summary>

/// <param name="inputPath">載入路徑</param>

/// <param name="outputPath">儲存路徑</param>

/// <param name="startPage">初始頁碼(預設為第一頁[0])</param>

/// <param name="endPage">結束頁碼(預設為最後一頁)</param>

public static bool WordToPDF(string inputPath, string outputPath, int startPage =0, int endPage = 0)

{

bool b = true;

#region初始化

//初始化一個application

Application wordApplication = new Application();

//初始化一個document

Document wordDocument = null;

#endregion

#region參數設定~~我去累死寶寶了~~

//word路徑

object wordPath = Path.GetFullPath(inputPath);

//輸出路徑

string pdfPath = Path.GetFullPath(outputPath);

//導出格式為PDF

WdExportFormat wdExportFormat = WdExportFormat.wdExportFormatPDF;

//導出大檔案

WdExportOptimizeFor wdExportOptimizeFor =WdExportOptimizeFor.wdExportOptimizeForPrint;

//導出整個文檔

WdExportRange wdExportRange = WdExportRange.wdExportAllDocument;

//開始頁碼

int startIndex = startPage;

//結束頁碼

int endIndex = endPage;

//導出不帶标記的文檔(這個可以改)

WdExportItem wdExportItem = WdExportItem.wdExportDocumentContent;

//包含word屬性

bool includeDocProps = true;

//導出書簽

WdExportCreateBookmarks paramCreateBookmarks =WdExportCreateBookmarks.wdExportCreateWordBookmarks;

//預設值

object paramMissing = Type.Missing;

#region轉換

try

//打開word

wordDocument = wordApplication.Documents.Open(ref wordPath, ref paramMissing, refparamMissing, ref paramMissing, ref paramMissing, ref paramMissing, refparamMissing, ref paramMissing, ref paramMissing, ref paramMissing, refparamMissing, ref paramMissing, ref paramMissing, ref paramMissing, refparamMissing, ref paramMissing);

//轉換成指定格式

if (wordDocument != null)

wordDocument.ExportAsFixedFormat(pdfPath, wdExportFormat, false, wdExportOptimizeFor, wdExportRange, startIndex, endIndex, wdExportItem, includeDocProps, true, paramCreateBookmarks, true, true, false, ref paramMissing);

}

catch (Exception ex)

b = false;

finally

//關閉

wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);

wordDocument = null;

//退出

if (wordApplication != null)

wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);

wordApplication = null;

return b;

本文轉自毒逆天部落格園部落格,原文連結:http://www.cnblogs.com/dunitian/p/5041062.html,如需轉載請自行聯系原作者

繼續閱讀