mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 07:43:23 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abdd37b09e | ||
|
|
e1e855a823 | ||
|
|
585d9686a6 | ||
|
|
e87a6bdaf5 | ||
|
|
5ded5111b4 | ||
|
|
914c61048b | ||
|
|
25fb76d9b7 | ||
|
|
7faa27a3b3 | ||
|
|
5700be0684 | ||
|
|
6d86108060 | ||
|
|
4581c2b3e9 | ||
|
|
142c31ccc1 |
@@ -4,7 +4,7 @@
|
||||
RootModule = 'ImportExcel.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '6.2.1'
|
||||
ModuleVersion = '6.2.2'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
||||
|
||||
@@ -269,7 +269,6 @@ function Import-Excel {
|
||||
[Parameter(ParameterSetName = "PathA", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
|
||||
[Parameter(ParameterSetName = "PathB", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
|
||||
[Parameter(ParameterSetName = "PathC", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
|
||||
[ValidateScript( {(Test-Path -Path $_ -PathType Leaf) -and ($_ -match '.xls$|.xlsx$|.xlsm$')})]
|
||||
[String]$Path,
|
||||
[Parameter(ParameterSetName = "PackageA", Mandatory)]
|
||||
[Parameter(ParameterSetName = "PackageB", Mandatory)]
|
||||
@@ -300,6 +299,7 @@ function Import-Excel {
|
||||
)
|
||||
begin {
|
||||
$sw = [System.Diagnostics.Stopwatch]::StartNew()
|
||||
|
||||
Function Get-PropertyNames {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
@@ -346,6 +346,19 @@ function Import-Excel {
|
||||
|
||||
process {
|
||||
if ($path) {
|
||||
$extension = [System.IO.Path]::GetExtension($Path)
|
||||
if ($extension -notmatch '.xlsx$|.xlsm$') {
|
||||
throw "Import-Excel does not support reading this extension type $($extension)"
|
||||
}
|
||||
|
||||
$resolvedPath = (Resolve-Path $Path -ErrorAction SilentlyContinue)
|
||||
if ($resolvedPath) {
|
||||
$Path = $resolvedPath.ProviderPath
|
||||
}
|
||||
else {
|
||||
throw "'$($Path)' file not found"
|
||||
}
|
||||
|
||||
$stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, 'Open', 'Read', 'ReadWrite'
|
||||
if ($Password) { $ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream , $Password }
|
||||
else { $ExcelPackage = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream }
|
||||
@@ -382,7 +395,7 @@ function Import-Excel {
|
||||
else {
|
||||
$Columns = $StartColumn .. $EndColumn ; if ($StartColumn -gt $EndColumn) { Write-Warning -Message "Selecting columns $StartColumn to $EndColumn might give odd results." }
|
||||
if ($NoHeader) { $Rows = $StartRow..$EndRow ; if ($StartRow -gt $EndRow) { Write-Warning -Message "Selecting rows $StartRow to $EndRow might give odd results." } }
|
||||
else {$Rows = (1 + $StartRow)..$EndRow ; if ($StartRow -ge $EndRow) {Write-Warning -Message "Selecting $StartRow as the header with data in $(1+$StartRow) to $EndRow might give odd results."}}
|
||||
else { $Rows = (1 + $StartRow)..$EndRow } # ; if ($StartRow -ge $EndRow) { Write-Warning -Message "Selecting $StartRow as the header with data in $(1+$StartRow) to $EndRow might give odd results." } }
|
||||
}
|
||||
#endregion
|
||||
#region Create property names
|
||||
|
||||
11
README.md
11
README.md
@@ -53,6 +53,17 @@ Install-Module ImportExcel -scope CurrentUser
|
||||
Install-Module ImportExcel
|
||||
```
|
||||
|
||||
# What's new 6.2.1
|
||||
|
||||
- Added requested feature, chart trendlines.
|
||||
- [Example PowerShell script](https://github.com/dfinke/ImportExcel/blob/master/Examples/Charts/NumberOfVisitors.ps1)
|
||||
|
||||

|
||||
|
||||
# What's new 6.2.2
|
||||
|
||||
- Fixed Import-Excel and relative path issue, added unit tests.
|
||||
|
||||
# What's new 6.2.0
|
||||
Thank you to [James O'Neill](https://github.com/jhoneill)
|
||||
|
||||
|
||||
38
__tests__/Path.tests.ps1
Normal file
38
__tests__/Path.tests.ps1
Normal file
@@ -0,0 +1,38 @@
|
||||
Describe "Test reading relative paths" {
|
||||
BeforeAll {
|
||||
$script:xlfileName = "TestR.xlsx"
|
||||
@{data = 1 } | Export-Excel "$pwd\TestR.xlsx"
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
Remove-Item "$pwd\$($script:xlfileName)"
|
||||
}
|
||||
|
||||
It "Should read local file" {
|
||||
$actual = Import-Excel -Path ".\$($script:xlfileName)"
|
||||
$actual | Should Not Be $null
|
||||
$actual.Count | Should Be 1
|
||||
}
|
||||
|
||||
It "Should read with pwd" {
|
||||
$actual = Import-Excel -Path "$pwd\$($script:xlfileName)"
|
||||
$actual | Should Not Be $null
|
||||
}
|
||||
|
||||
It "Should read with just a file name and resolve to cwd" {
|
||||
$actual = Import-Excel -Path "$($script:xlfileName)"
|
||||
$actual | Should Not Be $null
|
||||
}
|
||||
|
||||
It "Should fail for not found" {
|
||||
{ Import-Excel -Path "ExcelFileDoesNotExist.xlsx" } | Should Throw "'ExcelFileDoesNotExist.xlsx' file not found"
|
||||
}
|
||||
|
||||
It "Should fail for xls extension" {
|
||||
{ Import-Excel -Path "ExcelFileDoesNotExist.xls" } | Should Throw "Import-Excel does not support reading this extension type .xls"
|
||||
}
|
||||
|
||||
It "Should fail for xlsxs extension" {
|
||||
{ Import-Excel -Path "ExcelFileDoesNotExist.xlsxs" } | Should Throw "Import-Excel does not support reading this extension type .xlsxs"
|
||||
}
|
||||
}
|
||||
BIN
__tests__/testRelative.xlsx
Normal file
BIN
__tests__/testRelative.xlsx
Normal file
Binary file not shown.
BIN
images/ChartTrendlines.png
Normal file
BIN
images/ChartTrendlines.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 96 KiB |
Reference in New Issue
Block a user