我正在尝试使用ASP.Net Web应用程序中的以下代码创建一个excel文件 当我从visual studio运行时,代码正常工作,但当我在IIS上部署应用程序并运行已部署的版本时,会出现 workbook.Close 命令异常。
Excel.Application exc = null;
try
{
exc = new Excel.Application();
Excel.Workbooks workbooks = exc.Workbooks;
Excel._Workbook workbook = workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel._Worksheet worksheet = (Excel._Worksheet)workbook.Worksheets[1];
Excel.Range range = worksheet.get_Range("A1", System.Reflection.Missing.Value);
Object[] data = new Object[] { "" };
range.GetType().InvokeMember("Value", System.Reflection.BindingFlags.SetProperty, null, range, data);
workbook.Close(true, p_sTempFileName, null);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\n" + ex.InnerException);
Console.ReadLine();
}
finally
{
if (exc != null)
exc.Quit();
}
答案 0 :(得分:1)
答案 1 :(得分:0)
在代码中:
Range rng = (Excel.Range)worksheet.get_Range((object)worksheet.Cells[1, 1], (object)worksheet.Cells[3,3])