Protected Sub ExportToExcel(sender As Object, e As EventArgs) Response.Clear() Response.Buffer = True Response.AddHeader("content-disposition", "attachment;filename=Scope.xls") 'Response.AddHeader("content-disposition", "attachment;filename=Scope.xlsx") Response.Charset = "" Response.ContentType = "application/vnd.ms-excel" Using sw As New StringWriter() Dim hw As New HtmlTextWriter(sw) 'To Export all pages gdScope.AllowPaging = False Me.btnShow_Click(Me, e) gdScope.HeaderRow.BackColor = Color.White For Each cell As TableCell In gdScope.HeaderRow.Cells cell.BackColor = gdScope.HeaderStyle.BackColor Next For Each row As GridViewRow In gdScope.Rows row.BackColor = Color.White For Each cell As TableCell In row.Cells If row.RowIndex Mod 2 = 0 Then cell.BackColor = gdScope.AlternatingRowStyle.BackColor Else cell.BackColor = gdScope.RowStyle.BackColor End If cell.CssClass = "textmode" Next Next gdScope.RenderControl(hw) 'style to format numbers to string Dim style As String = "<style> .textmode { } </style>" Response.Write(style) Response.Output.Write(sw.ToString()) Response.Flush() Response.[End]() End Using End Sub Public Overrides Sub VerifyRenderingInServerForm(control As Control) ' Verifies that the control is rendered End Sub
<connectionStrings> <add name ="Excel03ConString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'"/> <add name ="Excel07ConString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'"/> </connectionStrings >
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)