ASPNET + IIS + Javascript Excel导出

时间:2017-11-14 05:52:21

标签: javascript asp.net excel iis

我需要你的小帮助,因为我试图从VBNet Develop下载大量数据。

此代码在我的本地PC上工作正常(5MB / 8MB文件),但是当我在服务器上传版本时,它只适用于小于4MB的生成文件。

我认为这与响应超时有关,但我对服务器上的IIS配置进行了一些更改。没结果!

这是我的VBNet代码

        Dim dt As New DataTable
        Dim objNeg As New Negocio.tempExcel(sg)
        dt = objNeg.getReportData(strnombreProcedimiento, parametros) 
                                            If strnombreReporte Is String.Empty Then
            strnombreReporte = "GenericReport"
        End If

        Dim worksheet = workbook.Worksheets.Add("Sheet")
        Dim intCol As Integer = 1
        Dim intRow As Integer = 2
        Dim indexTotal As Integer = 0
        Dim excelFormat As String
        For Each row As DataRow In dt.Rows
            indexTotal += 1
            For Each rowColumnConfig As DataRow In dtColumnasPorUsuario.Rows
                Dim index As Integer = 0                                                                                Dim isKey As String = rowColumnConfig.Item("IC_KEY").ToString
                Dim nameColumn As String = rowColumnConfig.Item("DS_ITEM").ToString
                Dim headerColumn As String = rowColumnConfig.Item("DS_NICK_OBJECT_ITEM").ToString
                Dim alignColumn As String = rowColumnConfig.Item("VL_ORDER_DIM1").ToString
                Dim formatColumn As String = rowColumnConfig.Item("DS_NICK_MASK").ToString
                Dim maxQttyChars As String = rowColumnConfig.Item("QT_CHARS").ToString
                Dim stringLength As String

                            For Each rowColumnConfig As DataRow In dtColumnasPorUsuario.Rows
            Dim headerColumn As String = rowColumnConfig.Item("DS_NICK_OBJECT_ITEM").ToString
            Dim maxCharsOnColumn As String = rowColumnConfig.Item("QT_CHARS").ToString
            Dim isKey As String = rowColumnConfig.Item("IC_KEY").ToString
                                                            Dim nameColumn As String = rowColumnConfig.Item("DS_ITEM").ToString
                                                            If isKey = "N" then
                                                                        worksheet.Cell(1, rowIndex).Value = headerColumn.Trim
                                                                        #If DEBUG then
                                                                                            worksheet.Cell(1, rowIndex).Value = nameColumn.Trim
                                                                        #End If
                                                                        'worksheet.Cell(1, rowIndex).Style.Font.Bold = True
                                                                        worksheet.Cell(1, rowIndex).Style.Font.FontName = "Calibri"
                                                                        worksheet.Cell(1, rowIndex).Style.Font.FontSize = CDec(12)
                                                                        'worksheet.Cell(1, rowIndex).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center
                                                                        worksheet.Cell(1, rowIndex).Style.Border.SetBottomBorder(XLBorderStyleValues.Thin)
                                                                        worksheet.Cell(1, rowIndex).Style.Border.SetLeftBorder(XLBorderStyleValues.Thin)
                                                                        worksheet.Cell(1, rowIndex).Style.Border.SetRightBorder(XLBorderStyleValues.Thin)
                                                                        worksheet.Cell(1, rowIndex).Style.Border.SetTopBorder(XLBorderStyleValues.Thin)
                                                                        worksheet.Column(rowIndex).Width = Convert.ToDouble(maxCharsOnColumn) + 4 

                                                                        rowIndex += 1
                                                            End If
        Next

        worksheet.Cell(indexTotal + 3, 1).Value = "DATE: " + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")
        worksheet.Cell(indexTotal + 3, 1).Style.Font.Bold = True

        Dim fileName As String

        fileName = DateTime.Now.ToString.Trim.Replace("/", "").Replace(":", "").Replace(" ", "").ToString + "_" + strnombreReporte.ToString.ToUpper + "_" + sg.UsuarioLogueado.ToString.ToUpper + ".xlsx"
                                            Dim path As String
                                            Dim urlServer As string
                                            Dim HttpResponse As HttpResponse = Response
                                            Dim clientURL As String = HttpContext.Current.Request.Url.Scheme + HttpContext.Current.Request.Url.SchemeDelimiter + HttpContext.Current.Request.Url.Authority + "/FTSNet/Excel/" + fileName
                                            Dim isLocal As String = String.Empty


                                            urlServer = Server.MapPath("~")
                                            path = urlServer + "/" +"Excel" + "/" + fileName
                                            worksheet.Workbook.SaveAs(path)
                                            Me.hdnFileName.Value = fileName

                                            Dim file As System.IO.FileInfo
                                            file = New FileInfo(path)

                                            ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "window.open('"+clientURL+"');", True) 'Retorna al cliente para poder descargar el archivo
                                            'ScriptManager.RegisterStartupScript(me.GetType(), "dsadas", "window.open('"+clientURL+"');", true)



                                            If (file.Exists) then
                                                                    Dim content As New LiteralControl("<script type='text/javascript'>" & "exportExcel('" & fileName & "','" & isLocal & "');" & "</script>")
                                                                    Me.WARPLista.Controls.Add(content)
                                                                    ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "exportExcel('" & fileName & "','" & isLocal & "');", True) 
                                                                    return
                                            End If

    Catch fex As FTS.Entidades.ExcepcionFTS
        Me.msgMensajes.MostrarError(fex, True)
    Catch ex As Exception
        Me.msgMensajes.MostrarError(ex, True)   
                            End Try
End Sub`

问题是当我尝试在Web服务器上执行时。生成文件,但长时间执行后应用程序不会返回。你能帮我正确配置IIS吗?提前谢谢!

0 个答案:

没有答案