所以我有一个带有MasterTableView的Grid,它包含一个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> </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>
答案 0 :(得分:1)
是的,内置的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();
}