• ExceL转PDF


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Excel = Microsoft.Office.Interop.Excel;
    namespace ExcelToPdfDemo
    {
    class Program
    {
    static void Main(string[] args)
    {
    try
    {
    string path = @"C:\aa.xls";
    string path2 = @"C:\cc.pdf";
    XLSConvertToPDF(path,path2);
    Console.WriteLine("转换成功!");
    Console.ReadKey();
    }
    catch (Exception)
    {
    
    throw;
    }
    
    }
    ///<summary>
    /// 把Excel文件转换成PDF格式文件
    ///</summary>
    ///<param name="sourcePath">源文件路径</param>
    ///<param name="targetPath">目标文件路径</param> 
    ///<returns>true=转换成功</returns>
    private static bool XLSConvertToPDF(string sourcePath, string targetPath)
    {
    bool result = false;
    Excel.XlFixedFormatType targetType = Excel.XlFixedFormatType.xlTypePDF;
    object missing = Type.Missing;
    Excel.Application application = null;
    Excel.Workbook workBook = null;
    try
    {
    application = new Excel.Application();
    object target = targetPath;
    object type = targetType;
    workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
    missing, missing, missing, missing, missing, missing, missing, missing, missing);
    
    workBook.ExportAsFixedFormat(targetType, target, Excel.XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
    result = true;
    }
    catch
    {
    result = false;
    }
    finally
    {
    if (workBook != null)
    {
    workBook.Close(true, missing, missing);
    workBook = null;
    }
    if (application != null)
    {
    application.Quit();
    application = null;
    }
    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();
    GC.WaitForPendingFinalizers();
    }
    return result;
    }
    
    
    }
    }
  • 相关阅读:
    JMeter压力测试入门教程[图文]
    从技术转管理的困惑
    APP纯黑盒测试—某些可以试试的操作
    测试网站访问速度的方法(GTmetrix)
    【转】web测试技术经典案例(基础、全面)
    【转】H5页面的测试点总结
    【转】测试思考之——思想有多远,你就能走多远
    【转】测试趋势之我的观点
    线程学习一
    继承log4.net的类
  • 原文地址:https://www.cnblogs.com/527289276qq/p/4313214.html
Copyright © 2020-2023  润新知