Reputation: 139
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();
}
}
Upvotes: 1
Views: 5811
Reputation: 867
I was trying to do the same thing. The following worked for me:
worksheet.Columns().Count()
Upvotes: 2
Reputation: 633
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;
Upvotes: 4