最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net生成csv文件代码
时间:2022-06-25 06:05:29 编辑:袖梨 来源:一聚教程网
using system.web;
public class sdsavecsv
{
///
/// 构造函数
///
/// httpresponse对象
public sdsavecsv(httpresponse response)
{
this.response = response;
}
///
/// 输入出文件
///
/// 文件名称
/// 文件内容
///成功/失败
public bool outfile(string fullpath, string content)
{
bool retvalue = false;
try
{
this.response.buffer = true;
this.response.clear();
this.response.charset = system.text.encoding.default.bodyname;
this.response.contentencoding = system.text.encoding.getencoding("gb2312");//gb2312用excel打开时,没有乱码。
this.response.appendheader("content-disposition", "attachment;filename=" + fullpath);
this.response.contenttype = "application/ms-excel";
this.response.output.write(content);
this.response.flush();
this.response.end();
retvalue = true;
}
catch (exception ex)
{
retvalue = false;
throw new applicationexception(string.format("输出数据csv出错:{0}",fullpath), ex);
}
return retvalue;
}
}
//===============================以下为调用方法
stringbuilder sbfile = new stringbuilder();
sbfile.append("商户,蛋名称,蛋id,时间,累计领蛋人数,累计发蛋量");
sbfile.appendline();//换行
foreach (datarow row in ds.tables[0].rows)
{
sbfile.appendformat("{0},{1},{2},{3},{4},{5}", eggmerchants1.merchantname, row["eggname"], row["rowid"], row["date"], row["pep"], row["num"]);
sbfile.appendline();
}
new sdsavecsv(this.response).outfile(string.format("fetchegg({0}).csv",datetime.now), sbfile.tostring());
相关文章
- 胜利女神战前整备面板详解 战斗队伍组建技巧 07-01
- ps怎么给人物嘴唇添加立体效果? 07-01
- 分析:币圈MA移动平均线参数如何设置?如何运用MA辅助分析? 07-01
- 无畏契约手游爆破模式怎么玩 核心玩法技能解析 07-01
- 根据XRP历史上的抛售阶段分析,分析师预测火箭式上涨至9.5美元或37.5美元 07-01
- 和平精英爆裂萌兔技能是什么 爆裂萌兔技能介绍 07-01