mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Initial commit
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -41,3 +41,4 @@ $RECYCLE.BIN/
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
InstallModule.ps1
|
||||
|
||||
BIN
EPPlus.dll
Normal file
BIN
EPPlus.dll
Normal file
Binary file not shown.
44
ImportExcel.psm1
Normal file
44
ImportExcel.psm1
Normal 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
7
TryEPPlus.ps1
Normal 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
BIN
testImport.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user