mirror of
https://github.com/dfinke/ImportExcel.git
synced 2026-03-02 11:21:27 +00:00
Allow reading even if file is open by Excel
This commit is contained in:
@@ -12,8 +12,10 @@ function Import-Excel {
|
||||
|
||||
$FullName = (Resolve-Path $FullName).Path
|
||||
write-debug "target excel file $FullName"
|
||||
|
||||
$stream = New-Object System.IO.FileStream $FullName,"Open","Read","ReadWrite"
|
||||
|
||||
$xl = New-Object OfficeOpenXml.ExcelPackage $FullName
|
||||
$xl = New-Object OfficeOpenXml.ExcelPackage $stream
|
||||
|
||||
$workbook = $xl.Workbook
|
||||
|
||||
@@ -39,7 +41,9 @@ function Import-Excel {
|
||||
}
|
||||
[PSCustomObject]$h
|
||||
}
|
||||
|
||||
|
||||
$stream.Close()
|
||||
$stream.Dispose()
|
||||
$xl.Dispose()
|
||||
$xl = $null
|
||||
}
|
||||
|
||||
3
TestImportExcel.ps1
Normal file
3
TestImportExcel.ps1
Normal file
@@ -0,0 +1,3 @@
|
||||
Import-Module "$PSScriptRoot/ImportExcel" -Force
|
||||
|
||||
Import-Excel "$PSScriptRoot/test.xlsx" -ErrorAction Stop
|
||||
Reference in New Issue
Block a user