Export to Excel shows an empty sheet

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Export to Excel shows an empty sheet

    When I run my Export to Excel, the Spreadheet is empty. Anyone know what may cause this? Here is my code:
    Response.Clear()
    Response.Charset = ""
    Response.ContentType = "application/vnd.ms-excel"
    Response.AppendHeader("Content-Disposition", "attachment;filename=" & strFileName & ".xls")


    Dim stringWrite As New System.IO.StringWriter
    Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

    Dim dg As New DataGrid

    'Copy data from existing Datagrid to the new Datagrid

    dg = dgExport

    dg.AllowPaging = False
    dg.AllowCustomPaging = False
    dg.AllowSorting = False
    dg.EnableViewState = False

    'Lets make it a generic looking spreadsheet
    dg.HeaderStyle.BackColor = Color.LightGray
    dg.AlternatingItemStyle.BackColor = Color.White
    dg.FooterStyle.BackColor = Color.LightGray
    dg.PagerStyle.BackColor = Color.Gainsboro
    dg.HeaderStyle.Font.Bold = True

    dg.DataBind()
    dg.RenderControl(htmlWrite)

    Response.Write(stringWrite.ToString)
    Response.End()

    Paul

    Paul D. Fox Guest

  2. Similar Questions and Discussions

    1. How to get the name of an Excel sheet?
      It's a COM call via CFObject but be warned - if there are External Links in the spreadsheet or VBA code, you could have issues. I'll post some code...
    2. Excel sheet creation from ASP
      Hi. Simple ASP creates Excel file on C drive: Dim xls Set xls = CreateObject( "Excel.Application") xls.Workbooks.Add...
    3. Export IPTC-Headers into Excel-Sheet
      I would like to Export IPTC-Header-information to an Excel-Sheet from about 300 Photoshop-jpg-Files. Any idea how? Rike
    4. Excel Sheet Export
      Hi All, I have an Excel sheet which I recieve every week. Its not too much data and the present process is to manually load that data into a SQL...
    5. Export to Excel sheet
      You may refer to this KB article: http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q288130 Luke (This posting is provided "AS IS",...
  3. #2

    Default Re: Export to Excel shows an empty sheet

    I seemed to have found the Issue. in my Page_Load event I have...
    The Page_Load event has the following:

    If Not Page.IsPostBack Then
    dgrdLCFDynamicReport.SelectedIndex = 0
    If dgrdLCFDynamicReport.Attributes("SortExpression") Is Nothing Then
    dgrdLCFDynamicReport.Attributes("SortExpression") = "Create_Date" 'Default Sort
    dgrdLCFDynamicReport.Attributes("SortDirection") = "ASC"
    End If
    Bind_dgrdLCFDynamicReport()
    End If

    This prevents the ability to Export the datagrid to Excel. By Removing the If/End If statement, the Datagrid can be properly exported. Not sure if this is actually an ASP.NET error or what...

    Paul
    "Paul D. Fox" <pdfox99@rcn.com> wrote in message news:uNgCxlpPFHA.2824@TK2MSFTNGP10.phx.gbl...
    When I run my Export to Excel, the Spreadheet is empty. Anyone know what may cause this? Here is my code:
    Response.Clear()
    Response.Charset = ""
    Response.ContentType = "application/vnd.ms-excel"
    Response.AppendHeader("Content-Disposition", "attachment;filename=" & strFileName & ".xls")


    Dim stringWrite As New System.IO.StringWriter
    Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

    Dim dg As New DataGrid

    'Copy data from existing Datagrid to the new Datagrid

    dg = dgExport

    dg.AllowPaging = False
    dg.AllowCustomPaging = False
    dg.AllowSorting = False
    dg.EnableViewState = False

    'Lets make it a generic looking spreadsheet
    dg.HeaderStyle.BackColor = Color.LightGray
    dg.AlternatingItemStyle.BackColor = Color.White
    dg.FooterStyle.BackColor = Color.LightGray
    dg.PagerStyle.BackColor = Color.Gainsboro
    dg.HeaderStyle.Font.Bold = True

    dg.DataBind()
    dg.RenderControl(htmlWrite)

    Response.Write(stringWrite.ToString)
    Response.End()

    Paul

    Paul D. Fox Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139