【发布时间】:2012-11-15 10:16:06
【问题描述】:
我正在使用此代码在客户端机器上创建一个 excel 文件,同时按下 asp.net 中的按钮
protected void excldwnlbtn4_Click(object sender, EventArgs e)
{
write_on_excel("Vendor.xls");
lblmsg4.Text = "File Downloaded";
}
而创建excel文件的代码是:
public void write_on_excel(string filepath)
{
Excel.ApplicationClass excelApp = new Excel.ApplicationClass();
try
{
Excel.Workbook workbook = (Excel.Workbook)excelApp.Workbooks.Add(Missing.Value);
Excel.Worksheet worksheet;
//// Opening excel file
//workbook = excelApp.Workbooks.Open(filepath, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
workbook.SaveAs(filepath,
Excel.XlFileFormat.xlExcel5, Missing.Value, Missing.Value,
false, false, Excel.XlSaveAsAccessMode.xlNoChange,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
// Get first Worksheet
worksheet = (Excel.Worksheet)workbook.Sheets.get_Item(1);
// Setting cell values
((Excel.Range)worksheet.Cells[1, "A"]).Value2 = "Vendor Code";
((Excel.Range)worksheet.Cells[1, "B"]).Value2 = "Vendor Password";
((Excel.Range)worksheet.Cells[1, "C"]).Value2 = "Vendor Name";
workbook.Save();
workbook.Close(0, 0, 0);
}
catch (Exception)
{
lblmsg4.Text = "File not Downloaded!!";
}
finally
{
excelApp.Quit();
}
}
现在它在我的 IIS localhost 中工作正常 .. 我在硬盘驱动器中获得了一个带有这些列标题的空 excel 文件....但是当我将它托管在服务器中并使其生效时,我无法创建excel文件...我收到一个错误:
Server Error in '/' Application.
The resource cannot be found.
我该怎么办??我的错在哪里?请帮我解决这个问题
【问题讨论】:
-
您的服务器上安装了 Excel 吗? (顺便说一句,以这种方式创建 Excel 文件是个坏主意,但那是另一回事......)
-
我买了一个域名...所以我认为他们应该有 excel
-
服务器上是否安装了 MS Excel?您可以询问他们的支持人员是否已安装。您是否允许将文件保存在您指定的文件夹中?
-
你能举例说明如何创建一个excel文件吗?我只知道这个
-
@ArindamDas:你买了一个域,所以他们应该有 Excel?我没有看到联系。根据这个答案,我想我们可以得出结论,您的服务器上没有安装 Excel,因此您进行的 Excel 互操作调用只会失败。
标签: c# asp.net excel export-to-excel