您的位置:首页 > 其它

excel转存pdf失败,报错

2015-07-01 12:34 381 查看
问题:Excel转存pdf失败,报错远程过程调用失败

转存方法:

public static bool XLSConvertToPDF(string sourcePath, string targetPath)

{

bool result = false;

Excel.XlFixedFormatType targetType = Excel.XlFixedFormatType.xlTypePDF;

object missing = Type.Missing;

Excel.ApplicationClass application = null;

Excel.Workbook workBook = null;

try

{

application = new Excel.ApplicationClass();

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

logger.Info("开始转换成pdf");

workBook.ExportAsFixedFormat(targetType, target, Excel.XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);

logger.Info("转换成pdf完成");

result = true;

}

catch (Exception e)

{

result = false;

logger.Error(e.Message, e);

}

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;

}

解决思路:代码调试没有问题,发布环境问题,调用com组件的权限设置

解决方法:控制面板-组件服务—我的电脑—属性—COM安全—编辑默认值 添加各种用户权限,主要是ASP用户
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: