最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
在ASP.NET中使用EXCEL之三 写Excel文件
时间:2008-01-12 编辑:简简单单 来源:一聚教程网
在按钮的click事件中输入如下代码,即可以实现写入Excel文件。
写Excel文件时,还要把项目文件夹的权限进行设置,对iuser_machine用户有可写的权限。
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]="'第2列";
oExcel.Cells[i,3]="'第3列";
oExcel.Cells[i,4]="'第4列";
}
wb.Saved = true;
filename= Request.PhysicalApplicationPath + "test.xls";
oExcel.ActiveWorkbook.SaveCopyAs(filename);
oExcel.Quit();
System.GC.Collect();
Response.Redirect( Request.ApplicationPath + "/test.xls");
}
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10