zoukankan      html  css  js  c++  java
  • 用Word写博客园文章

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

    效果如下:

    啦啦啦啦啦啦我是卖报的小行家

    /// <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;

    #endregion

    #region转换

    try

    {

    //打开word

    wordDocument = wordApplication.Documents.Open(ref wordPath, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, 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

    {

    //关闭

    if (wordDocument != null)

    {

    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;

    #endregion

    }

  • 相关阅读:
    分享一个js方法
    微信小程序中如何使用setData修改数组或对象中的某一参数
    微信小程序实现图片上传功能
    微信小程序图片上传放大预览删除代码
    小程序单张图片 和 九宫格图片上传、预览、删除示例
    微信小程序多图上传/朋友圈传图效果【附完整源码】
    shell 和awk性能对比
    超实用的8个Linux命令行性能监测工具
    storm分组模式
    Python程序的执行原理(转)
  • 原文地址:https://www.cnblogs.com/dunitian/p/5041062.html
Copyright © 2011-2022 走看看