Beispiel #1
0
        public void CanMakeMultipleSheetWorkbook()
        {
            var objectList1 = new List <TestObject1>
            {
                new TestObject1("Test1-1", 1),
                new TestObject1("Test1-2", 2)
            };

            var objectList2 = new List <TestObject2>
            {
                new TestObject2("Test2-1", 1),
                new TestObject2("Test2-2", 2)
            };

            var sheet1Spec = new ExcelWorksheetSpec <TestObject1>();

            sheet1Spec.AddColumn("Object Name", x => x.ObjectName);
            sheet1Spec.AddColumn("Object Int", x => x.ObjectInt);
            sheet1Spec.AddColumn("Object Date", x => x.ObjectDate);
            sheet1Spec.AddColumn("Object Decimal", x => x.ObjectDecimal);
            sheet1Spec.AddColumn("Object Bool", x => x.ObjectBool);
            var sheetDescription1 = new ExcelWorkbookSheetDescriptor <TestObject1>("SheetName1", sheet1Spec, objectList1);

            var sheet2Spec = new ExcelWorksheetSpec <TestObject2>();

            sheet2Spec.AddColumn("Object Name", x => x.ObjectName);
            sheet2Spec.AddColumn("Object Int", x => x.ObjectInt);
            var sheetDescription2 = new ExcelWorkbookSheetDescriptor <TestObject2>("SheetName2", sheet2Spec, objectList2);

            var sheets = new List <IExcelWorkbookSheetDescriptor> {
                sheetDescription1, sheetDescription2
            };
            var excelWorkbook = new ExcelWorkbookMaker(sheets);

            var wb = excelWorkbook.ToXLWorkbook();

            Assert.That(wb.Worksheets.Count, Is.EqualTo(sheets.Count));
            Assert.That(wb.Worksheets.Select(x => x.Name).ToList(), Is.EquivalentTo(sheets.Select(x => x.WorksheetName).ToList()));

            var xlWorksheets = wb.Worksheets.Select(x => x).ToList();
            var workSheet1   = xlWorksheets[0];

            var firstDataRow = workSheet1.Row(2);

            Assert.That(firstDataRow.Cells().Select(x => x.DataType).ToList(),
                        Is.EquivalentTo(
                            new[]
            {
                XLCellValues.Text, XLCellValues.Number, XLCellValues.DateTime, XLCellValues.Number,
                XLCellValues.Boolean
            }.ToList()), "Data types should match up");
        }
 public static ExcelWorkbookSheetDescriptor <T> MakeWorksheet <T>(string worksheetName, ExcelWorksheetSpec <T> spec, IList <T> dataObjectListForWorksheet)
 {
     return(new ExcelWorkbookSheetDescriptor <T>(worksheetName, spec, dataObjectListForWorksheet));
 }
 public ExcelWorkbookSheetDescriptor(string worksheetName, ExcelWorksheetSpec <T> spec, IList <T> dataObjectListForWorksheet)
 {
     _dataObjectListForWorksheet = dataObjectListForWorksheet;
     _worksheetName = worksheetName.Length > 31 ? worksheetName.Substring(0, 31) : worksheetName; // max 31 chars in worksheet name
     _spec          = spec;
 }
Beispiel #4
0
 public ExcelWorkbookSheetDescriptor(string worksheetName, ExcelWorksheetSpec <T> spec, IList <T> dataObjectListForWorksheet)
 {
     _dataObjectListForWorksheet = dataObjectListForWorksheet;
     _worksheetName = ExcelWorkbookSheetDescriptorFactory.TruncateWorksheetName(worksheetName);
     _spec          = spec;
 }