This is a migrated thread and some comments may be shown as answers.

Export to excel

2 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nithya Rani
Top achievements
Rank 1
Nithya Rani asked on 12 Jan 2012, 06:36 AM
Hi

While i was exporting the radgrid to excel and work export tool bar is also including. i want to avoid the export toolbar in excel sheet.
While i was using ExportOnlyData="true" that is not including. But in my case i have used linkbutton in the grid so if i use ExportOnlyData="true" link button value is also not including. Any other way to avoid export tool bar in excel.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Jan 2012, 06:52 AM
Hello Nithya,

You can set ExportOnlyData property as true to avoid toolbar. While exporting, you can add the column containing link button as shown below.
C#:
grid.MasterTableView.GetColumn("UniqueName").Visible = true;

-Shinu.
0
Nithya Rani
Top achievements
Rank 1
answered on 12 Jan 2012, 07:08 AM
Hi Shinu,

I have tried that. but its not working.
I have tried in ExportCellFormatting and GridExporting method but its not working.

please find the code bellow
.aspx page
<telerik:RadGrid ID="RadGrid_InvAdjus" runat="server" AllowPaging="True" AllowSorting="True"
                        GridLines="Both" EnableLinqExpressions="false" Width="100%" AutoGenerateEditColumn="false"
                        AutoGenerateColumns="False" OnPageIndexChanged="RadGrid_InvAdjus_PageIndexChanged"
                        Visible="false" OnItemCommand="RadGrid_InvAdjus_ItemCommand" OnExcelExportCellFormatting="RadGrid_InvAdjus_ExportCellFormatting"
                        OnNeedDataSource="RadGrid_InvAdjus_NeedDataSource"
                        ongridexporting="RadGrid_InvAdjus_GridExporting">
                        <PagerStyle Mode="NextPrevAndNumeric" />
                        <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true"
                            HideStructureColumns="true" FileName="Inventory Adjustment">
                        </ExportSettings>
                        <MasterTableView AllowPaging="true" CommandItemDisplay="Top" GridLines="Both">
                            <CommandItemSettings ShowExportToPdfButton="true" ShowExportToWordButton="true" ShowExportToExcelButton="true"
                                ShowAddNewRecordButton="false" ShowRefreshButton="false" ShowExportToCsvButton="false" />
                            <Columns>
                                <telerik:GridDateTimeColumn DataType="System.DateTime" HeaderText="Date" UniqueName="Date"
                                    ItemStyle-HorizontalAlign="Left" DataField="DATETIME" DataFormatString="<%$Appsettings:dateformat%>">
                                    <ItemStyle Width="10%" />
                                    <HeaderStyle Width="10%" />
                                </telerik:GridDateTimeColumn>
                                <telerik:GridTemplateColumn HeaderText="Product" UniqueName="Product" DataField="PROD_ID"
                                    ItemStyle-HorizontalAlign="Left" SortExpression="PROD_ID">
                                    <ItemStyle Width="10%" />
                                    <HeaderStyle Width="10%" />
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lnkprodNum" runat="server" OnClick="lnkprodNum_Click" ForeColor="DarkBlue"
                                            Text='<%# DataBinder.Eval (Container.DataItem, "PRODUCT_CODE") %>' ValidationGroup='<%# DataBinder.Eval (Container.DataItem, "PROD_ID") %>'>
                                        </asp:LinkButton>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn HeaderText="Description" UniqueName="Description" DataField="PROD_DESC"
                                    ItemStyle-HorizontalAlign="Left">
                                    <ItemStyle Width="20%" />
                                    <HeaderStyle Width="20%" />
                                </telerik:GridBoundColumn>
                                <telerik:GridCalculatedColumn HeaderText="Qty" UniqueName="qty" ItemStyle-HorizontalAlign="Right"
                                    Aggregate="Sum" DataFields="QTTY, PACKSHORT_DESC" Expression='{0}+ " " +{1}'>
                                    <ItemStyle Width="10%" />
                                    <HeaderStyle Width="10%" />
                                </telerik:GridCalculatedColumn>
                                <telerik:GridBoundColumn HeaderText="Lot" UniqueName="lot" DataField="LOT_CODE" ItemStyle-HorizontalAlign="Left">
                                    <ItemStyle Width="20%" />
                                    <HeaderStyle Width="20%" />
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn HeaderText="Order No." UniqueName="Order_No." DataField="ORDER_NO"
                                    ItemStyle-HorizontalAlign="Left" SortExpression="ORDER_NO">
                                    <ItemStyle Width="10%" />
                                    <HeaderStyle Width="10%" />
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lnkOrdNum" runat="server" OnClick="lnkrefNum_Click" ForeColor="DarkBlue"
                                            CommandArgument='<%# DataBinder.Eval (Container.DataItem, "ORDER_NO2") %>' Text='<%# DataBinder.Eval (Container.DataItem, "ORDER_NO") %>'
                                            ValidationGroup='<%# DataBinder.Eval (Container.DataItem, "SRORDER_ID") %>'>
                                        </asp:LinkButton>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn HeaderText="Reference No" UniqueName="Reference_No" DataField="ORDER_NO2"
                                    ItemStyle-HorizontalAlign="Left">
                                    <ItemStyle Width="10%" />
                                    <HeaderStyle Width="10%" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Warehouse" UniqueName="Warehouse" ItemStyle-HorizontalAlign="Left"
                                    DataField="WAREHOUSE_CODE">
                                    <ItemStyle Width="10%" />
                                    <HeaderStyle Width="10%" />
                                </telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>

