我在使用我的 aspx 页面之一下载 excel 时遇到问题。Excel 文件大小仅为 256KB。
从所有 aspx 页面下载文件,但从一个 aspx 页面除外。我不明白为什么会这样。不仅如此,它还在开发和质量保证环境中工作,而且当我们将相同的代码推送到生产环境时。它不工作。
更新
在 Master Page 菜单项上下载代码。
母版页
ElseIf e.Item.Text = "Download" Then
ResponseHelper.DownloadExcel()
响应助手.vb
Public Shared Sub DownloadExcel() GenerateData() End Sub Public Shared Sub GenerateData() Dim response As HttpResponse response = System.Web.HttpContext.Current.Response
Dim sqlDs As New DataSet
Dim sqlCmd As New SqlClient.SqlCommand
Dim sqlDa As New SqlClient.SqlDataAdapter
Dim SqlCnn As New SqlClient.SqlConnection(AppSettings("dbKey"))
--All ADO.Net statements here
If sqlDs.Tables(0).Rows.Count > 0 Then
Dim dtAllDownload As DataTable = sqlDs.Tables(0)
Dim dtChinaManufacturing As New DataTable
Dim dtChinaHealthcare As New DataTable
Dim dtChinaManagement As New DataTable
Dim dtChinaSelling As New DataTable
Dim dv As DataView
dv = New DataView(sqlDs.Tables(0), "GL_Source='Manufacturing'", "Id", DataViewRowState.CurrentRows)
dtChinaManufacturing = dv.ToTable
dv = New DataView(sqlDs.Tables(0), "GL_Source='Healthcare'", "Id", DataViewRowState.CurrentRows)
dtChinaHealthcare = dv.ToTable
dv = New DataView(sqlDs.Tables(0), "GL_Source='Management'", "Id", DataViewRowState.CurrentRows)
dtChinaManagement = dv.ToTable
dv = New DataView(sqlDs.Tables(0), "GL_Source='Selling'", "Id", DataViewRowState.CurrentRows)
dtChinaSelling = dv.ToTable
dv.Dispose()
Using pck As New ExcelPackage()
'Create the worksheets
Dim wsAll As ExcelWorksheet = pck.Workbook.Worksheets.Add("All")
Dim wsChinaManufacturing As ExcelWorksheet = pck.Workbook.Worksheets.Add("Manufacturing")
Dim wsChinaHealthcare As ExcelWorksheet = pck.Workbook.Worksheets.Add("Healthcare")
Dim wsChinaManagement As ExcelWorksheet = pck.Workbook.Worksheets.Add("Management")
Dim wsChinaSelling As ExcelWorksheet = pck.Workbook.Worksheets.Add("Selling")
'Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
wsAll.Cells("A1").LoadFromDataTable(dtAllDownload, True)
If dtChinaManufacturing.Rows.Count > 0 Then
wsManufacturing.Cells("A1").LoadFromDataTable(dtManufacturing, True)
End If
If dtChinaHealthcare.Rows.Count > 0 Then
wsChinaHealthcare.Cells("A1").LoadFromDataTable(dtHealthcare, True)
End If
If dtChinaManagement.Rows.Count > 0 Then
wsChinaManagement.Cells("A1").LoadFromDataTable(dtManagement, True)
End If
If dtChinaSelling.Rows.Count > 0 Then
wsChinaSelling.Cells("A1").LoadFromDataTable(dtSelling, True)
End If
'wsAll.Cells(1, 1, dtAllDownload.Rows.Count - 1, dtAllDownload.Columns.Count).AutoFitColumns(30)
wsAll.defaultColWidth = 20
'Write it back to the client
Dim filename As String = "FullExtract_" & Now.Year.ToString & Now.Month.ToString & Now.Day.ToString & ".xlsx"
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
response.AddHeader("content-disposition", "attachment; filename=" & filename)
response.BinaryWrite(pck.GetAsByteArray())
response.End()
End Using
End If
End Sub
此下载给出错误的 Aspx 页面。
http://uploading.com/files/18b59f94/Observations.aspx/