mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-11 13:53:20 +00:00
Added -NoHeader and returns .Value
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user