mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-14 23:33:18 +00:00
Spike to fix #792
This commit is contained in:
@@ -142,7 +142,14 @@
|
|||||||
$Columns = $StartColumn .. $EndColumn ; if ($StartColumn -gt $EndColumn) { Write-Warning -Message "Selecting columns $StartColumn to $EndColumn might give odd results." }
|
$Columns = $StartColumn .. $EndColumn ; if ($StartColumn -gt $EndColumn) { Write-Warning -Message "Selecting columns $StartColumn to $EndColumn might give odd results." }
|
||||||
if ($NoHeader) { $Rows = $StartRow..$EndRow ; if ($StartRow -gt $EndRow) { Write-Warning -Message "Selecting rows $StartRow to $EndRow might give odd results." } }
|
if ($NoHeader) { $Rows = $StartRow..$EndRow ; if ($StartRow -gt $EndRow) { Write-Warning -Message "Selecting rows $StartRow to $EndRow might give odd results." } }
|
||||||
elseif ($HeaderName) { $Rows = $StartRow..$EndRow }
|
elseif ($HeaderName) { $Rows = $StartRow..$EndRow }
|
||||||
else { $Rows = (1 + $StartRow)..$EndRow } # ; if ($StartRow -ge $EndRow) { Write-Warning -Message "Selecting $StartRow as the header with data in $(1+$StartRow) to $EndRow might give odd results." } }
|
else {
|
||||||
|
$Rows = (1 + $StartRow)..$EndRow
|
||||||
|
if ($StartRow -eq 1 -and $EndRow -eq 1) {
|
||||||
|
$Rows = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ; if ($StartRow -ge $EndRow) { Write-Warning -Message "Selecting $StartRow as the header with data in $(1+$StartRow) to $EndRow might give odd results." } }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#region Create property names
|
#region Create property names
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
$xlfile = "TestDrive:\testImportExcel.xlsx"
|
$xlfile = "TestDrive:\testImportExcel.xlsx"
|
||||||
|
$xlfileHeaderOnly = "TestDrive:\testImportExcelHeaderOnly.xlsx"
|
||||||
|
|
||||||
Describe "Import-Excel on a sheet with no headings" {
|
Describe "Import-Excel on a sheet with no headings" {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
@@ -18,6 +19,15 @@ Describe "Import-Excel on a sheet with no headings" {
|
|||||||
Set-ExcelRange -Worksheet $xl.Sheet1 -Range C3 -Value 'I'
|
Set-ExcelRange -Worksheet $xl.Sheet1 -Range C3 -Value 'I'
|
||||||
|
|
||||||
Close-ExcelPackage $xl
|
Close-ExcelPackage $xl
|
||||||
|
|
||||||
|
# crate $xlfileHeaderOnly
|
||||||
|
$xl = "" | Export-excel $xlfileHeaderOnly -PassThru
|
||||||
|
|
||||||
|
Set-ExcelRange -Worksheet $xl.Sheet1 -Range A1 -Value 'A'
|
||||||
|
Set-ExcelRange -Worksheet $xl.Sheet1 -Range B1 -Value 'B'
|
||||||
|
Set-ExcelRange -Worksheet $xl.Sheet1 -Range C1 -Value 'C'
|
||||||
|
|
||||||
|
Close-ExcelPackage $xl
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Import-Excel should have this shape" {
|
It "Import-Excel should have this shape" {
|
||||||
@@ -193,4 +203,25 @@ Describe "Import-Excel on a sheet with no headings" {
|
|||||||
# $actual[0].City | Should BeExactly 'Brussels'
|
# $actual[0].City | Should BeExactly 'Brussels'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Should handle data correctly if there is only a single row" {
|
||||||
|
$actual = Import-Excel $xlfileHeaderOnly
|
||||||
|
$names = $actual.psobject.properties.Name
|
||||||
|
$names | should be $null
|
||||||
|
$actual.Count | should be 0
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should handle data correctly if there is only a single row and using -NoHeader " {
|
||||||
|
$actual = @(Import-Excel $xlfileHeaderOnly -WorksheetName Sheet1 -NoHeader)
|
||||||
|
|
||||||
|
$names = $actual[0].psobject.properties.Name
|
||||||
|
$names.count | should be 3
|
||||||
|
$names[0] | should be 'P1'
|
||||||
|
$names[1] | should be 'P2'
|
||||||
|
$names[2] | should be 'P3'
|
||||||
|
|
||||||
|
$actual.Count | should be 1
|
||||||
|
$actual[0].P1 | should be 'A'
|
||||||
|
$actual[0].P2 | should be 'B'
|
||||||
|
$actual[0].P3 | should be 'C'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user