public void DataReaderTest() { using (var reader = new ExcelDataReader(@"test.xlsx")) { Assert.AreEqual(0, reader.Depth); Assert.AreEqual(-1, reader.RecordsAffected); Assert.AreEqual(7, reader.FieldCount); Assert.AreEqual(5, reader.GetOrdinal("ColDecimal")); Assert.AreEqual(-1, reader.GetOrdinal("InvalidColName")); } }
public void GetField() { //var filePath = @"D:\Users\Scott\Source\github\cadru\tests\Cadru.Data.Tests\Plan Assignment DELETE File 20170615.xlsx"; var filePath = @"Adjustments Table Upload 20170616.xlsx"; using (var stream = File.OpenRead(filePath)) { using (var reader = new ExcelDataReader(stream)) { reader.FirstRowAsHeader = true; reader.Read(); var sheetName = reader.CurrentSheetName; reader.Read(); var empty = this.IsRowEmpty(reader, 0, Enumerable.Empty <int>()); var fiscalYear = reader.Field <int>(0); var empId = reader.Field <string>(1); var startDate = reader.Field <DateTime>(2); var status = reader.Field <int?>(6); var monthlyRate = reader.Field <decimal?>(7); var orgUnit = reader.Field <string>(10); var s1 = reader.ToDelimitedString(); var s2 = reader.ToDelimitedString(true); var action = "I"; var index = -1; if (reader.FieldNames.Contains("ImportAction")) { index = reader.GetOrdinal("ImportAction"); } else if (reader.FieldNames.Contains("Action")) { index = reader.GetOrdinal("Action"); } if (index != -1) { action = reader.GetString(index) ?? "I"; } reader.Close(); } } }