我正在使用此代码在客户端机器上创建一个 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.
我该怎么办??我的错在哪里?请帮助我