Skip to content

Commit 29839ea

Browse files
committed
Initial commit
1 parent b11aa01 commit 29839ea

5 files changed

Lines changed: 52 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ $RECYCLE.BIN/
4141
Network Trash Folder
4242
Temporary Items
4343
.apdisk
44+
InstallModule.ps1

EPPlus.dll

1.14 MB
Binary file not shown.

ImportExcel.psm1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Add-Type -Path "$($PSScriptRoot)\EPPlus.dll"
2+
3+
function Import-Excel {
4+
param(
5+
[Parameter(ValueFromPipelineByPropertyName)]
6+
$FullName,
7+
$Sheet=1,
8+
[string[]]$Header
9+
)
10+
11+
Process {
12+
13+
$FullName = (Resolve-Path $FullName).Path
14+
write-debug "target excel file $($FullName)"
15+
16+
$xl = New-Object OfficeOpenXml.ExcelPackage $FullName
17+
18+
$workbook = $xl.Workbook
19+
20+
$worksheet=$workbook.Worksheets[$Sheet]
21+
$dimension=$worksheet.Dimension
22+
23+
$Rows=$dimension.Rows
24+
$Columns=$dimension.Columns
25+
26+
if(!$Header) {
27+
$Header = foreach ($Column in 1..$Columns) {
28+
$worksheet.Cells[1,$Column].Text
29+
}
30+
}
31+
32+
foreach ($Row in 2..$Rows) {
33+
$h=[Ordered]@{}
34+
foreach ($Column in 0..($Columns-1)) {
35+
$Name = $Header[$Column]
36+
$h.$Name = $worksheet.Cells[$Row,($Column+1)].Text
37+
}
38+
[PSCustomObject]$h
39+
}
40+
41+
$xl.Dispose()
42+
$xl = $null
43+
}
44+
}

TryEPPlus.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#cls
2+
3+
import-module
4+
#Import-Excel .\Book1.xlsx |ft
5+
#Import-Excel .\TestRead.xlsx
6+
#Import-Excel .\testImport.xlsx 1 (echo a b c d) | Out-String
7+
#Import-Excel .\testImport.xlsx 2 (echo e f g h) | Out-String

testImport.xlsx

8.12 KB
Binary file not shown.

0 commit comments

Comments
 (0)