mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-14 23:33:18 +00:00
Sync to Doug's 6.5.3 release
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
function Import-Excel {
|
function Import-Excel {
|
||||||
|
[CmdLetBinding()]
|
||||||
[CmdLetBinding()]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")]
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSPossibleIncorrectUsageOfAssignmentOperator', '', Justification = 'Intentional')]
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSPossibleIncorrectUsageOfAssignmentOperator', '', Justification = 'Intentional')]
|
param (
|
||||||
Param (
|
|
||||||
[Alias('FullName')]
|
[Alias('FullName')]
|
||||||
[Parameter(ParameterSetName = "PathA", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
|
[Parameter(ParameterSetName = "PathA", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
|
||||||
[Parameter(ParameterSetName = "PathB", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
|
[Parameter(ParameterSetName = "PathB", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
|
||||||
[Parameter(ParameterSetName = "PathC", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
|
[Parameter(ParameterSetName = "PathC", Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, Position = 0 )]
|
||||||
[String]$Path,
|
[String[]]$Path,
|
||||||
[Parameter(ParameterSetName = "PackageA", Mandatory)]
|
[Parameter(ParameterSetName = "PackageA", Mandatory)]
|
||||||
[Parameter(ParameterSetName = "PackageB", Mandatory)]
|
[Parameter(ParameterSetName = "PackageB", Mandatory)]
|
||||||
[Parameter(ParameterSetName = "PackageC", Mandatory)]
|
[Parameter(ParameterSetName = "PackageC", Mandatory)]
|
||||||
@@ -37,55 +36,61 @@
|
|||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[String]$Password
|
[String]$Password
|
||||||
)
|
)
|
||||||
begin {
|
end {
|
||||||
$sw = [System.Diagnostics.Stopwatch]::StartNew()
|
$sw = [System.Diagnostics.Stopwatch]::StartNew()
|
||||||
|
if ($input) {
|
||||||
|
$Paths = $input
|
||||||
|
}
|
||||||
|
elseif ($Path) {
|
||||||
|
$Paths = $Path
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$Paths = ''
|
||||||
|
}
|
||||||
|
Function Get-PropertyNames {
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Create objects containing the column number and the column name for each of the different header types.
|
||||||
|
#>
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = "Name would be incorrect, and command is not exported")]
|
||||||
|
Param (
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[Int[]]$Columns,
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[Int]$StartRow
|
||||||
|
)
|
||||||
|
|
||||||
Function Get-PropertyNames {
|
Try {
|
||||||
<#
|
if ($HeaderName) {
|
||||||
.SYNOPSIS
|
$i = 0
|
||||||
Create objects containing the column number and the column name for each of the different header types.
|
foreach ($H in $HeaderName) {
|
||||||
#>
|
$H | Select-Object @{N = 'Column'; E = { $Columns[$i] } }, @{N = 'Value'; E = { $H } }
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = "Name would be incorrect, and command is not exported")]
|
$i++
|
||||||
Param (
|
|
||||||
[Parameter(Mandatory)]
|
|
||||||
[Int[]]$Columns,
|
|
||||||
[Parameter(Mandatory)]
|
|
||||||
[Int]$StartRow
|
|
||||||
)
|
|
||||||
|
|
||||||
Try {
|
|
||||||
if ($HeaderName) {
|
|
||||||
$i = 0
|
|
||||||
foreach ($H in $HeaderName) {
|
|
||||||
$H | Select-Object @{N = 'Column'; E = { $Columns[$i] } }, @{N = 'Value'; E = { $H } }
|
|
||||||
$i++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif ($NoHeader) {
|
|
||||||
$i = 0
|
|
||||||
foreach ($C in $Columns) {
|
|
||||||
$i++
|
|
||||||
$C | Select-Object @{N = 'Column'; E = { $_ } }, @{N = 'Value'; E = { 'P' + $i } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
if ($StartRow -lt 1) {
|
|
||||||
throw 'The top row can never be less than 1 when we need to retrieve headers from the worksheet.' ; return
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($C in $Columns) {
|
|
||||||
$Worksheet.Cells[$StartRow, $C] | Where-Object { $_.Value } | Select-Object @{N = 'Column'; E = { $C } }, Value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Catch {
|
elseif ($NoHeader) {
|
||||||
throw "Failed creating property names: $_" ; return
|
$i = 0
|
||||||
|
foreach ($C in $Columns) {
|
||||||
|
$i++
|
||||||
|
$C | Select-Object @{N = 'Column'; E = { $_ } }, @{N = 'Value'; E = { 'P' + $i } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
if ($StartRow -lt 1) {
|
||||||
|
throw 'The top row can never be less than 1 when we need to retrieve headers from the worksheet.' ; return
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($C in $Columns) {
|
||||||
|
$Worksheet.Cells[$StartRow, $C] | Where-Object { $_.Value } | Select-Object @{N = 'Column'; E = { $C } }, Value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Catch {
|
||||||
|
throw "Failed creating property names: $_" ; return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
foreach ($Path in $Paths) {
|
||||||
process {
|
|
||||||
if ($path) {
|
if ($path) {
|
||||||
$extension = [System.IO.Path]::GetExtension($Path)
|
$extension = [System.IO.Path]::GetExtension($Path)
|
||||||
if ($extension -notmatch '.xlsx$|.xlsm$') {
|
if ($extension -notmatch '.xlsx$|.xlsm$') {
|
||||||
@@ -193,4 +198,5 @@
|
|||||||
if ($Path) { $stream.close(); $ExcelPackage.Dispose() }
|
if ($Path) { $stream.close(); $ExcelPackage.Dispose() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
RootModule = 'ImportExcel.psm1'
|
RootModule = 'ImportExcel.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '6.5.2'
|
ModuleVersion = '6.5.3'
|
||||||
|
|
||||||
# ID used to uniquely identify this module
|
# ID used to uniquely identify this module
|
||||||
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -60,6 +60,19 @@ Plus, wiring the [PowerShell ScriptAnalyzer Excel report](https://github.com/dfi
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
# What's new 6.5.3
|
||||||
|
|
||||||
|
Thanks again to the community for making this module even better.
|
||||||
|
|
||||||
|
- [Fix import excel headers](https://github.com/dfinke/ImportExcel/pull/713)
|
||||||
|
- Numerous improvements for DataTables and exporting it to Excel [James O'Neill](https://twitter.com/jamesoneill)
|
||||||
|
- Names, styles, proper appending
|
||||||
|
- Handles marking the empty row on an empty table as dummy row
|
||||||
|
- Re-work code based on linting recommendations
|
||||||
|
- Update existing tests and add more
|
||||||
|
- Support PipelineVariable thanks to [Luc Dekens](https://twitter.com/LucD22) for reporting and [Ili](https://twitter.com/ili_z) for the PR
|
||||||
|
- Fix quoting in ConvertFromExcelToSQLInsert [beckerben](https://github.com/beckerben)
|
||||||
|
|
||||||
# What's new 6.5.2
|
# What's new 6.5.2
|
||||||
|
|
||||||
Thank you [uSlackr](https://github.com/uSlackr)ill
|
Thank you [uSlackr](https://github.com/uSlackr)ill
|
||||||
|
|||||||
@@ -42,4 +42,25 @@ Describe "Tests" {
|
|||||||
$data[0].p1 | Should be "a"
|
$data[0].p1 | Should be "a"
|
||||||
$data[1].p1 | Should be "b"
|
$data[1].p1 | Should be "b"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Should take Paths from parameter".PadRight(90) {
|
||||||
|
$data = Import-Excel -Path (Get-ChildItem -Path $PSScriptRoot -Filter "TestData?.xlsx").FullName
|
||||||
|
$data.count | Should be 4
|
||||||
|
$data[0].cola | Should be 1
|
||||||
|
$data[2].cola | Should be 5
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should take Paths from pipeline".PadRight(90) {
|
||||||
|
$data = (Get-ChildItem -Path $PSScriptRoot -Filter "TestData?.xlsx").FullName | Import-Excel
|
||||||
|
$data.count | Should be 4
|
||||||
|
$data[0].cola | Should be 1
|
||||||
|
$data[2].cola | Should be 5
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should support PipelineVariable".PadRight(90) {
|
||||||
|
$data = Import-Excel $PSScriptRoot\Simple.xlsx -PipelineVariable 'Pv' | ForEach-Object { $Pv.p1 }
|
||||||
|
$data.count | Should be 2
|
||||||
|
$data[0] | Should be "a"
|
||||||
|
$data[1] | Should be "b"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
BIN
__tests__/ImportExcelTests/TestData1.xlsx
Normal file
BIN
__tests__/ImportExcelTests/TestData1.xlsx
Normal file
Binary file not shown.
BIN
__tests__/ImportExcelTests/TestData2.xlsx
Normal file
BIN
__tests__/ImportExcelTests/TestData2.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user