导出excel
来源:互联网 发布:dj是什么意思网络用语 编辑:程序博客网 时间:2024/06/06 06:54
asp.net里导出excel表方法汇总
1、由dataset生成
2、使用微软的C++写的ACTIVEX控件:http://download.microsoft.com/download/OfficeXPDev/sample/1.0/WIN98MeXP/EN-US/Dsoframerctl.exe
3、由datagrid生成:
用法:ToExcel(datagrid1);
4、这个用dataview ,代码好长
----------------------------------------------------------------
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]); 对方法一,二补充一点,如果你希望导出的是xls文件分隔符用\t就能了,不要用逗号 代码修改如下: ---------------------------------项目实践--yx--- ------------
SqlDataAdapter da=new SqlDataAdapter("select * from tb1",conn);
DataSet ds=new DataSet();
da.Fill(ds,"table1");
DataTable dt=ds.Tables["table1"];
StringWriter sw=new StringWriter();
sw.WriteLine("自动编号,姓名,年龄");
foreach(DataRow dr in dt.Rows)
{
sw.WriteLine(dr["ID"]+","+dr["vName"]+","+dr["iAge"]);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=test.csv");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();
sw.WriteLine("自动编号\t姓名\t年龄");
foreach(DataRow dr in dt.Rows)
{
sw.WriteLine(dr["ID"]+"\t"+dr["vName"]+"\t"+dr["iAge"]);
}
另外,修改输出的文件扩展名为xls即可。
- 导出EXCEL
- Excel导出
- 导出Excel
- 导出EXCEL
- 导出Excel
- EXCEL导出
- 导出Excel
- 导出excel
- 导出excel
- EXCEL导出
- 导出excel
- 导出Excel
- Excel导出。
- 导出excel
- Excel 导出
- 导出excel
- 导出excel
- 导出excel
- xcode 高版本sdk编译适合低版本sdk的设置
- js文本替换(高亮效果)
- All threads (200) are currently busy解决方案
- COM组件的内部流程简介
- sql中 in 、not in 、exists、not exists 用法和差别
- 导出excel
- Linux I2C核心、总线与设备驱动
- [DBA手记]IMP-00093错误的解决方法
- IE8提示找不到元素
- AS3和JavaScript的通讯
- SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
- 【mysql】数据库目录
- eclipse启动tomcat程序错误处理
- android特效