GridView导出Excel方法

全志A527 T527 android13支持usb摄像头 我们发现usb摄像头在A527 android13上面并不能正常使用,需要支持相关的摄像头。 阅读详情

GridView导出Excel方法
一、引用如下命名空间
using System.IO;
using System.Text;
二、详细代码

方法一:将代码直接写在页面


    /// <summary>
    /// 数据导出
    /// </summary>
    /// <param name="FileType"></param>
    /// <param name="FileName"></param>
    private void Export(string FileType, string FileName)
    {
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF8;//注意编码
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        gridGatewayDetails.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }

方法二、将以上代码改进成公共方法:


    /// <summary>
    /// 将网格数据导出到Excel
    /// </summary>
    /// <param name="ctrl">网格名称(如GridView1)</param>
    /// <param name="FileType">要导出的文件类型(Excel:application/ms-excel)</param>
    /// <param name="FileName">要保存的文件名</param>
    public static void GridViewToExcel(Control ctrl, string FileType, string FileName)
    {
        HttpContext.Current.Response.Charset = "GB2312";
        HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;//注意编码
        HttpContext.Current.Response.AppendHeader("Content-Disposition",
            "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
        HttpContext.Current.Response.ContentType = FileType;//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
        ctrl.Page.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        ctrl.RenderControl(hw);
        HttpContext.Current.Response.Write(tw.ToString());
        HttpContext.Current.Response.End();
    }

 

三、注意事项:

 

在导出的时候,如果某个字段为长数字(如身份证号码511922198507151512)、以0开头的编号(如0809111212)之类的数据。如果不加处理在导出的Excel文件中将会被分别当作5.11922E+17和809111212来处理,这样与我们要达到 的实际效果不一致。所以我们要加以处理,即给单元格数据规定格式。常见的格式如下:

1) 文本:vnd.ms-excel.numberformat:@
2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
3) 数字:vnd.ms-excel.numberformat:#,##0.00
4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
5) 百分比:vnd.ms-excel.numberformat: #0.00%

使用方法如下:

//给第一个单元格设置格式为

e.Item.Cells[0].Attributes.Add("style","vnd.ms-excel.numberformat:@");

//给第四个单元格设置格式为
e.Item.Cells[3].Attributes.Add("style","vnd.ms-excel.numberformat:¥#,###.00");

redhawk:GSC file与STA file redhawk做lowpower分析时需要GSC(Global Switching Configuration)file指导block/instance/power domain的开关状态。 Syntax(in GSR file): GSC_FILES <gsc_FilePathName> Syntax(in GSC file) [<blockName> | <instanceName>] ?<domain_name> ? <state1&gt 阅读详情

相关推荐

手把手教你用西门子博图V18配置阿特拉斯PF6000拧紧枪PN通讯(附完整GSD文件与ToolsTalk配置文件)

本文详细介绍了如何使用西门子博图V18配置阿特拉斯PF6000拧紧枪的PN通讯,包括硬件连接、网络参数规划、ToolsTalk软件配置及博图工程设置。通过完整的GSD文件和配置文件,帮助工程师快速实现高精度拧紧设备与PLC的高效通讯,适用于汽车装配和电子制造等工业自动化场景。

weixin_42662293的博客 626

C#DataGridview数据导出至excel两个方法

C#DataGridview数据导出至excel两个方法

HXD196的博客 3798

内网环境下的高德地图离线化实战:从瓦片下载到交互功能集成

本文详细介绍了在内网环境中部署离线高德地图的完整实战方案。针对军工、能源、金融等对网络隔离与数据安全有严格要求的场景,文章核心解决了离线地图的两大基石:地图瓦片数据的高效下载与本地化,以及高德地图JS API的获取与插件集成。通过具体代码示例,进一步讲解了如何实现地图初始化、海量点标注与聚合、自定义图标及框选查询等核心交互功能,并分享了内网部署的路径配置、性能优化及法律合规等关键注意事项,为开发者在封闭网络环境下构建稳定、可控的地图应用提供了清晰指南。

Apple的专栏 401

【无标题】c#——将gridview中的数据导出Excel

将gridview中的数据导出excel ,打开文件

m0_54035969的博客 574

