c# 异常System.Runtime.InteropServices.COMException hresult 0x800a03ec

rzhtc 2015-12-03 03:52:16
如下代码 运行到红色那句就异常 System.Runtime.InteropServices.COMException hresult 0x800a03ec,球解
private string ExcelToPdf(object excelFileName)
{
try
{
KillExcel();
//在此处放置用户代码以初始化页面
Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application();
Type excelsType = Excel.GetType();
Microsoft.Office.Interop.Excel.Workbooks excels = Excel.Workbooks;
//打开文件
Type xlssType = excels.GetType();
Microsoft.Office.Interop.Excel.Workbook xls = (Microsoft.Office.Interop.Excel.Workbook)xlssType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, excels, new Object[] { excelFileName, true, true });
//转换格式,另存为
Type xlsType = xls.GetType();
string excelSaveFileName = excelFileName.ToString();
string strSaveFileName = excelSaveFileName.Substring(0, excelSaveFileName.Length - 3) + "pdf";
object saveFileName = (object)strSaveFileName;
xls.SaveAs(saveFileName, Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF);
//xlsType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, xls, new object[] { saveFileName, Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF });
xlsType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, xls, null);
//退出 Word
excelsType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, excels, null);
return saveFileName.ToString();
}
catch (Exception ex)
{
KillExcel();
throw ex;
}
}
...全文
518 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
slwsss 2015-12-03
  • 打赏
  • 举报
回复
itextsharp

8,327

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 IIS
社区管理员
  • IIS
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