Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > C#.NET > 把DataGrid导出到excel
【标  题】:把DataGrid导出到excel
【关键字】:DataGrid,excel
【来  源】:http://blog.csdn.net/haipingma/archive/2006/09/21/1260510.aspx

把DataGrid导出到excel

Your Ad Here

btnExport is a BUTTON Control; DataGrid1 is a DataGrid Control

private void btnExportExcel_Click(object sender, System.EventArgs e) 

{

            HttpContext.Current.Response.Charset ="UTF-8";
            HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
            HttpContext.Current.Response.ContentType ="application/ms-excel";
            DataGrid1.Page.EnableViewState =false;

            System.IO.StringWriter  sw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
            DataGrid1.RenderControl(hw);
            HttpContext.Current.Response.Write(sw.ToString());
            HttpContext.Current.Response.End();

}

 导出到Excel,数字内容显示不正确

private void dgShow_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
         if(e.Item.ItemType  ==  ListItemType.Item  ||  e.Item.ItemType  ==  ListItemType.AlternatingItem)
         {
                e.Item.Cells[4].Attributes.Add("style","vnd.ms-excel.numberformat:@");

                .......
         }

  }

 

检查是否包含非法词语的正则:【上一篇】
调用消息对话框,并取得其返回值:【下一篇】
【相关文章】
  • 在DataGrid中利用CheckBox全选所有行
  • 请教个WIN里面的dataGrid问题
  • DataGridView中虚拟模式(Virtual Mode)的使用
  • 使用VSIUAL C#.NET操作Excel -把DataTable中的数据写入Excel
  • DataGrid中的数据导入到Word和Excel_C#
  • datagrid点删除,弹出一个确认和取消的消息框
  • 关于Asp.net中使用以下代码导出Excel表格的问题
  • HOW TO:利用Excel的QueryTable下载网上数据
  • DataGrid 控件 除了包含格式化指令外
  • 在EXCEL中插入内存中的图片(VSTO)
  • 【随机文章】
  • CWDM技术在城域网中的应用(6)
  • SQL数据操作基础(中级)  7
  • Linux内核入侵检测安全增强实现
  • 替代模型To Replace Models
  • 关于iBATIS的sqlmap的几点说明
  • Spring | JdbcTemplate & Mysql
  • vpnserver
  • /etc/inputrc 用来处理键盘映射表
  • JDOM操作XML文件--转载
  • VC6.0 中的__asm语句
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.