public void ReadBatchTest_AllSheet() { DataSet dataSet = null; DataTable dataTable = null; int rowCount = 0; using (IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(Helper.GetTestWorkbook("TestMultiSheet"))) { if (!excelReader.IsValid) { throw new Exception(excelReader.ExceptionMessage); } dataSet = excelReader.GetSchema(); excelReader.BatchSize = 5; // Modify as per need, default is 1000 foreach (DataTable dt in dataSet.Tables) { excelReader.SheetName = dt.TableName; excelReader.IsFirstRowAsColumnNames = Convert.ToBoolean(dt.ExtendedProperties["IsFirstRowAsColumnNames"]); excelReader.SkipRows = Convert.ToInt32(dt.ExtendedProperties["SkipRows"]); rowCount = 0; while (excelReader.ReadBatch()) { dataTable = excelReader.GetCurrentBatch(); rowCount += dataTable.Rows.Count; if (rowCount == excelReader.BatchSize) { Assert.AreEqual(5, rowCount); } } } } }
public void GetSchemaTest_MoreThanOneSheet() { DataSet dataset = null; List <SheetParameters> sheetParamList = new List <SheetParameters>(2); using (IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(Helper.GetTestWorkbook("TestMultiSheet"))) { if (!excelReader.IsValid) { throw new Exception(excelReader.ExceptionMessage); } sheetParamList.Add(new SheetParameters("Sheet2", false)); sheetParamList.Add(new SheetParameters("Sheet1", false)); dataset = excelReader.GetSchema(sheetParamList); } Assert.AreEqual(4, dataset.Tables["Sheet2"].Columns.Count); foreach (DataColumn dc in dataset.Tables["Sheet2"].Columns) { Assert.AreEqual(typeof(double), dc.DataType); } Assert.AreEqual(4, dataset.Tables["Sheet1"].Columns.Count); foreach (DataColumn dc in dataset.Tables["Sheet1"].Columns) { Assert.AreEqual(typeof(double), dc.DataType); } }
public void GetSchemaTest_AllSheet() { DataSet dataset = null; using (IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(Helper.GetTestWorkbook("TestMultiSheet"))) { if (!excelReader.IsValid) { throw new Exception(excelReader.ExceptionMessage); } dataset = excelReader.GetSchema(); } Assert.AreEqual(4, dataset.Tables["Sheet2"].Columns.Count); foreach (DataColumn dc in dataset.Tables["Sheet2"].Columns) { Assert.AreEqual(typeof(double), dc.DataType); } Assert.AreEqual(4, dataset.Tables["Sheet1"].Columns.Count); foreach (DataColumn dc in dataset.Tables["Sheet1"].Columns) { Assert.AreEqual(typeof(double), dc.DataType); } Assert.AreEqual(2, dataset.Tables["Sheet3"].Columns.Count); foreach (DataColumn dc in dataset.Tables["Sheet3"].Columns) { Assert.AreEqual(typeof(double), dc.DataType); } }
public void GetSchemaTest_OneSheet() { DataTable datatable = null; using (IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(Helper.GetTestWorkbook("TestMultiSheet"))) { if (!excelReader.IsValid) { throw new Exception(excelReader.ExceptionMessage); } datatable = excelReader.GetSchema(new SheetParameters("Sheet2", false)); } Assert.AreEqual(4, datatable.Columns.Count); foreach (DataColumn dc in datatable.Columns) { Assert.AreEqual(typeof(double), dc.DataType); } }