我的aspx页面有一个excel下载问题。 Excel文件大小仅为256KB。
从一个aspx页面以外的所有aspx页面下载文件。我不明白为什么会这样。不仅如此,它正在开发DEV和QA环境,但是当我们将相同的代码推向生产时。它不起作用。
在母版页菜单项上下载代码。
ElseIf e.Item.Text = "Download" Then
ResponseHelper.DownloadExcel()
Public Shared Sub DownloadExcel() GenerateData() 结束子 公共共享子GenerateData() 昏暗的回应作为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
http://uploading.com/files/18b59f94/Observations.aspx/
答案 0 :(得分:0)
您是否尝试过使用其他内容类型? 请改为使用“application / vnd.ms-excel”。
祝你好运!