.net web端导出Excel个人的看法
//对已有方法进行重写
public override void VerifyRenderingInServerForm(Control control)
{ }
//设置文件名
string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
//HTTP请求内容
System.Web.HttpContext curContext = System.Web.HttpContext.Current;
// 输出文件流
System.IO.StringWriter strWriter = null;
//服务端控件输出流
System.Web.UI.HtmlTextWriter htmlWriter = null;
// 清空当前 Response
HttpContext.Current.Response.Clear();
//设置缓冲方式输出
HttpContext.Current.Response.Buffer = true;
//添加HTTP标头到输出流
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.xls", fileName));
curContext.Response.ContentType = "application/vnd.ms-excel"; //设置输出文件类型为xls文件
/**如果要输出doc文件,请用下面这段代码**/
//HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.doc", fileName));
//curContext.Response.ContentType = "application/ms-word"; //设置输出文件类型为word文件
//设置编码方式
curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
curContext.Response.Charset = "";
// 导出文件
strWriter = new System.IO.StringWriter();
htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
htmlWriter.Write("测试标题1");
//for (int i = 0; i < ds.Columns.Count; i++)
//{
// htmlWriter.Write(ds.Columns[i].Caption.ToString());
//}
//
// 返回客户端
// DataList1.RenderControl
GridView1.RenderControl(htmlWriter);
curContext.Response.Write(strWriter.ToString().Replace("<br/>", "<br style='mso-data-placement:same-cell;'/> "));
curContext.Response.End();
//设置文件名
string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
//HTTP请求内容
System.Web.HttpContext curContext = System.Web.HttpContext.Current;
// 输出文件流
System.IO.StringWriter strWriter = null;
//服务端控件输出流
System.Web.UI.HtmlTextWriter htmlWriter = null;
// 清空当前 Response
HttpContext.Current.Response.Clear();
//设置缓冲方式输出
HttpContext.Current.Response.Buffer = true;
//添加HTTP标头到输出流
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.xls", fileName));
curContext.Response.ContentType = "application/vnd.ms-excel"; //设置输出文件类型为xls文件
/**如果要输出doc文件,请用下面这段代码**/
//HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.doc", fileName));
//curContext.Response.ContentType = "application/ms-word"; //设置输出文件类型为word文件
//设置编码方式
curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
curContext.Response.Charset = "";
// 导出文件
strWriter = new System.IO.StringWriter();
htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
htmlWriter.Write("测试标题1");
//for (int i = 0; i < ds.Columns.Count; i++)
//{
// htmlWriter.Write(ds.Columns[i].Caption.ToString());
//}
//
// 返回客户端
GridView1.RenderControl(htmlWriter);
curContext.Response.Write(strWriter.ToString().Replace("<br/>", "<br style='mso-data-placement:same-cell;'/> "));
curContext.Response.End();
.net web端导出Excel个人的看法的更多相关文章
- fastadmin 随笔 刷新表格数据 获取当前登录人信息 服务端导出Excel
table.bootstrapTable('refresh',{url:'你的url'}); 获取当前登录人信息 $this->auth就能获取当前用户信息,比如$this->auth-& ...
- JDE报表开发笔记(Client端导出Excel乱码)
之前导出Excel时没发生任何问题, Client端PL/SQL字符集为UTF-8 Oracle JDE E910字符集为UTF-8 解决方式:添加指定用户的字符集(上图即为修改后的用户字符集) 角色 ...
- 64位系统web项目导出excel问题分析及解决方法汇总
最近在web项目中做了一个导出Excel功能.在导出的时候报错:检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败. 一 ...
- Web C# 导出Excel 方法总结
方法1:微软推荐服务器需安装Excel型 依赖: 软件:Office Excel 2007-2013 引用:Microsoft Office 14.0 Object Library 1.1 数据准备 ...
- Web端导出CSV
前端导出文件大部分还是通过服务器端的方式生成文件,然后传递到客户端.但很多情况下当我们导出CSV时并不需要后端参与,甚至没有后端. 做过WebGIS的同学经常会碰到这种场景,用户的兴趣点数据以csv文 ...
- 前端导出Excel兼容写法
今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ...
- uniapp导入导出Excel
众所周知,uniapp作为跨端利器,有诸多限制,其中之一便是vue页面不支持传统网页的dom.bom.blob等对象. 所以,百度上那些所谓的导入导出excel的方法,大部分都用不了,比如xlsx那个 ...
- (ssh整合web导出excel)在ssh框架中使用poi正确导出具有比较高级固定格式的excel 整体过程,查询导出前后台下载
(一) 接需求 : 需求相关 (贴图 ) 生成三核对文件 1.新增三核对菜单页面中,增加生成三核对文件功能按钮,弹窗可根据变电站.电压等级查询定值单. 2.定值单信息以表格形式展示,根据选择 ...
- 浏览器端JS导出EXCEL
浏览器端JS导出EXCEL FileSaver.js 实现了在本身不支持 HTML5 W3C saveAs() FileSaver 接口的浏览器支持文件保存.FileSaver.js 在客户端保存文件 ...
随机推荐
- Sql语句复习
1.两张表A,B 其中A表中字段1,字段2,字段3要迁移到B表中字段4,字段5,字段6,迁移后B表的字段7 全赋值为123: insert into B(字段4,字段5,字段6,字段7) select ...
- ADO总结测试数据库
create database ADO测试 go use ADO测试 go create table Student ( Code ) not null primary key,--学生编号,主键 N ...
- 关于/usr/local/lib/libz.a(zutil.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC解决办法
具体报错截图如下: 解决方法: 题外话,我对makefill cmake也是一窍不通因此本人也是不想去积极的解决这个问题,但是当你求助无缘的时候你才会静心去思考.读到这句话的时候也许你已经发现了问题所 ...
- 数据表格datagrid内容整理
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- codeforces problem 140E New Year Garland
排列组合题 题意 用m种颜色的彩球装点n层的圣诞树.圣诞树的第i层恰由l[i]个彩球串成一行,且同一层内的相邻彩球颜色不同,同时相邻两层所使用彩球的颜色集合不同.求有多少种装点方案,答案对p取模. 只 ...
- 【初级】linux pwd 命令详解及使用方法实战
pwd:查看当前工作目录 前言: Linux中用 pwd 命令来查看”当前工作目录“的完整路径,就是经常提及的所在目录,多用在生产环境多级目录中查看当前所在路径,使用此命令能给运维人员/操作人员带来很 ...
- learn python, ref, diveintopython 分类: python 2015-07-22 14:42 14人阅读 评论(0) 收藏
for notes of learing python. // just ignore the ugly/wrong highlight for python code. ""&q ...
- curl获取远程图片存到本地
$url = 'http://sssss/sss/xu0fLo9waqKSTDO7j0kSO41O5Luq3LB6ozUvY4O7OsXUWNicB49fBs8nGYzoqcwGDARQZHpVuic ...
- 高精度快速预览打开dwg文件的CAD控件CAD Image DLL介绍及下载
CAD Image DLL对于DXF格式, DWG格式(AutoCAD R12 到AutoCAD 2004/2005), PLT 以及 HPGL/HPGL2文件都有快速的显示速度和精度,开发者再也不会 ...
- Bootstrap 模态框在用户点击背景空白处时会自动关闭
问题: Bootstrap 模态框在用户点击背景空白处时,会自动关闭. 解决方法: 在HTML页面中编写模态框时,在div初始化时添加属性 aria-hidden=”true” data-backdr ...