Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)归海一刀
published in(发表于) 2014/1/30 1:35:16
将GridView内容导出到Excel或Word中_[Asp.Net教程]

将GridView内容导出到Excel或Word中_[Asp.Net教程]

前台页面:



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExportDemo.aspx.cs" Inherits="ExportDemo" %>

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 runat="server">
<title>GridView导出到Excel或Word文件——周公的博客:http://blog.csdn.nettitle>
head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvPersonList" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Id" HeaderText="编号" />
<asp:BoundField DataField="Name" HeaderText="姓名" />
<asp:TemplateField HeaderText="性别">
<ItemTemplate>
<%# Eval("Sex").ToString()=="true"?"":"" %>
ItemTemplate>
asp:TemplateField>
<asp:BoundField DataField="Age" HeaderText="年龄" />
<asp:TemplateField HeaderText="婚否">
<ItemTemplate>
<%# Boolean.Parse(Eval("Married").ToString())==true?"":"" %>
ItemTemplate>
asp:TemplateField>
Columns>
asp:GridView>
<asp:Button ID="btnToExcel" runat="server" OnClick="btnToExcel_Click" Text="导出到Excel" />
<asp:Button ID="btnToWord" runat="server" OnClick="btnToWord_Click" Text="导出到Word" />
div>
form>
body>
html>



If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759