perf: removed verbose from loop in import. tests: better alias check

This commit is contained in:
jhoneill
2018-10-04 21:31:47 +01:00
parent 66f5d09ace
commit 91a7c17341
2 changed files with 14 additions and 11 deletions

View File

@@ -327,11 +327,11 @@ function Import-Excel {
$Path = (Resolve-Path $Path).ProviderPath
Write-Verbose "Import Excel workbook '$Path' with worksheet '$Worksheetname'"
$Stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, 'Open', 'Read', 'ReadWrite'
}
Catch {throw "Could not open $Path ; $_ "}
}
Catch {throw "Could not open $Path ; $_ "}
if ($Password) {
Try {$Excel = New-Object -TypeName OfficeOpenXml.ExcelPackage
Try {$Excel = New-Object -TypeName OfficeOpenXml.ExcelPackage
$excel.Load( $Stream,$Password)}
Catch { throw "Could not read $Path with the provided password." }
}
@@ -394,12 +394,13 @@ function Import-Excel {
else {
#region Create one object per row
foreach ($R in $Rows) {
Write-Verbose "Import row '$R'"
#Disabled write-verbose for speed
# Write-Verbose "Import row '$R'"
$NewRow = [Ordered]@{}
foreach ($P in $PropertyNames) {
$NewRow[$P.Value] = $Worksheet.Cells[$R, $P.Column].Value
Write-Verbose "Import cell '$($Worksheet.Cells[$R, $P.Column].Address)' with property name '$($p.Value)' and value '$($Worksheet.Cells[$R, $P.Column].Value)'."
# Write-Verbose "Import cell '$($Worksheet.Cells[$R, $P.Column].Address)' with property name '$($p.Value)' and value '$($Worksheet.Cells[$R, $P.Column].Value)'."
}
[PSCustomObject]$NewRow

View File

@@ -1,26 +1,28 @@
#Requires -Modules Pester
remove-module importExcel -erroraction silentlyContinue
Import-Module $PSScriptRoot\..\ImportExcel.psd1 -Force
Describe "Check if Function aliases exist" {
It "Set-Column should exist" {
Get-Command Set-Column | Should Not Be $null
${Alias:Set-Column} | Should Not BeNullOrEmpty
}
It "Set-Row should exist" {
Get-Command Set-Row | Should Not Be $null
${Alias:Set-Row} | Should Not BeNullOrEmpty
}
It "Set-Format should exist" {
Get-Command Set-Format | Should Not Be $null
${Alias:Set-Format} | Should Not BeNullOrEmpty
}
It "Merge-MulipleSheets should exist" {
<#It "Merge-MulipleSheets should exist" {
Get-Command Merge-MulipleSheets | Should Not Be $null
}
#>
It "New-ExcelChart should exist" {
Get-Command New-ExcelChart | Should Not Be $null
${Alias:New-ExcelChart} | Should Not BeNullOrEmpty
}
}