Exclude Property in Export-Excel now supports wildcards

This commit is contained in:
jhoneill
2018-08-07 16:16:45 +01:00
parent 5a235e309e
commit c1604fc08a
4 changed files with 14 additions and 12 deletions

View File

@@ -636,7 +636,7 @@
catch {Write-Warning "Could not insert value at Row $Row. "}
}
else {
#region Add headers
#region Add headers - if we are appending, or we have been through here once already we will have the headers
if (-not $script:Header) {
$ColumnIndex = $StartColumn
if ($DisplayPropertySet -and $TargetData.psStandardmembers.DefaultDisplayPropertySet.ReferencedPropertyNames) {
@@ -644,8 +644,9 @@
}
else {
if ($NoAliasOrScriptPropeties) {$propType = "Property"} else {$propType = "*"}
$script:Header = $TargetData.PSObject.Properties.where( {$_.MemberType -like $propType -and $_.Name -notin $ExcludeProperty}).Name
$script:Header = $TargetData.PSObject.Properties.where( {$_.MemberType -like $propType}).Name
}
foreach ($exclusion in $ExcludeProperty) {$script:Header = $script:Header -notlike $exclusion}
if ($NoHeader) {
# Don't push the headers to the spreadsheet
$Row -= 1
@@ -659,18 +660,17 @@
}
}
#endregion
#region Add non header values
$Row += 1
$ColumnIndex = $StartColumn
foreach ($Name in $script:Header) {
#region Add non header values
try {Add-CellValue -TargetCell $ws.Cells[$Row, $ColumnIndex] -CellValue $TargetData.$Name}
catch {Write-Warning -Message "Could not insert the $Name property at Row $Row, Column $Column"}
$ColumnIndex += 1
#endregion
}
$ColumnIndex -= 1 # column index will be the last column whether isDataTypeValueType was true or false
#endregion
}
}
Catch {

View File

@@ -53,11 +53,12 @@ Install-Module ImportExcel
```
# New Aug 3rd -
- Fixed bug where Export-Excel would not recognise it had to set $TitleFillPattern - made the default 'Solid'
- Gave Expand-NumberFormat a better grasp of currency layouts.
- ExcludeProperty in Export-Excel now supports wildcards.
- Added DateTime to the list of types which can be exported as single column.
- Addded Password support to Open- and Close-ExcelPackage (password was not doing anything in Export-Excel)
- Gave Expand-NumberFormat a better grasp of currency layouts - it follows .NET which is not always the same as Excel would set:-(
# What's new to 2nd Aug 2018
# What's new in Release 5.1.1
- Set-Row and Set-Column will now create hyperlinks and insert dates correctly
- Import-Excel now has an argument completer for Worksheet name - this can be slow on large files
- The NumberFormat parameter (in Export-Excel, Set-Row, Set-Column, Set-Format and Add-ConditionalFormat) and X&YAxisNumberFormat paramaters (in New-ExcelChartDefinition and Add-ExcelChart) now have an argument completer and the names Currency, Number, Percentage, Scientific, Fraction, Short Date ,Short time,Long time, Date-Time and Text will be converted to the correct Excel formatting strings.

View File

@@ -1,13 +1,14 @@
- [x] Create an autocomplete for WorkSheetName param on ImportExcel and for number format ; where number format exists Translate "Date", "DateTime", "Currency"
- [x] Support "make worksheet active"
- [X] Add checks for valid worksheet names
- [x] Allow Exclude property to take wildcards
- [ ] Improve checking of worksheet, pivot names, range names and table names
- [ ] Allow Exclude property to take wildcards
- [ ] Investigate regional support for number conversion & possible date conversion. Also investigate feasablity of preserving number format when converting string to number
- [ ] Add help text for parmaters which don't have it ( PivotDataToColumn , NoClobber and CellStyleSB ) in Export Excel, copy to Send-SQLDataToExcel
- [ ] Add help in ConvertToExcelXLSx.ps1, Get-HTMLTable.ps1, GetRange.PS1, GetExcelTable.Ps1, Import-HTML.PS1, New-ConditionalFormattingIconSet.Ps1, NewConditionalText.PS1, New-Psitem.PS1, Remove-Worksheet.ps1 and Add-ExcelChart - Copy parameter help from function Add-ExcelChart into New-ExcelChart.ps1
- [ ] Add examples to add-ConditionalFormat, set-format,set-Row and Set-column (e.g. from tests)
- [ ] Add Examples and tests for new "Quick charts" in Export Excel (replace examples) that use Charting.ps1, GetXYRange.ps1, InferData.PS1 (move these to deprecated).
- [X] Test password behaviour in Export-Excel Open & Close-Excel Package
- [X] Test Add PivotTable selecting source sheet by position
-[X] Test UnhideSheet, and Wildcard support for hideSheet
- [X] Test return range support for Set-Row

View File

@@ -50,7 +50,7 @@ Describe ExportExcel {
}
}
it "Formatted the process StartTime field as 'localized Date-Time' " {
it "Formatted the process StartTime field as 'localized Date-Time' " {
$STHeader = $ws.cells["1:1"].where( {$_.Value -eq "StartTime"})[0]
$STCell = $STHeader.Address -replace '1$', '2'
$ws.cells[$stcell].Style.Numberformat.NumFmtID | Should be 22
@@ -75,7 +75,7 @@ Describe ExportExcel {
$Excel = Open-ExcelPackage -Path $path
$ws = $Excel.Workbook.Worksheets[1]
it "Created a new file with alias & Script Properties removed. " {
it "Created a new file with Alias & Script Properties removed. " {
$ws.Name | Should be "sheet1"
$ws.Dimension.Columns | Should be $propertyNames.Count
$ws.Dimension.Rows | Should be ($rowcount + 1 ) # +1 for the header.
@@ -87,13 +87,13 @@ Describe ExportExcel {
$warnVar.Count | Should be 1
}
#This time use clearsheet instead of deleting the file
$Processes | Export-Excel $path -NoAliasOrScriptPropeties -ExcludeProperty SafeHandle, modules, MainModule, StartTime, Threads -ClearSheet
$Processes | Export-Excel $path -ClearSheet -NoAliasOrScriptPropeties -ExcludeProperty SafeHandle, threads, modules, MainModule, StartInfo, MachineName, MainWindow*, M*workingSet
$Excel = Open-ExcelPackage -Path $path
$ws = $Excel.Workbook.Worksheets[1]
it "Created a new file with a further 5 properties excluded and cleared the old sheet " {
$ws.Name | Should be "sheet1"
$ws.Dimension.Columns | Should be ($propertyNames.Count - 5)
$ws.Dimension.Columns | Should be ($propertyNames.Count - 10)
$ws.Dimension.Rows | Should be ($rowcount + 1) # +1 for the header
}