public void ReadAndWrite() { var xl = new TestFileContext("test.xlsx"); xl.SerializeToFile("test-out.xlsx"); xl.SerializeToStream(); xl.SerializeToExcelPackage(); var xl2 = new TestFileContext("test-out.xlsx"); Assert.AreEqual(xl.GetSheet <TestFileContext.Sheet1>().Count, xl2.GetSheet <TestFileContext.Sheet1>().Count); Assert.AreEqual(xl.GetSheet <Class1>().Count, xl2.GetSheet <Class1>().Count); }
public void ReadSample1File_test(TestFileContext xl) { var sheet1 = xl.GetSheet <TestFileContext.Sheet1>(); var sheet2 = xl.GetSheet <Class1>(); Assert.AreEqual(2, sheet1.Count); var s1row = sheet1[0]; Assert.AreEqual(DateTime.Parse("7/1/2020"), s1row.Date); Assert.AreEqual(52, s1row.Quantity); Assert.AreEqual("Widgets", s1row.Description); Assert.AreEqual(45.99m, s1row.Amount); Assert.AreEqual(2391.48m, s1row.Total); Assert.AreEqual(null, s1row.Notes); s1row = sheet1[1]; Assert.AreEqual(DateTime.Parse("7/23/2020"), s1row.Date); Assert.AreEqual(22, s1row.Quantity); Assert.AreEqual("Bolts", s1row.Description); Assert.AreEqual(2.54m, s1row.Amount); Assert.AreEqual(55.88m, s1row.Total); Assert.AreEqual("Each bolt is a set of two", s1row.Notes); Assert.AreEqual(9, sheet2.Count); var s2row = sheet2[0]; Assert.AreEqual(1, s2row.IntColumn); Assert.AreEqual(1f, s2row.FloatColumn); Assert.AreEqual(1.0, s2row.DoubleColumn); Assert.AreEqual("test", s2row.StringColumn); Assert.AreEqual(true, s2row.BooleanColumn); Assert.AreEqual(DateTime.Parse("8/2/2020"), s2row.DateTimeColumn); Assert.AreEqual(TimeSpan.FromHours(14), s2row.TimeSpanColumn); Assert.AreEqual(new Uri("http://localhost/test"), s2row.UriColumn); Assert.AreEqual(Guid.Parse("f1dc7e7d-d63e-4279-8dfd-cecb6e26cda8"), s2row.GuidColumn); Assert.AreEqual(3, s2row.NullableIntColumn); s2row = sheet2[1]; Assert.AreEqual(1, s2row.IntColumn); Assert.AreEqual(1.1f, s2row.FloatColumn); Assert.AreEqual(1.1, s2row.DoubleColumn); Assert.AreEqual("test2", s2row.StringColumn); Assert.AreEqual(false, s2row.BooleanColumn); Assert.AreEqual(DateTime.Parse("8/1/2020"), s2row.DateTimeColumn); Assert.AreEqual(TimeSpan.FromHours(14), s2row.TimeSpanColumn); Assert.AreEqual(new Uri("http://localhost/help"), s2row.UriColumn); Assert.AreEqual(Guid.Parse("89892480-4179-42c7-9e2f-e0bb1094dd6b"), s2row.GuidColumn); Assert.AreEqual(3, s2row.NullableIntColumn); s2row = sheet2[2]; Assert.AreEqual(1, s2row.IntColumn); Assert.AreEqual(1.1f, s2row.FloatColumn); Assert.AreEqual(1.1, s2row.DoubleColumn); Assert.AreEqual("test2", s2row.StringColumn); Assert.AreEqual(true, s2row.BooleanColumn); Assert.AreEqual(DateTime.Parse("8/3/2020"), s2row.DateTimeColumn); Assert.AreEqual(TimeSpan.FromHours(14), s2row.TimeSpanColumn); Assert.AreEqual(new Uri("http://localhost/help"), s2row.UriColumn); Assert.AreEqual(Guid.Parse("89892480-4179-42c7-9e2f-e0bb1094dd6b"), s2row.GuidColumn); Assert.AreEqual(3, s2row.NullableIntColumn); s2row = sheet2[3]; Assert.AreEqual(1, s2row.IntColumn); Assert.AreEqual(1.1f, s2row.FloatColumn); Assert.AreEqual(1.1, s2row.DoubleColumn); Assert.AreEqual("test2", s2row.StringColumn); Assert.AreEqual(true, s2row.BooleanColumn); Assert.AreEqual(DateTime.Parse("8/1/2020 2:30 PM"), s2row.DateTimeColumn); Assert.AreEqual(TimeSpan.Parse("2:34:56"), s2row.TimeSpanColumn); Assert.AreEqual(new Uri("http://localhost/help"), s2row.UriColumn); Assert.AreEqual(Guid.Parse("89892480-4179-42c7-9e2f-e0bb1094dd6b"), s2row.GuidColumn); Assert.AreEqual(null, s2row.NullableIntColumn); Assert.AreEqual(false, sheet2[4].BooleanColumn); Assert.AreEqual(true, sheet2[5].BooleanColumn); Assert.AreEqual(false, sheet2[6].BooleanColumn); Assert.AreEqual(true, sheet2[7].BooleanColumn); Assert.AreEqual(false, sheet2[8].BooleanColumn); }