Ejemplo n.º 1
0
        public void Should_get_worksheet_as_enumerable()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            ExcelWorksheet worksheet1 = excelPackage1.GetWorksheet("TEST4");
            ExcelWorksheet worksheet2 = excelPackage1.GetWorksheet("TEST5");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable <StocksNullable> list1 = worksheet1.AsEnumerable <StocksNullable>(configuration =>
            {
                configuration.SkipCastingErrors();
                configuration.SkipValidationErrors();
                configuration.WithoutHeaderRow();
            });

            IEnumerable <StocksNullable> list2 = worksheet2.AsEnumerable <StocksNullable>(configuration =>
            {
                configuration.SkipCastingErrors();
                configuration.SkipValidationErrors();
                configuration.WithoutHeaderRow();
            });

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            list1.Count().Should().Be(4, "Should have four");
            list2.Count().Should().Be(4, "Should have four");
        }
        public void Test_Worksheet_AsEnumerable()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            ExcelWorksheet worksheet1 = excelPackage.Workbook.Worksheets["TEST4"];
            ExcelWorksheet worksheet2 = excelPackage.Workbook.Worksheets["TEST5"];

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable <StocksNullable> list1 = worksheet1.AsEnumerable <StocksNullable>(null, configuration =>
            {
                configuration.SkipCastingErrors = true;
                configuration.HasHeaderRow      = true;
            });
            IEnumerable <StocksNullable> list2 = worksheet2.AsEnumerable <StocksNullable>(null, configuration =>
            {
                configuration.SkipCastingErrors = true;
                configuration.HasHeaderRow      = false;
            });

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            list1.Count().Should().Be(4, "Should have four");
            list2.Count().Should().Be(4, "Should have four");
        }
Ejemplo n.º 3
0
        public void Test_Worksheet_AsEnumerable()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            ExcelWorksheet worksheet1 = excelPackage.Workbook.Worksheets["TEST4"];
            ExcelWorksheet worksheet2 = excelPackage.Workbook.Worksheets["TEST5"];

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable <StocksNullable> list1 = worksheet1.AsEnumerable <StocksNullable>(true);
            IEnumerable <StocksNullable> list2 = worksheet2.AsEnumerable <StocksNullable>(true, false);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            list1.Count().Should().Be(4, "Should have four");
            list2.Count().Should().Be(4, "Should have four");
        }
Ejemplo n.º 4
0
 /// <summary>
 ///     Converts the worksheet into list of objects
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="worksheet"></param>
 /// <param name="configurationAction"></param>
 /// <returns></returns>
 public static List <T> ToList <T>(this ExcelWorksheet worksheet, Action <ExcelReadConfiguration <T> > configurationAction = null) where T : class, new() => worksheet.AsEnumerable(configurationAction).ToList();
 /// <summary>
 ///     Returns objects of specified type from the ExcelWorksheet as a list.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="worksheet"></param>
 /// <param name="onCaught"></param>
 /// <param name="configurationAction"></param>
 /// <returns></returns>
 public static List <T> ToList <T>(this ExcelWorksheet worksheet, OnCaught <T> onCaught = null, Action <IExcelConfiguration <T> > configurationAction = null) where T : class, new()
 {
     return(worksheet.AsEnumerable(onCaught, configurationAction).ToList());
 }
 /// <summary>
 ///     Returns objects of specified type from the ExcelWorksheet as a list.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="worksheet"></param>
 /// <param name="hasHeaderRow"></param>
 /// <param name="skipCastErrors"></param>
 /// <returns></returns>
 public static IList <T> ToList <T>(this ExcelWorksheet worksheet, bool skipCastErrors = false, bool hasHeaderRow = true) where T : class, new()
 {
     return(worksheet.AsEnumerable <T>(skipCastErrors, hasHeaderRow).ToList());
 }