Explorar el Código

Improved on start from

Piotr Czajkowski hace 4 meses
padre
commit
8d9e97f5ed

+ 3 - 2
ExcelInfo/ExcelInfo/WorkbookInfo.cs

@@ -4,7 +4,7 @@ namespace ExcelInfo
 {
     public static class WorkbookInfo
     {
-        private static XLDataType EstablishType(IXLCells? cells)
+        private static XLDataType EstablishType(IEnumerable<IXLCell>? cells)
         {
             if (cells == null || !cells.Any())
                 return XLDataType.Error;
@@ -30,7 +30,8 @@ namespace ExcelInfo
                 
                 foreach (var cell in firstRow.CellsUsed())
                 {
-                    var columnCells = cell.WorksheetColumn().CellsUsed();
+                    var columnCells = cell.WorksheetColumn().Cells()
+                        .Where(x => x.Address.RowNumber > firstRow.RowNumber());
                     var cellsType = EstablishType(columnCells);
                     columns.Add(new ColumnInfo(cell.Address.ColumnLetter, cell.Value.ToString(), columnCells.Count() - 1, cellsType, cell.Address.ColumnNumber));
                 }

+ 3 - 4
ExcelInfo/ExcelInfoTests/ExcelInfoTests.csproj

@@ -22,14 +22,13 @@
         </PackageReference>
     </ItemGroup>
 
-    <ItemGroup>
-      <Folder Include="testFiles\" />
-    </ItemGroup>
-
     <ItemGroup>
       <None Update="testFiles\differentTypes.xlsx">
         <CopyToOutputDirectory>Always</CopyToOutputDirectory>
       </None>
+      <None Update="testFiles\differentTypesStartFrom.xlsx">
+        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+      </None>
     </ItemGroup>
 
     <ItemGroup>

+ 11 - 0
ExcelInfo/ExcelInfoTests/WorkbookInfoTests.cs

@@ -5,6 +5,8 @@ namespace ExcelInfoTests;
 public class WorkbookInfoTests
 {
     private const string DifferentTypesFile = "testFiles/differentTypes.xlsx";
+    private const string DifferentTypesFileStartFrom = "testFiles/differentTypesStartFrom.xlsx";
+    
     [Fact]
     public void GetInfoOnWorksheets()
     {
@@ -13,4 +15,13 @@ public class WorkbookInfoTests
         Assert.NotEqual(result.First(), result.Last());
         Assert.NotEqual(result.First().Columns, result.Last().Columns);
     }
+    
+    [Fact]
+    public void GetInfoOnWorksheetsStartFrom()
+    {
+        var result = WorkbookInfo.GetInfoOnWorksheets(DifferentTypesFileStartFrom, 2).ToList();
+        Assert.Equal(2, result.Count());
+        Assert.NotEqual(result.First(), result.Last());
+        Assert.NotEqual(result.First().Columns, result.Last().Columns);
+    }
 }

BIN
ExcelInfo/ExcelInfoTests/testFiles/differentTypesStartFrom.xlsx