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

Export To Excel Layout Issue

8 Answers 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 09 Aug 2011, 01:35 PM
So I have a Grid with a MasterTableView that contains a DetailTable, and that DetailTable contains a DetailTable.  Everything is correct as far as layout indentation when it renders to the screen and when I export to pdf. But the problem is when I try to export to excel. When the spreadsheet opens the MasterTableView item is say 7 columns wide. The first DetailTable item is say 5 columns wide, and the second DetailTable items are 3 columns wide. And they appear like they are center aligned so it looks like an upside down pyramid.  My client does not like this and I have tried for hours now to figure out how to make the item indentations look like they do in the pdf and screen but with no luck.  Is there a setting or something to make the excel render correctly or is this a bug.  Below will be my grid markup, and I'll attach an image of the spreadsheet so you can see what it looks like.  Thanks for any help in this issue.


<telerik:RadGrid ID="RadGrid1" runat="server" ShowFooter="false" AutoGenerateColumns="false" AllowPaging="true" AllowSorting="false" CellSpacing="5" AllowFilteringByColumn="false"> 
    <ExportSettings HideStructureColumns="true" ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
        <Pdf AllowAdd="false" AllowCopy="true" AllowModify="false" AllowPrinting="true" PageTitle="ESign Sent vs Sold" Title="ESign Sent vs Sold" PaperSize="A4" PageWidth="260mm" />
        <Excel Format="Html" />
    </ExportSettings>
    
    <ClientSettings AllowExpandCollapse="true">
        <Selecting AllowRowSelect="true" />
    </ClientSettings>

    <MasterTableView DataKeyNames="ParentID, ID" Name="DivisionTable" HierarchyLoadMode="Client" HierarchyDefaultExpanded="false" ClientDataKeyNames="ParentID, ID">
        <HeaderStyle Font-Bold="true" HorizontalAlign="Left" Wrap="false" />
        <ItemStyle Wrap="false" VerticalAlign="Middle" HorizontalAlign="Left" />
        <AlternatingItemStyle Wrap="false" VerticalAlign="Middle" HorizontalAlign="Left" />
        <FooterStyle Wrap="false" />

        <DetailTables>
            <telerik:GridTableView Name="RegionTable" DataKeyNames="ParentID, ID" ClientDataKeyNames="ParentID, ID" HierarchyLoadMode="Client" Width="100%" HierarchyDefaultExpanded="false" >
                <DetailTables>
                    <telerik:GridTableView Name="BranchTable" DataKeyNames="ParentID, ID" ClientDataKeyNames="ParentID, ID" HierarchyLoadMode="Client" Width="100%" HierarchyDefaultExpanded="false" >
                        <Columns>
                            <telerik:GridTemplateColumn UniqueName="Filler" ItemStyle-Width="25px" HeaderStyle-Width="25px">
                                <ItemTemplate> <span>&nbsp;</span> </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn UniqueName="Text" DataField="Text" SortExpression="Text" HeaderText="Branch" ItemStyle-Width="300px" HeaderStyle-Width="300px" />
                            <telerik:GridBoundColumn UniqueName="SentCount" DataField="SentCount" SortExpression="SentCount" HeaderText="ESign Sent" ItemStyle-Width="150px" HeaderStyle-Width="150px" />
                            <telerik:GridBoundColumn UniqueName="SoldCount" DataField="SoldCount" SortExpression="SoldCount" HeaderText="Sold w/ ESign"  />
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridBoundColumn UniqueName="Text" DataField="Text" SortExpression="Text" HeaderText="Region" ItemStyle-Width="300px" HeaderStyle-Width="300px" />
                    <telerik:GridBoundColumn UniqueName="SentCount" DataField="SentCount" SortExpression="SentCount" HeaderText="ESign Sent" ItemStyle-Width="150px" HeaderStyle-Width="150px" />
                    <telerik:GridBoundColumn UniqueName="SoldCount" DataField="SoldCount" SortExpression="SoldCount" HeaderText="Sold w/ ESign"  />
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>
            <telerik:GridBoundColumn UniqueName="Text" DataField="Text" SortExpression="Text" HeaderText="Division" ItemStyle-Width="300px" HeaderStyle-Width="300px" />
            <telerik:GridBoundColumn UniqueName="SentCount" DataField="SentCount" SortExpression="SentCount" HeaderText="ESign Sent" ItemStyle-Width="150px" HeaderStyle-Width="150px"   />
            <telerik:GridBoundColumn UniqueName="SoldCount" DataField="SoldCount" SortExpression="SoldCount" HeaderText="Sold w/ ESign"  />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