SikuliX实战:5分钟搞定游戏挂机脚本(附防检测思路与Python集成技巧)

本文详细介绍了如何使用SikuliX快速开发游戏挂机脚本,包括环境配置、基础原理、防检测策略及Python集成技巧。通过实战案例展示如何实现自动化任务、高级防检测方案,并结合Python提升脚本性能与智能度,帮助玩家高效完成重复性游戏操作。

weixin_33228769的博客 345

Python与西门子PLC数据交互实战:基于Snap7的跨平台工业通信指南

本文详细介绍了如何使用Python和Snap7库实现与西门子PLC的数据交互。内容涵盖跨平台环境搭建、连接参数配置、数据读写实战及性能优化技巧,为工业自动化、数据采集和智能制造场景提供了一套轻量、灵活且高效的通信解决方案。

vim8coder的博客 307

将GridView的内容导出到Excel中

原文来自:http://gridviewguy.com/ArticleDetails.aspx?articleID=197 介绍: 将GridView的内容导出到Excel是很普通的应用,在很多网站上都有使用。有各种不同的技术来实现GridView导出到Excel中,主要是看应用程序的具体情况。在本文中我将演示一些你会觉得有用的技巧。 从GridView导出到Exc...

QAZ135000的博客 561

RoboDK 自定义机器人

本文介绍了如何在RoboDK中自定义机器人模型的方法。主要内容包括:1)通过CAD软件处理3D模型后导入RoboDK,使用分割工具简化模型结构;2)配置机器人的DH参数和关节运动范围;3)验证机器人运动效果后导出.robot文件。该方法可使自制机器人获得与ABB等商用机器人相同的仿真和控制功能。文章详细说明了模型处理、参数设置和验证的完整流程,为机器人开发者提供了实用的技术指导。

zhbi98 的技术 Blogs 2671

C# | 导出DataGridView中的数据到Excel、CSV、TXT

导出中的数据到是开发中经常遇到的需求。而将DataGridView中的数据先转换为DataTable格式,再进行导出,是一种常见的实现方式。本文将介绍如何将DataGridView中的数据转换为DataTable格式,并提供将DataTable转换为Excel、CSV、TXT三种格式的例子。将DataGridView中的数据转换为DataTable格式,有助于我们更方便地对数据进行处理和操作。

猿长大人 7362

8、多导睡眠图记录中基于级联自适应滤波器的脑电图信号噪声去除

本文提出了一种基于三级级联自适应滤波器的新型方法,用于去除多导睡眠图(PSG)记录中脑电图(EEG)信号的常见伪迹,包括50/60 Hz电源线干扰、心电图(ECG)和眼电图(EOG)伪迹。该方法采用最小均方(LMS)算法,通过分阶段滤波有效分离并衰减各类噪声,在保留EEG关键神经节律信息的同时显著提升信号质量。研究利用MIT-BIH数据库中的18份真实PSG记录进行验证,结果表明该方法具有无相位失真、实现简单、自适应能力强等优势,适用于睡眠研究及脑机接口等生物医学应用领域。

banana的博客 176

华为OD机试双机位C卷-简单的解压缩算法(C/C++/Py/Java/Js/Go)

华为OD机试(机考)双机位C卷 【简单的解压缩算法】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD真题【简单的解压缩算法】。

qq_45776114的博客 484

从GridView导出到Excel

1.由于gridview的内容可能是分页显示的,因此,这里在每次导出excel时,先将gridview的allowpaging属性设置为false,然后databind()一下,确保搂到所有数据;2.不用单独设置导出的路径,导出时会弹出对话框让你确认保存位置;3.要写一个空的VerifyRenderingInServerForm方法(必须写),以确认在运行时为指定的ASP.NET 服务器控件呈现H

樟树下的专栏 2885

MFC实现键盘钩子(附完整源码)

MFC实现键盘钩子(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 402

在ASP.NET中GridView导出Excel的快速方法

此方法最有效,所以贴出来与大家分享 protected void btnOutExcel_Click(object sender, EventArgs e) { if (GridView1.Rows.Count > 0) { //调用导出方法 Ex

邱征响的专栏 8638

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

gridview导出html,Gridview导出Excel方法

方法一:前台:后台:protected void Button1_Click(object sender, EventArgs e){toExecl(GridView1);}// 将GridView数据导出到EXECLprivate void toExecl(System.Web.UI.WebControls.GridView gv){Response.Clear();Response.Buffe...

weixin_39744606的博客 302

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

GridView导出Excel方法源码以及注意事项

 public void ExortExcel() //从GridView中导出Excel的函数    {        if (this.Gv.Rows.Count != 0)        {            HttpContext.Current.Response.Clear();            HttpContext.Current.Response.AddHeader("c

hongjiaoli的专栏 2129

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

从GRIDVIEW中导出EXCEL的方法

将GridView的内容导出到Excel是很普通的应用,在很多网站上都有使用。有各种不同的技术来实现GridView导出到Excel中,主要是看应用程序的具体情况。在本文中我将演示一些你会觉得有用的技巧。从GridView导出到Excel(基础代码)    让我们从基础的导出方法开始。首先,我们需要用一些数据填充GridView。我创建了一个自定义的数据表,它包含了多个字段。你可以在下面的

未来~ 2392

自己总结的手动生成gridview导出excel的方法

首先添加函数: public override void VerifyRenderingInServerForm(Control control) { // Confirms that an HtmlForm control is rendered for } protected void btnExcel_Click(object sender...

diecai1469的博客 126

使用RenderControl方法把GridView控件导出到EXCEL

//  把GridView输出到Excel文件         private void ExportExcel(GridView gridView, string title, string title2, string fileName)         {             int nHideCols = 0;             //如果不想输出出某列,将Visible

Kevin yan的专栏 1584

Gridview导出Excel方法

方法一: 前台: <asp:Button ID="btnExcel" runat="server" Text="导出Excel" /> 后...

weixin_33911824的博客 271

GridView中的数据导出到Excel方法(经测试完整)

GridView中的数据导出到Excel方法(经测试完整) protected void Button2_Click(object sender, EventArgs e)    {        if (this.GridView1.Rows.Count == 0)        {            Response.Write("alert(没有查找到数据,无法导出!)");  

liuhuan2099的专栏 1774

C# .NET关于GridView和ASPxGridView导出Excel表格的解决方法

GridView导出Excel 1.前端页面代码: <asp:Button ID="Button4" runat="server" Text="导出Excel" OnClick="ExcelClick" Height="22px" Width="82px" /> <asp:GridView ID="GridView1" runat="server" AutoGenerateC...

有趣技术 1008

html gridview excel,ASP.NET使用GridView导出Excel实现方法

本文实例讲述了ASP.NET使用GridView导出Excel实现方法。分享给大家供大家参考。具体实现方法如下:/// /// 将DataTable数据导出到EXCEL,调用该方法后自动返回可下载的文件流/// /// 要导出的数据源public static void DataTable1Excel(System.Data.DataTable dtData){System.Web.UI.WebC...

weixin_39710462的博客 299

带分页功能的GridView导出Excel或Word的方法

#region 导出Excel按钮功能实现 protected void BtnOutput_Click(object sender, EventArgs e) { Export("application/ms-excel", "盘点结果表.xls");//调用导出方法 } #endregion #region 导出Excel方法

DreamFly 4136

GridView/DataGrid导出成Excel文件的万能解决方法

 [原创] GridView[DataGrid]导出成Excel文件的万能解决方法 GridView[DataGrid]导出成Excel文件在Dot.Net使用群中是个很大的问题了,随便一搜,都会搜出一大堆的。而好多实现要依赖于Office软件自带的ActiveX,基于ActiveX的实现,必然会出现"Dll Hell"的问题,所以并不可取。 最好的方法是保持原来Web页面原样,而且不依赖于O

3057

gridview数据源导出到EXCEL的方法

protectedvoidPage_Load(objectsender,EventArgse) {  if(!Page.IsPostBack)  {   BindData();  } } privatevoidBindData() {  stringquery=/"SELECT*FROMcustomers/";  SqlConnectionmyConnection=newSqlConnection

秦半两的专栏 636
上一篇: 元素不是已经元素,原因可能是网站存在编译错误
下一篇: 使用AJAX时在系统处理的时候显示进度条(图片)
suchgoingdown
博客等级 码龄19年 4粉丝 21原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值