Compare commits

...

10 Commits

Author SHA1 Message Date
Wyatt Wong
65e3baa3dd Merge d251e7070a into fa907da4a4 2024-05-18 09:44:58 -04:00
dfinke
fa907da4a4 chore: Update module version to 7.8.9 2024-05-18 09:41:57 -04:00
dfinke
24c205e65d feat: Improve ConvertTo-ExcelXlsx robustness
This commit improves the `ConvertTo-ExcelXlsx` function by making it more robust. Thanks to Edward Miller for the contribution.

Note: This message follows the established convention of starting with a type (feat for feature) and providing a concise and clear description of the changes made.
2024-05-18 09:41:50 -04:00
Doug Finke
a1418a336e Merge pull request #1603 from edwardmiller-mesirow/read-only
[ConvertTo-ExcelXlsx] open XLS as read-only
2024-05-18 09:37:38 -04:00
dfinke
63683db543 chore: Update module version to 7.8.8 2024-05-18 09:33:54 -04:00
Edward Miller
36b5495bd5 check for null first 2024-05-17 23:28:26 -05:00
Edward Miller
722516de7c use try-finally 2024-05-17 23:24:11 -05:00
Edward Miller
57bb049111 open XLS as read-only 2024-05-17 22:41:53 -05:00
Wyatt Wong
d251e7070a Update and rename ConditionalFormattingUnmatchColumns.ps1 to ConditionalFormattingUnmatchColumns-Sol1.ps1
Minor update and change the filename as Solution 1
2024-02-06 10:04:44 +08:00
Wyatt Wong
1b2c280e4b Create ConditionalFormattingUnmatchColumns.ps1 2024-02-05 16:36:17 +08:00
4 changed files with 47 additions and 6 deletions

View File

@@ -0,0 +1,26 @@
try { Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 } catch { throw ; return }
$data = ConvertFrom-Csv @"
Sequence1,StateName1,Abbreviation1,Sequence2,StateName2,Abbreviation2
A001,Alabama,AL,A001,Alabama,AL
A002,California,CA,B002,California,CA
A003,Colorado,CO,A003,Colorado,CO
A004,Florida,FL,A004,Maine,FL
A005,Missouri,MO,A005,Missouri,MI
A006,New Mexico,NM,A006,Tennessee,TN
A007,North Carolina,NC,C007,North Carolina,NC
A008,North Dakota,ND,A008,South Dakota,SD
A009,Rhode Island,RI,D009,Rhode Island,VA
A010,Texas,TX,A010,Texas,TX
"@
$xlfile = "$PSScriptRoot\test.xlsx"
Remove-Item $xlfile -ErrorAction SilentlyContinue
$file = $data | Export-Excel $xlfile -AutoSize -PassThru
Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$D$2:$D$1048576' -ConditionValue '=NOT(EXACT($A2,$D2))' -RuleType Expression -ForegroundColor Red
Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$E$2:$E$1048576' -ConditionValue '=NOT(EXACT($B2,$E2))' -RuleType Expression -ForegroundColor Red
Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$F$2:$F$1048576' -ConditionValue '=NOT(EXACT($C2,$F2))' -RuleType Expression -ForegroundColor Red
Close-ExcelPackage $file -Show

View File

@@ -6,7 +6,7 @@
RootModule = 'ImportExcel.psm1'
# Version number of this module.
ModuleVersion = '7.8.7'
ModuleVersion = '7.8.9'
# ID used to uniquely identify this module
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'

View File

@@ -45,11 +45,18 @@ function ConvertTo-ExcelXlsx {
throw "Could not create Excel.Application ComObject. Please verify that Excel is installed."
}
$Excel.Visible = $false
$null = $Excel.Workbooks.Open($xlsFile.FullName)
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
$Excel.ActiveWorkbook.Close()
$Excel.Quit()
try {
$Excel.Visible = $false
$null = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
}
finally {
if ($null -ne $Excel.ActiveWorkbook) {
$Excel.ActiveWorkbook.Close()
}
$Excel.Quit()
}
}
}

View File

@@ -1,3 +1,11 @@
# 7.8.9
- Thanks to (Edward Miller)[https://github.com/edwardmiller-mesirow] for improving `ConvertTo-ExcelXlsx`and making it more robust
# 7.8.8
- Fix the release
# 7.8.7
- Thanks to [Phil Bossman](https://github.com/pbossman) for the PR and fixing this.