This project has moved and is read-only. For the latest updates, please go here.

Save files in Loop

May 14, 2014 at 9:57 AM
Edited May 14, 2014 at 10:53 AM
Hello !

I'm trying to generate Excel files in Loop, I can save my first file, but after that, my header crash and i cannot save other files ...

there is my function :
Function CreerExcel(ByVal val1 As String, ByVal val2 As String, ByVal val3 As String, ByVal val4 As String, ByVal val5 As String)
        'Ouverture de mon fichier Excel existant
        Dim ExistFile = Server.MapPath("~/Styles/Excel/fiche_evaluation.xlsx")
        Dim File = New FileInfo(ExistFile)
        'Définition du package EPplus
        Using package As New ExcelPackage(File)
            package.Load(New FileStream(ExistFile, FileMode.Open))
            'Selection de l'onglet de travail (Excel)
            Dim workSheet As ExcelWorksheet = package.Workbook.Worksheets("Feuil1")
            workSheet.Cells("B6").Value = val1
            workSheet.Cells("F6").Value = val2
            workSheet.Cells("C7").Value = val3
            workSheet.Cells("G7").Value = val4
            workSheet.Cells("C8").Value = val5
            'Enregistrement du nouveau fichier
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            Response.AddHeader("content-disposition", "attachment;  filename=Eval_" & val1 & "-" & val5 & ".xlsx")
        End Using
    End Function
Any idea to solve this ???
May 14, 2014 at 12:03 PM
I don´t know how are you doing your loop, but you can't flush several files at once. Maybe you can create all your worksheets on the server, zip them and flush this compress file.
May 14, 2014 at 12:53 PM
How can I Proceed ?

I never use VB, or EPPlus before, so i don't know how to work ><