8 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Aug 2011, 01:40 PM
Hello,

please see below link for set style before export.

http://www.telerik.com/help/aspnet/grid/grdexporttipstricks.html
http://www.telerik.com/help/aspnet-ajax/grid-html-export.html


For ex :
foreach (GridDataItem item in radgrid1.MasterTableView.Items)
                {
                    item["ColumnUniqueName"].Style["text-align"] = "left";
 
                    if (item.HasChildItems)
                    {
                       ........... // set again style here


Thanks,
Jayesh Goyani
0
Joshua
Top achievements
Rank 1
answered on 09 Aug 2011, 01:48 PM
I have tried that, and implement it to set the style of the row's background color, font color, etc.  I even tried to use it to set the widths of the column and/or the item's cell, but still no luck.
0
Joshua
Top achievements
Rank 1
answered on 09 Aug 2011, 03:41 PM
Anybody?  Telerik??? 
0
Daniel
Telerik team
answered on 12 Aug 2011, 09:53 PM
Hello Joshua,

Could you please try to help me reproduce this behavior locally? This way I will be able to provide a workaround for your scenario.
I attached a simple demo based on your code - test it on your end and see if I'm missing something.

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Joshua
Top achievements
Rank 1
answered on 15 Aug 2011, 01:32 PM
Actually, the work around I came up with was to create a second Grid that would not implement detail tables and add a style attribute to the Grid with position of absolute and visibility of hidden.  I tried using the asp.net attribute of Visible equals false and on the export button click setting the Grid's Visibility to true, but for some reason the Header would not render on the pdf even though it was found in the ItemCreated event.  So I think you may have a bug there.
0
Daniel
Telerik team
answered on 18 Aug 2011, 09:27 PM
Please have in mind that all changes that you made before export will be reflected in the exported file only. This means, that you don't have to set the Visible property back to its previous state. This setting won't have effect on your actual page that is displayed in the browser, but to the exported content only.

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Dai Thanh
Top achievements
Rank 1
answered on 29 May 2012, 11:24 AM
HI Daniel

i used you demo file and change value of column Text

example :
protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        RadGrid1.NeedDataSource += (s, a) =>
            {
                DataTable table = new DataTable();
                table.Columns.AddRange(new DataColumn[]
                {
                    new DataColumn { ColumnName = "ID" },
                    new DataColumn { ColumnName = "ParentID" },
                    new DataColumn { ColumnName = "Text" },
                    new DataColumn { ColumnName = "SentCount" },
                    new DataColumn { ColumnName = "SoldCount" }
               });

                string ex="<div class=\"ExternalClassCF0BF697C34047FA8A2A0634405DEF8C\"><p>?<table cellspacing=\"0\" cellpadding=\"0\"><colgroup><col width=\"189\" /></colgroup><tbody><tr height=\"59\"><td class=\"wc005DF1F0\" style=\"border-bottom:#f0f0f0;border-left:#f0f0f0;background-color:transparent;border-top:#f0f0f0;border-right:#f0f0f0\"><div class=\"ExternalClassBDCD4ADC97E742388A9A2898B925110C\"><div><font face=\"Arial\" size=\"2\">&lt;div&gt;?anh&lt;div&gt;</font></div>";
                ex += "<div><font face=\"Arial\" size=\"2\">&lt;div&gt;?ba&lt;div&gt;</font></div>";
                ex += "<div><font face=\"Arial\" size=\"2\">&lt;div&gt;?hung&lt;div&gt;</font></div></div></td></tr></tbody></table>";
                ex += "</p></div>";
                for (int i = 0; i < 1; i++)
                {
                    table.Rows.Add(i, i, ex, i, i);
                }
                RadGrid1.DataSource = table;
            };

        Button1.Click += (s, a) =>
            {
                RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
                RadGrid1.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true;
                RadGrid1.MasterTableView.ExportToExcel();
            };
    }

when i export excel column Text not content data on the same row. it break 3 rows








0
Daniel
Telerik team
answered on 01 Jun 2012, 08:13 AM
Hello Dai Thanh,

Microsoft Excel automatically converts the DIV tags to new lines. I believe there is no way around this.

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Joshua
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Joshua
Top achievements
Rank 1
Daniel
Telerik team
Dai Thanh
Top achievements
Rank 1
Share this question
or