Enter the following code in the click Event of the button to write the Excel file.
When writing an Excel file, you must set the permissions for the project folder to grant the iuser_machine user the write permission.
Private void button#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] = "'100 columns ";
OExcel. Cells [I, 3] = "3rd columns ";
OExcel. Cells [I, 4] = "'100 columns ";
}
Wb. Saved = true;
Filename = Request. PhysicalApplicationPath + "test.xls ";
OExcel. ActiveWorkbook. SaveCopyAs (filename );
OExcel. Quit ();
System. GC. Collect ();
Response. Redirect (Request. ApplicationPath + "/test.xls ");
}