excel转存pdf失败,报错

  问题: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用户

猜你喜欢

转载自blog.csdn.net/kuangdang178/article/details/46708889
今日推荐