This project has moved. For the latest updates, please go here.

Problem with Excel file

Aug 21, 2014 at 12:34 PM
Edited Aug 21, 2014 at 1:04 PM
Thanks for this feature, but when I had used it a problem become. The excel, during opening the created file, says, that the created xlsx file is wrong. Then, after some prompts, excel is trying to correct the file, fortunately successfully. But I would need direct success :-/
Don't you know, where the problem could be? Many thanks, datatable contains data in over 25 thousands db rows and cca 20 columns, but a small datatable causes the same result too :(
My code is:
    Dim a As New Class1
    Dim dt As New DataTable
    Dim da As New SqlDataAdapter
    dt = a.SelectTriviaDT(cs, "EXEC dbo.sp_VyberPlatnaIZO")

    Using pck As New ExcelPackage
        Dim ws As ExcelWorksheet
        ws = pck.Workbook.Worksheets.Add("Pokus")
        ws.Cells("A1").LoadFromDataTable(dt, True)
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        Response.AddHeader("content-disposition", "attachment;  filename=ExcelDemo.xlsx")
    End Using
Aug 21, 2014 at 1:32 PM
Please, take a look at this thread (, maybe is your problem too.
Marked as answer by vasek007 on 8/21/2014 at 7:11 AM
Aug 21, 2014 at 2:11 PM
Thanks a lot! It really works! Wow!!!