Search code examples
c#excelzipblazorepplus

how to get xls file from a ZipArchiveEntry EPPlus C#


i'am trying to get an xls file from an ZipArchive but cant get it with EPPLUS

  foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry != null)
                    {                        
                        string filepath = entry.FullName;
                        FileInfo fileInfo = new FileInfo(filepath);
                        
                        //here i got the excel package with the xls file inside the excelPackage 
                        using (ExcelPackage excelPackage = new ExcelPackage(fileInfo))
                        {                            
                      //but here impossible de get the worksheet or workbook inside or anything else    
                            ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.FirstOrDefault();
                            int totalColomn = worksheet.Dimension.End.Column;
                            int nbrsheet = excelPackage.Workbook.Worksheets.Count();
                        }
                    }
               }

the ExcelPackage i get in debug i see the xls file on debug inside the excelpackage but just when i try to get worksheet it exit without exception code....

same here when trying with entryStream


                        using (var entryStream = entry.Open())
                        {
                       //Cant even get the excelpackage, it crash here without exception
                            using (ExcelPackage excelPackage = new ExcelPackage(entryStream))
                            {
                                ExcelWorksheet worksheetest = excelPackage.Workbook.Worksheets.FirstOrDefault();
                            }
                        }

the stream here seem also strange ... entryStream Debug

Working with .NET CORE Blazor ServerSide, ePPLUS 4.5

Thanks for helping


Solution

  • I find the problem.

    it was that i tried to get an xls file and the epplus library dont work with it... you have to be careful, EPplus dont work with xls file

    So , your solution Jeff is working, it was my fault, didn't specified the extension of my excel file... sorry

    -> EPlus with an .xlsx OK, not .xls

    My bad. Thanks anyway :-)