GridView数据在Excel中导出 [英] Gridview data Export in excel

查看:82
本文介绍了GridView数据在Excel中导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

对于在网格视图中绑定的导出数据,我还有另一个问题.

我在网格视图中有很多列,某些绑定字段是visible= false.

当我想在Excel中导出数据时,我也想导出BouldField值,这是hide.

这是我的gridview.

Hello Friends,

I have another problem for export data which is bind in grid view.

I have many column in grid view ans some Bound Field is visible= false.

When I want to export data in Excel I also want to export BouldField value which is hide.

Here is my gridview.

<asp:GridView ID="GrdOrder" runat="server" AutoGenerateColumns="false"

                            AllowPaging="true" AllowSorting="true" PageSize="20"

                            DataKeyNames="OrderID" CssClass="Grid"

                            onpageindexchanging="GrdOrder_PageIndexChanging"

                            onselectedindexchanged="GrdOrder_SelectedIndexChanged">
                        <Columns>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    <input type="checkbox" name="SelectAllCheckBox" onclick="SelectAll(this)" />
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:CheckBox ID="ChkOrderId" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Order No" DataField="OrderID" />
                            <asp:BoundField HeaderText="Order Date" DataField="OrderDate" DataFormatString="{0:dd-MMM-yyyy}" />
                            <asp:BoundField HeaderText="Customer Name" DataField="ShippingCustomerName" />
                            <asp:BoundField HeaderText="Order Status" DataField="OrderStatus" />
                            <asp:BoundField HeaderText="Bill Address" DataField="BillngAddress" />
                            <asp:CommandField ShowSelectButton="true" ButtonType="Image" SelectImageUrl="images/details.png" HeaderText="More Details"/>
                        </Columns>
                        <FooterStyle />
                        <SelectedRowStyle />
                        <PagerStyle CssClass="GridPager" />
                        <HeaderStyle CssClass="HeaderProduct" />
                    </asp:GridView>



这是一些用于隐藏字段的导出代码.



Hhere is some code for export that hide field.

GrdOrder.HeaderRow.Cells[0].Visible = false;
        GrdOrder.HeaderRow.Cells[5].Visible = true;

        //Temp Code
        for (int i = 0; i < GrdOrder.Rows.Count; i++)
        {
            GridViewRow rw = GrdOrder.Rows[i];
            rw.Visible = true;
            GrdOrder.Columns[5].Visible = true;
            rw.Cells[0].Visible = false;
            rw.Cells[5].Visible = true;
        }

        for (int i = 0; i < GrdOrder.HeaderRow.Cells.Count; i++)
        {
            //GrdOrder.HeaderRow.Cells[i].Style.Add("background-color", "#E4E4E4");
            //GrdOrder.HeaderRow.Cells[i].Style.Add("color", "#444");
            GrdOrder.HeaderRow.Cells[i].Style.Add("font-size", "12pt");
            GrdOrder.HeaderRow.Cells[i].Style.Add("text-decoration", "bold");
            GrdOrder.Style.Add("font-family", "Verdana;");
            GrdOrder.Style.Add("font-size", "12pt");
            //GrdOrder.Style.Add("color", "Black");
        }


可以帮助我. !!!


Can help me for that. !!!

推荐答案

我建​​议使用Sql Reporting服务导出到excel/打印功能.您可以选择rdlc的客户端报告,因为它在客户端具有数据,因此更适合您.

谢谢
Rohit
I would recommend to use Sql Reporting services to export to excel / print functionality. You can choose client reporting which is rdlc which would be more suitable for you as you have data on client side.

Thanks
Rohit


尝试一下
将数据表导出为具有C#格式的Excel [ ^ ]
try this
Export DataTable to Excel with Formatting in C#[^]


这篇关于GridView数据在Excel中导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