[英]When exporting gridview to xls, the entire row is formatted. How can I limit this to my gridview columns
我有一個要導出到Excel文件的gridview。 當我打開excel文件時,交替的行顏色擴展到excel表的末尾,但是我只希望格式化6個數據列。 如何限制格式?
我的GridView:
<asp:GridView ID="grdExportable" runat="server" BackColor="White" ForeColor="Black"
Width="1100px" AutoGenerateColumns="False" Visible="False">
<PagerSettings Mode="NumericFirstLast" />
<Columns>
<asp:BoundField DataField="ActivityDateTime" HeaderText="Date/Time" />
<asp:BoundField DataField="TestName" HeaderText="TestName" />
<asp:BoundField DataField="RoundSerialNumber" HeaderText="RoundSerialNumber"/>
<asp:BoundField DataField="RoundType" HeaderText="RoundType"/>
<asp:BoundField DataField="LotNumber" HeaderText="Lot/StockNumber" />
<asp:BoundField DataField="Notes" HeaderText="Notes" />
</Columns>
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6C0000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC"/>
</asp:GridView>
我的導出方法:
private void ExportGridView()
{
string attachment = "attachment; filename=Activity Report.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grdExportable.Visible = true;
grdExportable.RenderControl(htw);
grdExportable.Visible = false;
Response.Write(sw.ToString());
Response.End();
}
好吧,您不是真正的“導出到excel”,而是將html表發送到瀏覽器,其內容類型為application / ms-excel,以便讓excel打開它並利用excel將顯示的事實作為電子表格。 如果要對excel格式進行這種精細的控制,則需要生成一個實際的excel文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.