public void Should_convert_multiple_worksheets_to_byte_array_of_xlsx_file() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- List <Person> pre50 = _personList.Where(x => x.YearBorn < 1950).ToList(); List <Person> post50 = _personList.Where(x => x.YearBorn >= 1950).ToList(); WorksheetWrapper <Person> worksheetWrapper = pre50 .ToWorksheet("< 1950") .WithTitle("< 1950") .NextWorksheet(post50, "> 1950") .WithTitle("> 1950"); string tempFile = Path.Combine(Path.GetTempPath(), "persons_pre50_post50.xlsx"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- byte[] result = worksheetWrapper.ToXlsx(); File.WriteAllBytes(tempFile, result); var excelPackage = new ExcelPackage(new FileInfo(tempFile)); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- excelPackage.Workbook.Worksheets.Count().Should().Be(2); excelPackage.Workbook.Worksheets[1].Dimension.Rows.Should().Be(4); excelPackage.Workbook.Worksheets[2].Dimension.Rows.Should().Be(5); }
public void Should_convert_a_worksheet_to_byte_array_of_xlsx_file() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- List <Person> post50 = _personList.Where(x => x.YearBorn > 1950).ToList(); string tempFile = Path.Combine(Path.GetTempPath(), "persons_post50.xlsx"); WorksheetWrapper <Person> worksheetWrapper = post50.ToWorksheet("> 1950"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- byte[] result = worksheetWrapper.ToXlsx(); File.WriteAllBytes(tempFile, result); var excelPackage = new ExcelPackage(new FileInfo(tempFile)); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- excelPackage.Workbook.Worksheets.Any().Should().Be(true); excelPackage.Workbook.Worksheets.First().Dimension.Rows.Should().Be(4); }