I have a gridview that I am exporting to an excel file. When I open the excel file, the alternating row color extends to the end of the excel table, but I only want my 6 data columns to be formatted. How can I limit the formatting?
My 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>
My export method:
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();
}