Tips:将Excel转换为PDF文件(含“值不在范围”异常处理方法)
将Excel转换成PDF格式:
using MsExcel = Microsoft.Office.Interop.Excel;
object missing = System.Reflection.Missing.Value; //打开Excel文件 MsExcel.Workbook wb = appc.Application.Workbooks.Open( fielPath, missing, false, missing, missing, missing, missing, missing, missing, true, missing, missing, missing, missing, missing); MsExcel.XlFixedFormatType targetType = MsExcel.XlFixedFormatType.xlTypePDF;
string target = @"E:\Test.pdf"; wb.ExportAsFixedFormat(targetType, target, MsExcel.XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
以上可能在方法wb.ExportAsFixedFormat()发生"值不在范围错误"..
解决方法如下:
安装office2007的插件OfficeSaveAsPDFandXPS
下载地址:点击跳转