diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 8d4cca9..e385900 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -10,7 +10,8 @@ function Import-Excel { [Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory)] $Path, $Sheet=1, - [string[]]$Header + [string[]]$Header, + [switch]$NoHeader ) Process { @@ -29,21 +30,33 @@ function Import-Excel { $Rows=$dimension.Rows $Columns=$dimension.Columns - if(!$Header) { - $Header = foreach ($Column in 1..$Columns) { - $worksheet.Cells[1,$Column].Text - } - } + if($NoHeader) { + foreach ($Row in 0..($Rows-1)) { + $newRow = [Ordered]@{} + foreach ($Column in 0..($Columns-1)) { + $propertyName = "P$($Column+1)" + $newRow.$propertyName = $worksheet.Cells[($Row+1),($Column+1)].Value + } - foreach ($Row in 2..$Rows) { - $h=[Ordered]@{} - foreach ($Column in 0..($Columns-1)) { - if($Header[$Column].Length -gt 0) { - $Name = $Header[$Column] - $h.$Name = $worksheet.Cells[$Row,($Column+1)].Text + [PSCustomObject]$newRow + } + } else { + if(!$Header) { + $Header = foreach ($Column in 1..$Columns) { + $worksheet.Cells[1,$Column].Text } } - [PSCustomObject]$h + + foreach ($Row in 2..$Rows) { + $h=[Ordered]@{} + foreach ($Column in 0..($Columns-1)) { + if($Header[$Column].Length -gt 0) { + $Name = $Header[$Column] + $h.$Name = $worksheet.Cells[$Row,($Column+1)].Value + } + } + [PSCustomObject]$h + } } $stream.Close() diff --git a/README.md b/README.md index 8867465..5bfca1f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -PowerShell Import-Excel +goPowerShell Import-Excel - This PowerShell Module wraps the .NET [EPPlus DLL](http://epplus.codeplex.com/) (included). Easily integrate reading and writing Excel spreadsheets into PowerShell, without launching Excel in the background. You can also automate the creation of Pivot Tables and Charts. @@ -24,6 +24,12 @@ Know Issues What's new - +#### 10/15/2015 + +`Import-Excel` has a new parameter `NoHeader`. If data in the sheet does not have headers and you don't want to supply your own, `Import-Excel` will generate the property name. + +`Import-Excel` now returns `.Value` rather than `.Text` + #### 10/1/2015