gridview 打开 word,excel 生成,另存为word,excel
来源:互联网 发布:2017甘肃省网络研修 编辑:程序博客网 时间:2024/06/06 12:34
//前台页面 EnableEventValidation = "false" 必须有。。。。。。。。。。。。
<%@ Page Language="C#" MasterPageFile="~/Admin/Admin.Master" EnableEventValidation = "false" AutoEventWireup="true" CodeBehind="daochu.aspx.cs" Inherits="Maticsoft.Web.Admin.daochu" Title="无标题页" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Panel ID="Panel1" runat="server" Height="34px" Width="747px">
把账本表格导入到<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="excel">Excel</asp:ListItem>
<asp:ListItem Value="word">word</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="在线打开" CommandName="open" OnCommand="Button_Click"/>
<asp:Button ID="Button2" runat="server" Text="本地保存" CommandName="save" OnCommand="Button_Click"/></asp:Panel>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="noteid" ForeColor="#333333" GridLines="None" OnPageIndexChanging="DisplayNews_PageIndexChanging"
Width="800px" PageSize="50">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="noteid" HeaderText="编号" Visible="False" />
<asp:BoundField DataField="typename" HeaderText="消费类别">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="doc" HeaderText="消费详情">
<ItemStyle Width="500px" />
</asp:BoundField>
<asp:BoundField DataField="notetime" HeaderText="消费时间">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="notemoney" HeaderText="消费金额">
<ItemStyle Width="120px" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</asp:Content>
//后台页面 重写方法必须有 public override void VerifyRenderingInServerForm(Control control)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Maticsoft.Web.Admin
{
public partial class daochu : System.Web.UI.Page
{
Maticsoft.Model.Note mn = new Maticsoft.Model.Note();
Maticsoft.BLL.Note bn = new Maticsoft.BLL.Note();
protected void Page_Load(object sender, EventArgs e)
{
GRBind(Session["username"].ToString());
}
//导出表 到 Excel word
protected void Button_Click(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "save":
switch (DropDownList1.SelectedValue)
{
case "excel":
OutPut("attachment;filename=out.xls", "application/ms-excel");
break;
case "word":
OutPut("attachment;filename=out.doc", "application/ms-word");
break;
}
break;
case "open":
switch (DropDownList1.SelectedValue)
{
case "excel":
OutPut("online;filename=out.xls", "application/ms-excel");
break;
case "word":
OutPut("online;filename=out.doc", "application/ms-word");
break;
}
break;
}
}
private void OutPut(string fileType, string strType)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", fileType);
Response.ContentType = strType;
this.EnableViewState = false;
System.IO.StringWriter swOut = new System.IO.StringWriter();
HtmlTextWriter hTw = new HtmlTextWriter(swOut);
GridView1.RenderControl(hTw);
Response.Write(swOut.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void DisplayNews_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GRBind(Session["username"].ToString());
}
private void GRBind(string userName)
{
DataSet ds = new DataSet();
string strWhere = " Note.typeid = Type.typeid and Note.username = '" + userName + "' ";
ds = bn.GetList(strWhere);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
}
}
// 单个导出
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default8 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
string filename = "attachment;filename= 1.doc";
Response.AppendHeader("Content-Disposition", filename);
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.ContentType = "application/ms-word";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.GridView1.AllowPaging = false;
this.GridView1.RenderControl(oHtmlTextWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
}
- gridview 打开 word,excel 生成,另存为word,excel
- asp.net gridview 生成excel及word
- GridView导出Excel,Word
- GridView到处Excel/Word
- 简单实现网页另存为word或者excel
- GridView导出Excel与Word
- GridView导入到word Excel
- Intent打开ppt、word、Excel
- unity打开Excel/Word/PPT
- jsp 生成 word excel pdf
- freemaker生成word 和 excel
- freemarker生成word,excel工作总结
- Excel/Word
- GridView数据导出到Word/Excel中
- GridView导出到Excel或Word文件
- GridView导出到Excel或Word文件
- GridView导出到Excel或Word文件
- GridView导出到Excel或Word文件
- VC++2008 将控件变成XP样式
- django的安装及web部署
- ASSIGN的另外一种用法。
- 监测程序时候运行,没有启动
- Android多媒体框架初步分析
- gridview 打开 word,excel 生成,另存为word,excel
- 【z】浅谈C中的wprintf和宽字符显示
- VS 2008 中 UNICODE 工程下 CSTRING 转 CONST CHAR* 的最简便方法
- Linux启动时间的极限优化
- http服务向服务器发送并接受数据--------------HttpClient对象向服务器发送并接受数据
- 获取repeater中控件的值
- WH_KEYBOARD和WH_KEYBOARD_LL的区别
- WinCE下使用C#的几个小技巧
- FindFirstStore函数 按扇区读取Windows Mobile的数据