.cs page


 protected void RadGrid_InvAdjus_ExportCellFormatting(object sender, ExcelExportCellFormattingEventArgs e)
        {
          
            GridDataItem item = e.Cell.Parent as GridDataItem;           
           
            if (e.FormattedColumn.UniqueName == "Date")
            {
                e.Cell.Style["text-align"] = "left";
            }
            if (e.FormattedColumn.UniqueName == "Product")
            {
                RadGrid_InvAdjus.MasterTableView.GetColumn("Product").Visible = true;
                e.Cell.Style["text-align"] = "left";
                e.Cell.Style["text-decoration"] = "none";
            }
            if (e.FormattedColumn.UniqueName == "Description")
            {
                e.Cell.Style["text-align"] = "left";
            }
            if (e.FormattedColumn.UniqueName == "qty")
            {
                e.Cell.Style["text-align"] = "right";
            }
            if (e.FormattedColumn.UniqueName == "lot")
            {
                e.Cell.Style["text-align"] = "left";
            }
            if (e.FormattedColumn.UniqueName == "Order_No")
            {
                e.Cell.Style["text-align"] = "left";
            }
            if (e.FormattedColumn.UniqueName == "Reference_No")
            {
                e.Cell.Style["text-align"] = "left";
            }
            if (e.FormattedColumn.UniqueName == "Warehouse")
            {
                e.Cell.Style["text-align"] = "left";
            }
            if (e.FormattedColumn.UniqueName == "Template1")
            {
                e.Cell.Style["text-align"] = "left";

            }
           

            GridHeaderItem HeaderItem = (GridHeaderItem)RadGrid_InvAdjus.MasterTableView.GetItems(GridItemType.Header)[0];
            foreach (TableCell cell in HeaderItem.Cells)
            {
                cell.Style["text-align"] = "left";
                cell.Style["color"] = "#ff0000";
                cell.Style["border"] = "thin solid black";
                cell.Style["background-color"] = "#cccccc";
                cell.Style["font-weight"] = "normal";
            }
        }

        protected void RadGrid_InvAdjus_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            RadGrid_InvAdjus.DataSource = FillInventoryAdjustment();
        }

        protected void RadGrid_InvAdjus_GridExporting(object sender, GridExportingArgs e)
        {
            RadGrid_InvAdjus.MasterTableView.GetColumn("Product").Visible = true;
        }
Tags
Grid
Asked by
Nithya Rani
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Nithya Rani
Top achievements
Rank 1
Share this question
or