static void Main(string[] args) { //Console.WriteLine("Hello World!"); var s = GetExcelPath(); var bytes = GetExcel(s); var wb = new ClosedXML.Excel.XLWorkbook(new MemoryStream(bytes)); IEnumerable <SimpleTable> data = wb.ReadTable <SimpleTable>(1); var l = wb.ReadTable <Models.TableWithHeaders>(1, new ReadOptions() { TitlesInFirstRow = true }); Console.WriteLine(l.ToList().Count); //Example with trasnformations Expression <Func <string, DateTime> > fConvertData = _ => DateTime.Now.AddDays(10); Expression <Func <string, bool> > fSelectToBool = c => c == "x"; var ls = wb.ReadTable <Models.TableWithHeadersAndBoleanConversion>(1, new ReadOptions() { TitlesInFirstRow = true, Converters = new Dictionary <string, LambdaExpression>() { { nameof(TableWithHeadersAndBoleanConversion.Birthday), fConvertData }, { nameof(TableWithHeadersAndBoleanConversion.Selected), fSelectToBool }, } }); wb.Dispose(); Console.WriteLine(ls.ToList().Count); Console.ReadLine(); }
private void btnLoadExcel_Click(object sender, EventArgs e) { var s = GetExcelPath(); var bytes = GetExcel(s); var wb = new ClosedXML.Excel.XLWorkbook(new MemoryStream(bytes)); var l = wb.ReadTable(1, new ReadOptions() { TitlesInFirstRow = true }); dataGridView1.DataSource = l; }