From 434a3e5180647eeb1dd539b630e7cdc85a48acb0 Mon Sep 17 00:00:00 2001 From: Francois Lachance-Guillemette Date: Fri, 21 Aug 2015 11:18:09 -0400 Subject: [PATCH] Added Reading in ConvertFrom-ExcelSheet + ... Streamlined parameters in Import-Excel (still compatible) --- ImportExcel.psm1 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 83ace78..14a00fc 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -2,20 +2,20 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll" function Import-Excel { param( - [Parameter(ValueFromPipelineByPropertyName=$true)] - $FullName, + [Alias("FullName")] + [Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory)] + $Path, $Sheet=1, [string[]]$Header ) Process { - $FullName = (Resolve-Path $FullName).Path - write-debug "target excel file $FullName" + $Path = (Resolve-Path $Path).Path + write-debug "target excel file $Path" - $stream = New-Object System.IO.FileStream $FullName,"Open","Read","ReadWrite" - - $xl = New-Object OfficeOpenXml.ExcelPackage $stream + $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,"Open","Read","ReadWrite" + $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream $workbook = $xl.Workbook @@ -344,7 +344,8 @@ function ConvertFrom-ExcelSheet { ) $Path = (Resolve-Path $Path).Path - $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path + $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,"Open","Read","ReadWrite" + $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream $workbook = $xl.Workbook $targetSheets = $workbook.Worksheets | Where {$_.Name -like $SheetName}