c# - When exporting gridview to xls, the entire row is formatted. How can I limit this to my gridview columns -


I have the gridview that I am exporting in Excel file. When I open Excel file, the color of the optional line Excel spreads to the end of the table, but I only want to format my 6 data columns. How can I limit the formatting?

GridView id = "grdExportable" runat = "server" BackColor = "white" ForeColor = "black" width = "1100px" AutoGenerateColumns = "False" visible = "False" & gt; & Lt; PageRacing mode = "NumericFirstLast" /> & Lt; Columns & gt; & Lt; ASP: BoundfieldDefined = "ActivityDetermine" header text = "date / time" /> & Lt; ASP: Boundfield datedfield = "Tastem" header text = "testname" /> & Lt; ASP: Boundfield datedfield = "round serial number" header text = "round cial number" /> & Lt; ASP: BoundfieldDIFF field = "Round type" header text = "round type" /> & Lt; ASP: Boundfield datedfield = "Lotnumber" headtext = "Lot / Stockman" /> & Lt; ASP: Boundfield Datafield = "Notes" HeaderText = "Notes" /> & Lt; / Column & gt; & Lt; SelectedRowStyle BackColor = "# 000099" font-bold = "true" ForeColor = "white" /> & Lt; HeaderStyle BackColor = "# 6C0000" font-bold = "true" ForeColor = "white" /> & Lt; AlternatingRowStyle BackColor = "#CCCCC" /> & Lt; / ASP: GridView & gt;

My export method:

  Private Zero Export Grid view () {string attachment = "attachment; filename = activity report.xls"; Response.ClearContent (); Response.AddHeader ("Content-Properties", Attachments); Response.ContentType = "App / MS-Excel"; Stringwright SW = new stringwriter (); HtmlTextWriter htw = new HtmlTextWriter (sw); GrdExportable.Visible = True; GrdExportable.RenderControl (HTW); GrdExportable.Visible = false; Response.Write (sw.ToString ()); Response.End (); }  

Well you are not really "exported for excellence", you Sending an HTML table to open it in the browser with the content type of App / MS-Excel, and to take advantage of the fact that Excel will show it as a spreadsheet. If you want this good level of control of Excel formatting you need to create a real Excel file.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -