0

I tried to do that using code:

worksheet.Columns.count();

But there is not method count() for Columns

All code is:

 class ExcelReader
    {

        private XLWorkbook workbook;
        private string file;
        private IXLWorksheet worksheet;


        public ExcelReader(string file) {

            this.workbook = new XLWorkbook(file);
        }

        private void ChooseWorksheet(int sheet) {

            this.worksheet = workbook.Worksheet(sheet);
        } 

        public int NumberColumns() {

            return this.worksheet.Columns.Count();
        }
}
ITMANAGER
  • 131
  • 1
  • 3
  • 10

2 Answers2

3

Looking at the code from https://github.com/ClosedXML/ClosedXML Count should work using LINQ, since IXLColumns implemments IEnumerable<IXLColumn> IXLColumns: IEnumerable

If you are getting a method missing on Count, means you are missing

using System.Linq;
user6144226
  • 613
  • 1
  • 8
  • 15
1

I was trying to do the same thing. The following worked for me:

worksheet.Columns().Count()

Nate Anderson
  • 777
  • 2
  • 7
  • 26