当前位置:软件学习 > Excel >>

NPOI 导出数据到Excel(包括图片)

RT,对于asp.net导出页面数据到Excel,图片一直是个问题,这里我把我的处理方法分享给大家,用第三方组件NPOI来实现,同时玩玩二维码生成。

首先,新建一个webApplication,添加NPOI引用,这里还要添加一个二维码的dll

 

 

 

添加引用之后,新建一个aspx页面,我取名为QrEncoderPage.aspx

前台页面html源码如下:


[html]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="QrEncoderPage.aspx.cs" 
    Inherits="WebQrCodeNet.QrEncoderPage" %> 
 
<!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></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
        <asp:GridView ID="gvCardList" runat="server" Width="100%" AutoGenerateColumns="False" 
            RowStyle-CssClass="DataAlign" OnRowCommand="gvCardList_RowCommand" Style="margin-top: 15px"> 
            <Columns> 
                <asp:BoundField DataField="CardCode" HeaderText="卡号" SortExpression="CardCode" ReadOnly="True" 
                    ControlStyle-CssClass="text"> 
                    <ControlStyle CssClass="text"></ControlStyle> 
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
                </asp:BoundField> 
                <asp:BoundField DataField="Password" HeaderText="密码" SortExpression="Password" ReadOnly="True" 
                    ControlStyle-CssClass="text"> 
                    <ControlStyle CssClass="text"></ControlStyle> 
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
                </asp:BoundField> 
                <asp:TemplateField ShowHeader="False"> 
                    <ItemTemplate> 
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandArgument='<%# Eval("CardCode") %>' 
                            Text="选择"></asp:LinkButton> 
                    </ItemTemplate> 
                </asp:TemplateField> 
            </Columns> 
            <RowStyle CssClass="GridViewRowStyle" /> 
            <SelectedRowStyle CssClass="GridViewSelectedRowStyle" /> 
            <PagerTemplate> 
            </PagerTemplate> 
            <AlternatingRowStyle CssClass="GridViewAlternatingRowStyle" /> 
            <HeaderStyle CssClass="GridViewHeaderStyle" /> 
        </asp:GridView> 
    </div> 
    <div> 
        <%-- 输入QR code内容: 
        <asp:TextBox ID="txtContent" runat="server"></asp:TextBox>--%> 
        <asp:Button ID="btnGenerateCode" runat="server" Text="生成二维码" OnClick="btnGenerateCode_Click" /> 
    </div> 
    </form> 
</body> 
</html> 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="QrEncoderPage.aspx.cs"
    Inherits="WebQrCodeNet.QrEncoderPage" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="gvCardList" runat="server" Width="100%" AutoGenerateColumns="False"
            RowStyle-CssClass="DataAlign" OnRowCommand="gvCardList_RowCommand" Style="margin-top: 15px">
            <Columns>
                <asp:BoundField DataField="CardCode" HeaderText="卡号" SortExpression="CardCode" ReadOnly="True"
                    ControlStyle-CssClass="text">
                    <ControlStyle CssClass="text"></ControlStyle>

补充:web前端 , HTML/CSS  ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,