GridView導出Excel
1.aspx頁面需要添加:EnableEventValidation="false"
實例:<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="DefCheckDate.aspx.cs"
Inherits="WebAdmin_CustomRegister_ShortOverFlow_DefCheckDate" %>
2.後台代碼(實例):
public void btn_ExcelClick(object sender, EventArgs e)
{
if (Gdv_Sof.Rows.Count <= 0)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript'>alert('沒有數據!')</script>");
return;
}
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=CheckDate.xls");
Response.ContentType="application/excel";
Response.Charset = "Big5";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("Big5");
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
Gdv_Sof.Columns[0].Visible = false;
Gdv_Sof.Columns[1].Visible = false;
Gdv_Sof.HeaderRow.Controls.Clear();
Gdv_Sof.AllowPaging = false;
Gdv_Sof.AllowSorting = false;
BindGridView();
Gdv_Sof.RenderControl(htw);
Response.Write(sw);
Response.End();
Gdv_Sof.AllowPaging = true;
Gdv_Sof.AllowSorting = true;
BindGridView();
}
//此方法一定要有VerifyRenderingInServerForm
public override void VerifyRenderingInServerForm(Control control)
{
}
3.導出的數據格式設置:例如頁面為005,可是導出卻為5,就需要添加以下樣式vnd.ms-excel.numberFormat:@");
實例:
protected void Gdv_Sof_RowDateBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberFormat:@");
e.Row.Cells[4].Attributes.Add("style", "vnd.ms-excel.numberFormat:@");
}
}
GridView導出Excel的更多相关文章
- GridView導出Excel 解決亂碼問題
Response.Clear(); Response.Charset = "gb2312"; Response.Buffer = true; Response.AddHeader( ...
- C# gridview分頁導出excel
#region 导出Excel方法 //导出到Excel按钮 protected void btnExport_Click(object sender, EventArgs e) { Export(& ...
- C#根據當前DataGridView查詢數據導出Excel
private void btnsuggestinfo_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.C ...
- 導出Excel方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- Saiku更改導出文件的文件名(十九)
Saiku更改導出文件的文件名 Saiku查询完数据之后,可以以excel,pdf,csv等格式将数据导出,这里我们来讲一下怎么更改导出的文件名. 找到对应的导出方法所在的js文件: saiku-se ...
- asp.net教程:GridView导出到Excel或Word文件
asp.net教程:GridView导出到Excel或Word文件</ br> 在项目中我们经常会遇到要求将一些数据导出成Excel或者Word表格的情况,比如中国移动(我是中国移动用户) ...
- DevExpress GridControl GridView 导出到 Excel 类
说明: 1>GridView 导出到 Excel (如果分页,只导出当前页数据) 2>GridView 导出到 Excel 3>方法2可以参考DataTable 导出到 Excel ...
- 【asp.net】将GridView数据导出Excel
概要: 中午睡了一会,醒来的时候看到老师叫我去办公室,需求是这样的,把excel表中的每个同学,判断图片目录中是否有对应的照片(图片的名字用的学号或身份证号码) 没有对应图片的学生记录,存入自己的数据 ...
- GridView导出成Excel字符"0"丢失/数字丢失的处理方式 收藏
GridView导出成Excel字符"0"丢失/数字丢失的处理方式 收藏 GridView 导出成Excel文件,这个代码在网上比较多.但是发现存在一个问题,导出的数据中如果有&q ...
随机推荐
- PHP中对数据库操作的封装
在动态网面设计中很多都要涉及到对数据库的操作,但是有时跟据需要而改用其它后台数据库,就需要大量修改程序.这是一件枯燥.费时而且容易出错的功作.其实我们可以用PHP中的类来实现对数据库操作的封装,从而使 ...
- android:screenOrientation的说明 固定屏幕显示方向
Activity在屏幕当中显示的方向.属性值可以是下表中列出的一个值: "unspecified" 默认值,由系统来选择方向.它的使用策略,以及由于选择时特定的上下文环境,可能会因 ...
- [2014-03-13 08:46:42 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace. 问题提示 ...
- hibernate自动生成映射文件
映射文件是O/R Mapping的关键,相当于控制中心.当数据库表较多时,手动配置该映射文件非常耗时.为了快速开发程序,使开发人员的注意力集中到业务逻辑上来,Hibernate官方提供的MiddleG ...
- Codeforces Beta Round #97 (Div. 1)
B 判矩阵的时候 出了点错 根据点积判垂直 叉积判平行 面积不能为0 #include <iostream> #include<cstdio> #include<cstr ...
- 【Todo】Java Queue Stack Vector ArrayList
Java集合框架里存在Queue这个接口,之后有不同类型的队列的实现. 有Stack这个类实现堆栈,其实这个类是通过继承Vector的方式来实现的, Vector和ArrayList的实现方式差不多, ...
- 使用jQuery插件PrintArea进行html页面打印
在开发系统时,我们一般会有统计分析的功能需求,而现在大多数系统都是使用B/S的形式开发. 所以,html报表打印,并且打印指定内容,成了必要的功能. 开源地址:https://github.com/R ...
- POJ 1944 - Fiber Communications
原题地址:http://poj.org/problem?id=1944 题目大意:有n个点排成一圈,可以连接任意两个相邻的点,给出 p 对点,要求这 p 对点必须直接或间接相连,求最少的连接边数 数据 ...
- 如何在linux中从源代码编译安装nodejs?
$ sudo yum groupinstall 'Development Tools'安装开发环境$ wget https://nodejs.org/dist/v0.12.2/node-v0.12.2 ...
- npm和bower
npm用于管理node.js 的backend依赖模块:这些模块以node的require来调用 bower用于管理frontend的js依赖模块,这些模块用<script src=" ...