Initial commit

This commit is contained in:
Doug Finke
2015-03-27 13:32:04 -04:00
parent b11aa01e58
commit 29839ea142
5 changed files with 52 additions and 0 deletions

1
.gitignore vendored
View File

@@ -41,3 +41,4 @@ $RECYCLE.BIN/
Network Trash Folder
Temporary Items
.apdisk
InstallModule.ps1

BIN
EPPlus.dll Normal file

Binary file not shown.

44
ImportExcel.psm1 Normal file
View File

@@ -0,0 +1,44 @@
Add-Type -Path "$($PSScriptRoot)\EPPlus.dll"
function Import-Excel {
param(
[Parameter(ValueFromPipelineByPropertyName)]
$FullName,
$Sheet=1,
[string[]]$Header
)
Process {
$FullName = (Resolve-Path $FullName).Path
write-debug "target excel file $($FullName)"
$xl = New-Object OfficeOpenXml.ExcelPackage $FullName
$workbook = $xl.Workbook
$worksheet=$workbook.Worksheets[$Sheet]
$dimension=$worksheet.Dimension
$Rows=$dimension.Rows
$Columns=$dimension.Columns
if(!$Header) {
$Header = foreach ($Column in 1..$Columns) {
$worksheet.Cells[1,$Column].Text
}
}
foreach ($Row in 2..$Rows) {
$h=[Ordered]@{}
foreach ($Column in 0..($Columns-1)) {
$Name = $Header[$Column]
$h.$Name = $worksheet.Cells[$Row,($Column+1)].Text
}
[PSCustomObject]$h
}
$xl.Dispose()
$xl = $null
}
}

7
TryEPPlus.ps1 Normal file
View File

@@ -0,0 +1,7 @@
#cls
import-module
#Import-Excel .\Book1.xlsx |ft
#Import-Excel .\TestRead.xlsx
#Import-Excel .\testImport.xlsx 1 (echo a b c d) | Out-String
#Import-Excel .\testImport.xlsx 2 (echo e f g h) | Out-String

BIN
testImport.xlsx Normal file

Binary file not shown.