Enter the following code in the Click event of the button, which enables you to write to the Excel file.
When you write Excel files, you also set permissions on the project folder, and you have writable permissions for iuser_machine users.
private void Button1_Click (object sender, System.EventArgs e)
{string Filename= "";
Excel.applicationclass oexcel;
oexcel = new Excel.applicationclass ();
oExcel.UserControl = false;
Excel.workbookclass WB = (excel.workbookclass) oExcel.Workbooks.Add (System.Reflection.Missing.Value);
for (int i = 1;i <= 5; i++)
{
Oexcel.cells[i,1]=i.tostring ();
oexcel.cells[i,2]= "' 2nd column";
oexcel.cells[i,3]= "' 3rd column";
oexcel.cells[i,4]= "' 4th column";
}
Wb. Saved = true;
Filename= Request.physicalapplicationpath + "Test.xls";
OExcel.ActiveWorkbook.SaveCopyAs (filename);
oExcel.Quit ();
System.GC.Collect ();
Response.Redirect (Request.applicationpath + "/test.xls");
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.