You must Sign In to post a response.
  • Category: ASP.NET

    After Export datagrid to excel file format error yes/no prompt

    I have an issue for data grid view exporting to excel.
    Here I have data grid view with hyperlink column. As per requirement we have to export whole grid with hyper link. After export to excel user can able open report by clicking Month Column in Excel. So until this part everything is working fine But after export to excel file when we are trying to open excel it prompt message as below . I tried many ways it work without hyperlink and fixed file name. if I we pass hyper link or customised file name getting same issue. is there any other way to fix this issue.

    Code for Export to excel :-

    Protected Sub ExportToExcel(sender As Object, e As EventArgs) Handles btnExport.Click
    Dim fileName As String = lblHeader.Text.ToString() + "_" + Date.Now.ToString("dd-MM-yyyy_hh_mm_ss tt")
    Using sw As New StringWriter()
    Dim hw As New HtmlTextWriter(sw)
    gvReport.AllowPaging = False
    'Dim fromdate As String = Format(CDate(txtCreatedFrDt.Text), "yyyy-MM-dd")
    'Dim todate As String = Format(CDate(txtCreatedToDt.Text), "yyyy-MM-dd")
    'Me.BindDataGrid(fromdate, todate)
    gvReport.CellPadding = 0
    gvReport.CellSpacing = 0
    gvReport.GridLines = GridLines.None
    gvReport.BorderStyle = BorderStyle.None
    gvReport.HeaderRow.BackColor = Color.White
    gvReport.HeaderRow.BorderColor = Color.LightCyan

    For Each cell As TableCell In gvReport.HeaderRow.Cells
    cell.BackColor = gvReport.HeaderStyle.BackColor
    cell.BorderWidth = "1"
    'cell.BorderColor = Color.AliceBlue
    Dim tmpsdt As DataTable = Session("IDdt")
    For Each row As GridViewRow In gvReport.Rows
    row.BackColor = Color.White
    For Each cell As TableCell In row.Cells

    If row.RowIndex Mod 2 = 0 Then
    cell.BackColor = gvReport.AlternatingRowStyle.BackColor
    cell.BorderWidth = "0.5"
    cell.BorderColor = Color.AliceBlue
    cell.BackColor = gvReport.RowStyle.BackColor
    cell.BorderWidth = "0.5"
    cell.BorderColor = Color.AliceBlue
    End If

    Response.Buffer = True
    Response.ContentType = "application/"
    Response.Write("<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">")

    ' Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", "SummaryReport " + DateTime.UtcNow.ToString() + ".xls"))
    'Response.AddHeader("Content-Disposition: ", [String].Format("attachment; filename={0}", fileName))
    Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", fileName.ToString() + ".xls"))
    Response.Charset = "utf-8"
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250")
    Response.Write("<font style='font-size:10.0pt; font-family:Arial;'>")
    Response.Write("<Table border='1' bgColor='#ffffff' " + "borderColor='#cec9c9' cellSpacing='0' cellPadding='0' " + "style='font-size:10.0pt; font-family:Arial; background:white;'> <TR>")
    Dim style As String = "<style> .textmode { mso-number-format:\@; } </style>"
    ''Dim style As String = "<style> TD { mso-number-format:\@; } </style>"
    '' style = style + " <style> .textmode{mso-number-format:\@;} </style>"


    End Using
    End Sub
  • #769288

    cool ,,
    thanks for the post

  • Sign In to post your comments