无为清净楼资源网 Design By www.qnjia.com

本文实例讲述了asp.net+Ligerui实现grid导出Excel和Word的方法。分享给大家供大家参考,具体如下:

下面采用的导EXCEL方法,适合不翻页的grid,而且无需再读一次数据库,对于翻页的grid来说,要导全部,当然后台要再读一次数据库,这种导EXCEL方法baidu一大堆,这里不重复

代码部分:

grid.htm:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title></title>
  <link href="../lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
  <link href="../lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
  <script src="/UploadFiles/2021-04-02/jquery-1.3.2.min.js">

导出页面print.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="print.aspx.cs" Inherits="example" EnableEventValidation = "false" ValidateRequest="false" %>
<html>
<head>
  <title></title>
  <link href="../lib/ligerUI/skins/aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
  <script src="/UploadFiles/2021-04-02/jquery-1.3.2.min.js">

print.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace service
{
  public partial class print : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
      }
    }
    void exportexcel()
    {
      Response.Clear();
      Response.Buffer = true;
      Response.Charset = "utf-8";
      Response.AppendHeader("Content-Disposition", "attachment;filename=tmp.xls");
      Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
      Response.ContentType = "application/ms-excel";
      this.EnableViewState = false;
      System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
      System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
      oHtmlTextWriter.WriteLine(hf.Value);
      Response.Write(oStringWriter.ToString());
      Response.End();
    }
    void exportword()
    {
      Response.Clear();
      Response.Buffer = true;
      Response.Charset = "utf-8";
      Response.AppendHeader("Content-Disposition", "attachment;filename=tmp.doc");
      Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
      Response.ContentType = "application/ms-word";
      this.EnableViewState = false;
      System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
      System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
      oHtmlTextWriter.WriteLine(hf.Value);
      Response.Write(oStringWriter.ToString());
      Response.End();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      exportexcel();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
      exportword();
    }
  }
}

原理:在点导出按钮的时候,弹一个print.aspx页面,这个页面把grid的html传给自己一个叫hf的hidden里面,然后后台response输出这个html

更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net文件操作技巧汇总》、《asp.net ajax技巧总结专题》及《asp.net缓存操作技巧总结》。

希望本文所述对大家asp.net程序设计有所帮助。

标签:
asp.net,Ligerui,grid,导出Excel,导出Word

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。