none
How to read the XLS format excel file using EPPlus library RRS feed

  • Question

  • hi,

    I am using bellow code to read the data from excel file

       FileInfo fileInfo = new FileInfo(filePath);
       ExcelPackage excl = new ExcelPackage(fileInfo );

     foreach (ExcelWorksheet sht in excl.Workbook.Worksheets)

    {

    ....

    }

    Above code works only xlsx and xlsm format file but not works for xls format.

    Can anyone help me to use the same EPPlus library to read data from XLS format excel file?

    Thanks

    Arivazhagan K

    • Moved by Sabah ShariqMVP Friday, September 29, 2017 1:19 PM Moved From Visual C#
    Friday, September 29, 2017 7:36 AM

All replies

  • Hi Arivazhagan K,

    This is Visual C# forum. As your issue is related to Excel I am moving your thread to Excel forum for getting quick response.

    Your understanding and cooperation will be grateful.

    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Friday, September 29, 2017 1:19 PM
  • The .xls file is in structured storage format and not XML so you won't be able to use the EPPlus library for that. One option for .xls is to use an Excel Reader library:

    https://www.codeproject.com/Articles/16210/Excel-Reader


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, September 29, 2017 1:27 PM
  • Hello,

    This forum is for development issues when using Excel Object Model. We support questions about Microsoft.Office.Interop and Open XML library. EPPlus library is out of scope. I suggest you use Microsoft.Office.Interop.Excel to automate Excel. It works for all Excel formats.

    Please visit How to automate Microsoft Excel from Microsoft Visual C#.NET

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 2, 2017 3:26 AM
    Moderator
  • With all due respect, Celeste, unless things have changed (since last I read about it), Microsoft does not support instantiating Excel in a NON-GUI application (especially not from within a Windows Service or Web Service).

    Clearly, many people are doing so ANYWAY (and/or using other .NET components).

    While Excel does a GREAT job (as a User Interface), interacting with Excel files (both XML format and the older Compound Document format) is something that MANY, MANY applications must do to meet Business Requirements (without risking violating Microsoft's EULA).


    wardmd

    Wednesday, January 24, 2018 3:33 PM
  • Hi Arivazhagan K,

    You cannot use epplus to read xls file, I'm afraid you need to find other approaches instead. I'd recommend free spire.xls library availabe on nuget, it supports reading .xls, .xlsx and .xlsm files.

    Workbook workbook = new Workbook();
    workbook.LoadFromFile(@"Input.xls");
    
    foreach(Worksheet sheet in workbook.Worksheets)
    {
        //....
    } 
    

    Hope my answer helps.


    • Edited by Shawn Sh Thursday, January 25, 2018 2:38 AM
    Thursday, January 25, 2018 2:32 AM