RadGrid 导出到 Excel 布局问题

发布于 2024-11-28 22:30:42 字数 4483 浏览 0 评论 0原文

所以我有一个带有 MasterTableView 的网格,其中包含一个 DetailTable,并且该 DetailTable 包含一个 DetailTable。就布局缩进而言,当它渲染到屏幕上以及导出到 pdf 时,一切都是正确的。但问题是当我尝试导出到 Excel 时。当电子表格打开时,MasterTableView 项目的宽度为 7 列。第一个 DetailTable 项目的宽度为 5 列,第二个 DetailTable 项目的宽度为 3 列。它们看起来像是中心对齐的,所以看起来像一个颠倒的金字塔。我的客户不喜欢这个,我已经尝试了几个小时来弄清楚如何使项目缩进看起来像 pdf 和屏幕中的那样,但没有成功。是否有设置或其他东西可以使 Excel 正确渲染,或者这是一个错误。下面是我的网格标记,我将附上电子表格的图像,以便您可以看到它的样子。感谢您对此问题的任何帮助。

    <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>

在此处输入图像描述

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> </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>

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍孤女 2024-12-05 22:30:42

是的,内置的 Excel 导出功能并不可靠。

将导出按钮添加到您的页面,然后尝试使用此按钮:

   protected void btnExport_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/vnd.ms-excel";
        Response.Charset = "";

        this.EnableViewState = false;
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
        RadGrid1.RenderControl(oHtmlTextWriter);
        Response.Write(oStringWriter.ToString());
        Response.End();
    }

Yea, the built in Excel export functionality is unreliable.

Add an export button to your page, and try using this instead:

   protected void btnExport_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/vnd.ms-excel";
        Response.Charset = "";

        this.EnableViewState = false;
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
        RadGrid1.RenderControl(oHtmlTextWriter);
        Response.Write(oStringWriter.ToString());
        Response.End();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文