导出Excel事例
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事例的更多相关文章
- JS导出excel 兼容ie、chrome、firefox
运用js实现将页面中的table导出为excel文件,页面显示如下: 导出的excel文件显示如下: 实现代码: <!DOCTYPE html> <html> <head ...
- ASP.NETCore -----导出Excel文件并下载
本事例分为nopi(安装DotNetCore.NPOI)下载和EPPlus(EPPlus.Core.dll)下载,其中npoi下载演示的是根据执行的模板进行数据下载 npoi帮助类NpoiExcelU ...
- C#使用Aspose.Cells导出Excel简单实现
首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...
- 利用poi导出Excel
import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.r ...
- [django]数据导出excel升级强化版(很强大!)
不多说了,原理采用xlwt导出excel文件,所谓的强化版指的是实现在网页上选择一定条件导出对应的数据 之前我的博文出过这类文章,但只是实现导出数据,这次左思右想,再加上网上的搜索,终于找出方法实现条 ...
- NPOI导出Excel
using System;using System.Collections.Generic;using System.Linq;using System.Text;#region NPOIusing ...
- ASP.NET Core 导入导出Excel xlsx 文件
ASP.NET Core 使用EPPlus.Core导入导出Excel xlsx 文件,EPPlus.Core支持Excel 2007/2010 xlsx文件导入导出,可以运行在Windows, Li ...
- asp.net DataTable导出Excel 自定义列名
1.添加引用NPOI.dll 2.cs文件头部添加 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.IO; 3.代码如 ...
- Aspose.Cells导出Excel(1)
利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...
随机推荐
- Redhat常见问题
1.现象:hadoop用户启动startx时失败,报如下提示 Fatal server error: PAM authentication failed, cannot start X server. ...
- 怎么创建MongoDB数据库
MongoDB didn’t provides any command to create “database“. Actually, you don’t need to create it manu ...
- android 链接蓝牙不稳定的解决建议
My workaround I scan BLE for a short period of time 3-4 seconds then I turn scan OFF for 3-4 seconds ...
- 如何使用 SPICE client (virt-viewer) 来连接远程虚拟机桌面?
如何使用 SPICE client (virt-viewer) 来连接远程虚拟机桌面? 什么是SPICE? SPICE (Simple Protocol for Independent Computi ...
- CSS modules 与 React中实践
最近一直在学习React,看上去蛮简单的内容,其实学习曲线还是比较高的. 目前学到css绑定的问题,看到有一篇好的文章,就转过来了. CSS 模块化的解决方案有很多,但主要有两类.一类是彻底抛弃 CS ...
- 利用Microsoft Azure Machine Learning Studio创建机器学习实例
Microsoft Azure云服务推出机器学习的模块,用户只需上传数据,利用机器学习模块提供的一些算法接口和R语言或别的语言接口,就能利用Microsoft Azure强大的云计算能力来实现自己的机 ...
- linux安装oracle
目 录 一.硬件要求二.软件三.系统安装注意四.安装Oracle前的系统准备工作五.安装Oracle,并进行相关设置六.升级Oracle到patchset 10.2.0.4七.使用rlwrap调用sq ...
- ModSecurity--web应用防火墙
Introducing ModSecurity IIS 2.7.2 Stable Release ★★★★★ ★★★★ ★★★ ★★ ★ swiatFebruary 11, 20130 0 0 0 ...
- NSThead
每个iOS应用程序都有个专门用来更新显示UI界面.处理用户的触摸事件的主线程,因此不能将其他太耗时的操作放在主线程中执行,不然会造成主线程堵塞(出现卡机现象),带来极坏的用户体验.一般的解决方案就是将 ...
- SharePoint 2013+ Sqlserver 2014 Kerberos 配置传奇, 最终的解决方案 验证。
SharePoint 2013+ Sqlserver 2014 Kerberos 配置传奇. 1,安装数据库,我就不多说安装,客户一定要注意. 我将参照以下实施例和账户. 2,建立DNS,假设没有DN ...