部署.net C#MVC应用程序后保存/打开文件时出错
在我的MVC应用程序中,我使用Microsoft.Office.Interop.excel将数据导出到excel 我还启用了ASP.NET模拟,并给出了身份验证详细信息。它将数据写入excel,但不保存或打开excel文件。它从HRESULT:0x800A03EC引发异常部署.net C#MVC应用程序后保存/打开文件时出错,c#,asp.net-mvc,excel,C#,Asp.net Mvc,Excel,在我的MVC应用程序中,我使用Microsoft.Office.Interop.excel将数据导出到excel 我还启用了ASP.NET模拟,并给出了身份验证详细信息。它将数据写入excel,但不保存或打开excel文件。它从HRESULT:0x800A03EC引发异常异常。如果有人能帮忙,我将非常高兴。提前谢谢 我的出口代码是: public static void ExportExcel(this DataTable Tbl, string ExcelFilePath = null)
异常。如果有人能帮忙,我将非常高兴。提前谢谢
我的出口代码是:
public static void ExportExcel(this DataTable Tbl, string ExcelFilePath = null)
{
ExcelFilePath = "ExportTable.xls";
try
{
if (Tbl == null || Tbl.Columns.Count == 0)
//throw new Exception("ExportToExcel: Null or empty input table!\n");
Console.WriteLine("ExportToExcel: Null or empty input table!\n");
// load excel, and create a new workbook
Excel.Application excelApp = new Excel.Application();
excelApp.Workbooks.Add();
// single worksheet
Excel._Worksheet workSheet = excelApp.ActiveSheet;
// column headings
for (int i = 0; i < Tbl.Columns.Count; i++)
{
workSheet.Cells[1, (i + 1)] = Tbl.Columns[i].ColumnName;
workSheet.Cells[1, (i + 1)].Font.Bold = true;
workSheet.Cells[1, (i + 1)].Font.Size = 12;
}
// rows
for (int i = 0; i < Tbl.Rows.Count; i++)
{
// to do: format datetime values before printing
for (int j = 0; j < Tbl.Columns.Count; j++)
{
workSheet.Cells[(i + 2), (j + 1)] = Tbl.Rows[i][j];
}
}
// works fine till here
// check fielpath
if (ExcelFilePath != null && ExcelFilePath != "")
{
try
{
workSheet.SaveAs(ExcelFilePath);
excelApp.Quit();
}
catch (Exception ex)
{
Console.WriteLine("ExportToExcel: Excel file could not be saved! Check filepath.\n"+ ex.Message);
}
}
else // no filepath is given
{
excelApp.Visible = true;
}
}
catch (Exception ex)
{
Console.WriteLine("ExportToExcel: \n" + ex.Message);
}
公共静态void ExportExcel(此数据表Tbl,字符串ExcelFilePath=null)
{
ExcelFilePath=“ExportTable.xls”;
尝试
{
if(Tbl==null | | Tbl.Columns.Count==0)
//抛出新异常(“ExportToExcel:Null或空输入表!\n”);
Console.WriteLine(“ExportToExcel:Null或空输入表!\n”);
//加载excel,并创建新工作簿
Excel.Application excelApp=新的Excel.Application();
excelApp.Workbooks.Add();
//单一工作表
Excel.\u工作表工作表=excelApp.ActiveSheet;
//列标题
对于(int i=0;i
}IIS用户帐户必须具有写入文件的权限
在下面的文章中搜索0x800A03EC,HRESULT:0x800A03EC是一个未知的(VB.Net)COM错误。当Excel因为输入或参数错误而抛出错误时,通常会发生这种情况。如果您在Excel VBA中尝试您的代码,通常会更容易解决问题