DataTable table = new DataTable();

StringWriter sw = new StringWriter();

string tabltitle = "客户名称,电话号码,导入时间,分组编号,透传号码,预测状态";//excel表头
sw.WriteLine(tabltitle);

foreach (DataRow dr in table.Rows)
{
string tempstr = dr[0].ToString().Replace(",", "-") + "," + dr[1].ToString().Replace(",", "-") + ",";
tempstr += dr[2].ToString().Replace(",", "-") + ",";
tempstr += dr[3].ToString().Replace(",", "-") + ",";
tempstr += dr[4].ToString().Replace(",", "-") + ",";
tempstr += dr[5].ToString().Replace(",", "-");
sw.WriteLine(tempstr);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=FORECASTInfoBackup.csv");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();

//ps:如果fileName是中文则需要 HttpUtility.UrlEncode(filename, Encoding.UTF8)转换下

导出Excel事例的更多相关文章

  1. JS导出excel 兼容ie、chrome、firefox

    运用js实现将页面中的table导出为excel文件,页面显示如下: 导出的excel文件显示如下: 实现代码: <!DOCTYPE html> <html> <head ...

  2. ASP.NETCore -----导出Excel文件并下载

    本事例分为nopi(安装DotNetCore.NPOI)下载和EPPlus(EPPlus.Core.dll)下载,其中npoi下载演示的是根据执行的模板进行数据下载 npoi帮助类NpoiExcelU ...

  3. C#使用Aspose.Cells导出Excel简单实现

    首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...

  4. 利用poi导出Excel

    import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.r ...

  5. [django]数据导出excel升级强化版(很强大!)

    不多说了,原理采用xlwt导出excel文件,所谓的强化版指的是实现在网页上选择一定条件导出对应的数据 之前我的博文出过这类文章,但只是实现导出数据,这次左思右想,再加上网上的搜索,终于找出方法实现条 ...

  6. NPOI导出Excel

    using System;using System.Collections.Generic;using System.Linq;using System.Text;#region NPOIusing ...

  7. ASP.NET Core 导入导出Excel xlsx 文件

    ASP.NET Core 使用EPPlus.Core导入导出Excel xlsx 文件,EPPlus.Core支持Excel 2007/2010 xlsx文件导入导出,可以运行在Windows, Li ...

  8. asp.net DataTable导出Excel 自定义列名

    1.添加引用NPOI.dll 2.cs文件头部添加 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.IO; 3.代码如 ...

  9. Aspose.Cells导出Excel(1)

    利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...

随机推荐

  1. 动态调用WebService 通用方法Moss 中 传统开发中都可用。

    WebService是啥大家都知道了,这里不做过多的解释.通常我们使用WebService的做法基本都是在我们的项目中添加Web引用的方式,首先找到WebService的地址,然后定义命名空间,这样会 ...

  2. linux产生静态库和动态库

    如何构建一个库 静态库(.a) 静态库的建立和使用是非常简单的: 1. 编译源文件:gcc -Wall -c test1.c test2.c 2. 生成库文件:ar -cvq libtest.a 3. ...

  3. hdu4587-TWO NODES(割点)

    #include <bits/stdc++.h> using namespace std; ; ; struct Edge { int to, next; } edge[M]; int h ...

  4. A Tour of Go Maps

    A map maps keys to values. Maps must be created with make (not new) before use; the nil map is empty ...

  5. hdu 4115 (2—SAT)

    题意:两个人石头剪刀布,一个人的出法已确定,另一个人的出法有一定约束,某两次要相同或者不同,问你第二个人能否全部都不失败. 思路:根据Bob出的情况,我们可以确定每次Alice有两种方案. R与P,S ...

  6. magento 列表页显示产品属性值的几种调用方式

    之前有人提到要在列表显示一些特定的属性,除了自带的名字,价格等.因为列表页和产品页都有一个同名的产品对象:$_product,而在产品页,$_product是直接可以用$_product->ge ...

  7. 最牛X的编码套路

    最近,我大量阅读了Steve Yegge的文章.其中有一篇叫"Practicing Programming"(练习编程),写成于2005年,读后令我惊讶不已: 与你所相信的恰恰相反 ...

  8. Java split用法

    Java split用法 java.lang.string.split split 方法  将一个字符串分割为子字符串,然后将结果作为字符串数组返回. stringObj.split([separat ...

  9. ThinkPHP3.2.3新特性之:数据库设置

    ThinkPHP3.2.3版本数据库驱动采用PDO完全重写,配置和使用上面也比之前版本更加灵活和强大,我们来了解下如何使用. 首先,3.2.3的数据库配置信息有所调整,完整的数据库设置包括: /* 数 ...

  10. [Practical Git] Switching between current branch and last checkout branch

    When working on a project, it is much easier to work on features and bugs in isolation of the rest o ...