File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,3 +41,4 @@ $RECYCLE.BIN/
4141Network Trash Folder
4242Temporary Items
4343.apdisk
44+ InstallModule.ps1
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments