//把Excel文档转换为Pdf文档 #region private static void ExcelToPdf(string ExcelFileName, string PdfFileName) { //Object missing = System.Reflection.Missing.Value; //Object ReadOnly = (object)true; //ET.Application app = new ET.Application(); //app.Visible = false; //ET.workbook doc = (ET.workbook)app.Workbooks.Open(ExcelFileName, missing, ReadOnly, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); //doc.ExportPdf(PdfFileName, "", ""); //doc.Close(missing, missing, missing); //app.Quit(); //System.Runtime.InteropServices.Marshal.ReleaseComObject(app); //app = null; Object missing = System.Reflection.Missing.Value; Object ReadOnly = (object)true; Excel.Application app = new Excel.Application(); app.Visible = false; Excel.Workbook doc = (Excel.Workbook)app.Workbooks.Open(ExcelFileName, missing, ReadOnly, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); doc.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, PdfFileName); doc.Close(missing, missing, missing); app.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(app); app = null; }
private Boolean xls_exec(OfficeDomain office) { Boolean result = false; if (Array.IndexOf(xls, office.prefix) > -1) { log("excel开始工作..."); Excel.Workbook workbook = null; try { //参数含义:路径、只读 workbook = excelApp.Workbooks.Open(office.path, 0, true); //转换 workbook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, office.pdfFileName); result = true; log("excel工作完毕,准备关闭文件.."); } catch (Exception e) { error("excel工作异常:{0}", e.Message); } finally { if (workbook != null) { try { workbook.Close(); log("excel文件成功关闭.."); } catch (Exception e) { error("excel文件关闭时发生错误{1},重启{0}.exe", xls_name, e.Message); xls_start(); } } } } return(result); }