mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-13 23:03:24 +00:00
Add try/catch, warning, and tests
This commit is contained in:
@@ -35,7 +35,12 @@
|
|||||||
if ($pkgobj) {
|
if ($pkgobj) {
|
||||||
foreach ($w in $pkgobj.Workbook.Worksheets) {
|
foreach ($w in $pkgobj.Workbook.Worksheets) {
|
||||||
$sb = [scriptblock]::Create(('$this.workbook.Worksheets["{0}"]' -f $w.name))
|
$sb = [scriptblock]::Create(('$this.workbook.Worksheets["{0}"]' -f $w.name))
|
||||||
Add-Member -InputObject $pkgobj -MemberType ScriptProperty -Name $w.name -Value $sb
|
try {
|
||||||
|
Add-Member -InputObject $pkgobj -MemberType ScriptProperty -Name $w.name -Value $sb -ErrorAction Stop
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "Could not add sheet $($w.name) as 'short cut', you need to access it via `$wb.Worksheets['$($w.name)'] "
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $pkgobj
|
return $pkgobj
|
||||||
}
|
}
|
||||||
|
|||||||
39
__tests__/Open-ExcelPackage.tests.ps1
Normal file
39
__tests__/Open-ExcelPackage.tests.ps1
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#Requires -Modules Pester
|
||||||
|
|
||||||
|
if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) {
|
||||||
|
Import-Module $PSScriptRoot\..\ImportExcel.psd1
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
Methods
|
||||||
|
-------
|
||||||
|
Dispose
|
||||||
|
Equals
|
||||||
|
GetAsByteArray
|
||||||
|
GetHashCode
|
||||||
|
GetType
|
||||||
|
Load
|
||||||
|
Save
|
||||||
|
SaveAs
|
||||||
|
ToString
|
||||||
|
|
||||||
|
Properties
|
||||||
|
----------
|
||||||
|
|
||||||
|
Compatibility
|
||||||
|
Compression
|
||||||
|
DoAdjustDrawings
|
||||||
|
Encryption
|
||||||
|
File
|
||||||
|
Package
|
||||||
|
Stream
|
||||||
|
Workbook
|
||||||
|
#>
|
||||||
|
|
||||||
|
Describe "Test Open Excel Package" -Tag Open-ExcelPackage {
|
||||||
|
It "Should handle opening a workbook with Worksheet Names that will cause errors" {
|
||||||
|
$xlFilename = "$PSScriptRoot\UnsupportedWorkSheetNames.xlsx"
|
||||||
|
|
||||||
|
{ Open-ExcelPackage -Path $xlFilename -ErrorAction Stop } | Should -Not -Throw
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
__tests__/UnsupportedWorkSheetNames.xlsx
Normal file
BIN
__tests__/UnsupportedWorkSheetNames.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user