mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 07:43:23 +00:00
Merge branch 'dfinke:master' into PivotTableUpdates
This commit is contained in:
21
Examples/ConditionalFormatting/GetConditionalFormatting.ps1
Normal file
21
Examples/ConditionalFormatting/GetConditionalFormatting.ps1
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
try { Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 } catch { throw ; return}
|
||||||
|
|
||||||
|
# This example is using Excel generated by Highlight-DiffCells.ps1
|
||||||
|
# The displayed rule should be the same as in the PS script
|
||||||
|
|
||||||
|
function Get-ConditionalFormatting {
|
||||||
|
param (
|
||||||
|
[string] $xlSourcefile
|
||||||
|
)
|
||||||
|
$excel = Open-ExcelPackage -Path $xlSourcefile
|
||||||
|
|
||||||
|
$excel.Workbook.Worksheets | ForEach-Object {
|
||||||
|
$wsNme = $_.Name
|
||||||
|
$_.ConditionalFormatting | ForEach-Object {
|
||||||
|
"Add-ConditionalFormatting -Worksheet `$excel[""$wsNme""] -Range '$($_.Address)' -ConditionValue '=$($_.Formula)' -RuleType $($_.Type) "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$xlSourcefile = "$PSScriptRoot\GetConditionalFormatting.xlsx"
|
||||||
|
Get-ConditionalFormatting -xlSourcefile $xlSourcefile
|
||||||
BIN
Examples/ConditionalFormatting/GetConditionalFormatting.xlsx
Normal file
BIN
Examples/ConditionalFormatting/GetConditionalFormatting.xlsx
Normal file
Binary file not shown.
26
Examples/ConditionalFormatting/Highlight-DiffCells.ps1
Normal file
26
Examples/ConditionalFormatting/Highlight-DiffCells.ps1
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
try { Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 } catch { throw ; return }
|
||||||
|
|
||||||
|
$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx"
|
||||||
|
|
||||||
|
Write-Verbose -Verbose -Message "Save location: $xlSourcefile"
|
||||||
|
Remove-Item $xlSourcefile -ErrorAction Ignore
|
||||||
|
|
||||||
|
$data = ConvertFrom-Csv @"
|
||||||
|
Region,State,Units2021,Units2022
|
||||||
|
West,Texas,927,925
|
||||||
|
North,Tennessee,466,466
|
||||||
|
East,Florida,520,458
|
||||||
|
East,Maine,828,661
|
||||||
|
West,Virginia,465,465
|
||||||
|
North,Missouri,436,235
|
||||||
|
South,Kansas,214,214
|
||||||
|
North,North Dakota,789,640
|
||||||
|
South,Delaware,712,508
|
||||||
|
"@
|
||||||
|
|
||||||
|
$excel = $data | Export-Excel $xlSourcefile -AutoSize -PassThru
|
||||||
|
|
||||||
|
Add-ConditionalFormatting -Worksheet $excel.sheet1 -Range "C2:D10" -ConditionValue '=$C2=$D2' -RuleType Expression -BackgroundColor ([System.Drawing.Color]::Thistle) -Bold
|
||||||
|
Add-ConditionalFormatting -Worksheet $excel.sheet1 -Range "A2:D10" -ConditionValue '=$C2=$D2' -RuleType Expression -BackgroundColor ([System.Drawing.Color]::LavenderBlush)
|
||||||
|
|
||||||
|
Close-ExcelPackage $excel -Show
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
RootModule = 'ImportExcel.psm1'
|
RootModule = 'ImportExcel.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '7.6.0'
|
ModuleVersion = '7.7.0'
|
||||||
|
|
||||||
# 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'
|
||||||
|
|||||||
@@ -110,7 +110,7 @@
|
|||||||
|
|
||||||
#region Apply formatting
|
#region Apply formatting
|
||||||
$params = @{}
|
$params = @{}
|
||||||
foreach ($p in @('Underline','Bold','Italic','StrikeThru', 'FontName', 'FontSize','FontShift','NumberFormat','TextRotation',
|
foreach ($p in @('Underline','UnderLineType','Bold','Italic','StrikeThru', 'FontName', 'FontSize','FontShift','NumberFormat','TextRotation',
|
||||||
'WrapText', 'HorizontalAlignment','VerticalAlignment', 'Autosize', 'Width', 'FontColor'
|
'WrapText', 'HorizontalAlignment','VerticalAlignment', 'Autosize', 'Width', 'FontColor'
|
||||||
'BorderAround', 'BackgroundColor', 'BackgroundPattern', 'PatternColor')) {
|
'BorderAround', 'BackgroundColor', 'BackgroundPattern', 'PatternColor')) {
|
||||||
if ($PSBoundParameters.ContainsKey($p)) {$params[$p] = $PSBoundParameters[$p]}
|
if ($PSBoundParameters.ContainsKey($p)) {$params[$p] = $PSBoundParameters[$p]}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#Requires -Modules Pester
|
#Requires -Modules Pester
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'False Positives')]
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable','',Justification='Only executes on versions without the automatic variable')]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', '', Justification = 'Only executes on versions without the automatic variable')]
|
||||||
param()
|
param()
|
||||||
Describe ExportExcel -Tag "ExportExcel" {
|
Describe ExportExcel -Tag "ExportExcel" {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
@@ -8,7 +8,7 @@ Describe ExportExcel -Tag "ExportExcel" {
|
|||||||
$WarningAction = "SilentlyContinue"
|
$WarningAction = "SilentlyContinue"
|
||||||
. "$PSScriptRoot\Samples\Samples.ps1"
|
. "$PSScriptRoot\Samples\Samples.ps1"
|
||||||
if (-not (Get-command Get-Service -ErrorAction SilentlyContinue)) {
|
if (-not (Get-command Get-Service -ErrorAction SilentlyContinue)) {
|
||||||
Function Get-Service {Import-Clixml $PSScriptRoot\Mockservices.xml}
|
Function Get-Service { Import-Clixml $PSScriptRoot\Mockservices.xml }
|
||||||
}
|
}
|
||||||
if (Get-process -Name Excel, xlim -ErrorAction SilentlyContinue) {
|
if (Get-process -Name Excel, xlim -ErrorAction SilentlyContinue) {
|
||||||
It "Excel is open" {
|
It "Excel is open" {
|
||||||
@@ -389,7 +389,7 @@ Describe ExportExcel -Tag "ExportExcel" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "#Example 5 # Adding a single conditional format "{
|
Context "#Example 5 # Adding a single conditional format " {
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
#Test New-ConditionalText builds correctly
|
#Test New-ConditionalText builds correctly
|
||||||
$ct = New-ConditionalText -ConditionalType GreaterThan 525 -ConditionalTextColor ([System.Drawing.Color]::DarkRed) -BackgroundColor ([System.Drawing.Color]::LightPink)
|
$ct = New-ConditionalText -ConditionalType GreaterThan 525 -ConditionalTextColor ([System.Drawing.Color]::DarkRed) -BackgroundColor ([System.Drawing.Color]::LightPink)
|
||||||
@@ -1081,4 +1081,55 @@ Describe ExportExcel -Tag "ExportExcel" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Context " # Check UnderLineType" -Tag CheckUnderLineType {
|
||||||
|
BeforeAll {
|
||||||
|
$Path = Join-Path (Resolve-Path 'TestDrive:').ProviderPath "testUnderLineType.xlsx"
|
||||||
|
Remove-Item -Path $Path -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
$data = "
|
||||||
|
Set-ExcelRange,Set-ExcelColumn
|
||||||
|
Should be double underlined,Should be double underlined
|
||||||
|
Should be double underlined,Should be double underlined
|
||||||
|
" | ConvertFrom-Csv
|
||||||
|
|
||||||
|
$data | Export-Excel $Path -AutoSize
|
||||||
|
|
||||||
|
$excel = Open-ExcelPackage $Path
|
||||||
|
$ws = $excel.Workbook.Worksheets["sheet1"]
|
||||||
|
|
||||||
|
Set-ExcelRange -Range $ws.Cells["A2:A3"] -Underline -UnderLineType "Double"
|
||||||
|
Set-ExcelColumn -Worksheet $ws -Column 2 -StartRow 2 -Underline -UnderLineType "Double"
|
||||||
|
|
||||||
|
Close-ExcelPackage $excel
|
||||||
|
}
|
||||||
|
|
||||||
|
AfterAll {
|
||||||
|
Remove-Item -Path $Path -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
it "Check Cell Style Font via Set-ExcelColumn".PadRight(87) {
|
||||||
|
$excel = Open-ExcelPackage $Path
|
||||||
|
$cell = $excel.Sheet1.Cells["B2"]
|
||||||
|
|
||||||
|
$actual = $cell.Style.Font
|
||||||
|
|
||||||
|
$actual.Underline | Should -BeTrue
|
||||||
|
$actual.UnderlineType | Should -Be "Double"
|
||||||
|
|
||||||
|
Close-ExcelPackage $excel -NoSave
|
||||||
|
}
|
||||||
|
|
||||||
|
it "Check Cell Style Font via Set-ExcelRange".PadRight(87) {
|
||||||
|
$excel = Open-ExcelPackage $Path
|
||||||
|
$cell = $excel.Sheet1.Cells["A2"]
|
||||||
|
|
||||||
|
$actual = $cell.Style.Font
|
||||||
|
|
||||||
|
$actual.Underline | Should -BeTrue
|
||||||
|
$actual.UnderlineType | Should -Be "Double"
|
||||||
|
|
||||||
|
Close-ExcelPackage $excel -NoSave
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
10
changelog.md
10
changelog.md
@@ -1,3 +1,13 @@
|
|||||||
|
# 7.7.0
|
||||||
|
|
||||||
|
- Fix a bug with `-UnderLineType parameter is ignored in Set-ExcelColumn` [#1204](https://github.com/dfinke/ImportExcel/issues/1204)
|
||||||
|
|
||||||
|
# Example added
|
||||||
|
|
||||||
|
Thank you [@kkazala](https://github.com/kkazala)
|
||||||
|
- Added an example showing `ConditionalFormatting` using the `RuleType` `Expression` with a formula
|
||||||
|
- [Highlight-DiffCells.ps1](https://github.dev/kkazala/ImportExcel/blob/b53881fd023c052da1acc7812511da223bb2e40c/Examples/ConditionalFormatting/Highlight-DiffCells.ps1)
|
||||||
|
|
||||||
# 7.6.0
|
# 7.6.0
|
||||||
|
|
||||||
- **_[Under investigation]_** Fix -StartRow and -StartColumn being ignored.
|
- **_[Under investigation]_** Fix -StartRow and -StartColumn being ignored.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ PS\> Set-ExcelRange -Range $sheet1.Cells ["E1:S1048576" ], $sheet1.Cells ["V1:V1
|
|||||||
PS\> Close-ExcelPackage $excel -Show
|
PS\> Close-ExcelPackage $excel -Show
|
||||||
```
|
```
|
||||||
|
|
||||||
This will open the password protected file at $xlPath using the password stored in $Password. Sheet1 is selected and formatting applied to two blocks of the sheet; then the file is and saved and loaded into Excel.
|
This will open the password protected file at $xlPath using the password stored in $Password. Sheet1 is selected and formatting applied to two blocks of the sheet; then the file is saved and loaded into Excel.
|
||||||
|
|
||||||
## PARAMETERS
|
## PARAMETERS
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user