c# - 在 iis 中托管时无法打开 excel 文件
问题描述
我有一个按钮,它在其中打开一个透视格式的 excel 文件,该文件与 localhost 完美配合,但是当我将它托管到 IIS 时出现问题,它会引发以下错误:
操作不可用(HRESULT 异常:0x800401E3 (MK_E_UNAVAILABLE))
我使用的代码是:
using (OleDbConnection conn = new OleDbConnection("Provider=MSOLAP;Data Source=" + DS + ";Initial Catalog=" + Initial_Catalog + ";user id=" + (string)(Session["name"]) + ";password=" + (string)(Session["password"]) + ";"))
{
string connection = @"OLEDB;Provider=MSOLAP;Data Source=" + DS + ";Initial Catalog=" + Initial_Catalog + ";user id=" + (string)(Session["name"]) + ";password=" + (string)(Session["password"]) + ";";
conn.Open();
//Create a command, using this connection
//AdomdCommand cmd = conn.CreateCommand();
Microsoft.Office.Interop.Excel.Application app;
app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wkbk = (Microsoft.Office.Interop.Excel.Workbook)app.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel.Worksheet sheet = (Excel.Worksheet)(wkbk.ActiveSheet);
Microsoft.Office.Interop.Excel.Application objAplicacion;
objAplicacion = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
//wkbk.Open(sheet);
Microsoft.Office.Interop.Excel.PivotCache pivotCache;
pivotCache = wkbk.PivotCaches().Add(Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlExternal, Type.Missing);
//pivotCache.CommandText = "Lempo_Test1";
pivotCache.Connection = connection;
pivotCache.MaintainConnection = true;
pivotCache.CommandText = "Lempo";
pivotCache.CommandType = Microsoft.Office.Interop.Excel.XlCmdType.xlCmdCube;
// Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)objAplicacion.ActiveSheet;
Microsoft.Office.Interop.Excel.PivotTables pivotTables = (Microsoft.Office.Interop.Excel.PivotTables)sheet.PivotTables(Type.Missing);
Microsoft.Office.Interop.Excel.PivotTable pivotTable = pivotTables.Add(pivotCache, sheet.Cells[1, 1], "PivotTable1", true, Type.Missing);
pivotTable.SmallGrid = false;
pivotTable.ShowTableStyleRowStripes = true;
pivotTable.TableStyle2 = "PivotStyleLight1";
app.ScreenUpdating = true;
app.DisplayAlerts = true;
app.Visible = true;
app.UserControl = true;
app.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMaximized;
// Response.Redirect("Board.aspx");
}
请帮我解决这个错误
解决方案
推荐阅读
- python - 为什么不能在条件语句的代码中排除 LCM 变量?
- reactjs - 盖茨比网站的 Netlify“build.command”失败
- python - 图像地图热点中的条件语句?
- javascript - jquery没有按名称捕获输入选择器
- javascript - setTimeout 立即执行,而不是函数调用中传递的时间
- python - 如何使用 FFT 从图像中去除重复模式
- gem5 - 链接 X86/marshal 文件时的 LTO 编译问题
- parameters - 我可以以某种方式将 TInput/TOutput 页面作为 Inno Setup 中的一个参数传递给函数吗?
- python - 优化具有二进制变量的对称 MIP 的 Gurobi 模型 (PuLP)
- python - 提交表单的修改字段时出错