dfinke / ImportExcel

PowerShell module to import/export Excel spreadsheets, without Excel
https://www.powershellgallery.com/packages/ImportExcel/
Apache License 2.0
2.48k stars 400 forks source link

Conditional Formatting (Date) #1592

Closed montanaprogrammer closed 7 months ago

montanaprogrammer commented 7 months ago

I have the following script:

$data = Import-Csv -Path $csvFilePath
$p=@{
    ConditionalType='Expression'    
    Range="C2:C$($data.Length + 1)"
}
$todayPlusSixty='C2 < today() + 720'
$ct2 = New-ConditionalText -Text $todayPlusSixty  @p -BackgroundColor yellow -ConditionalTextColor white 
$xl = Export-Excel -InputObject $data -Path $xlfile -AutoSize -ConditionalFormat $ct2 -PassThru
Set-Format -Worksheet $xl.Sheet1 -Range "C:C" -NumberFormat 'MM/dd/yyyy HH:mm:ss'
Close-ExcelPackage $xl -Show

($data is an existing CSV file)

Column C has a date formatted as -Format "MM/dd/yyyy HH:mm:ss", however I cannot get the cell to have a background color of Yellow even though there are cells with data such as:

05/12/2024 10:01:42 05/19/2024 10:07:38 05/26/2024 10:09:24

Any ideas what I am doing wrong?

(If this is not the place to ask this, please let me know where I should :))

montanaprogrammer commented 7 months ago

I was able to get it working.

dfinke commented 7 months ago

how did you solve it? did the data in the CSV need to be converted from a string?

montanaprogrammer commented 7 months ago

Yes, I used your example in another issue thread and was able to get the dates converted. Thank you for the work you did on this! Two thumbs UP!!

On Fri, May 3, 2024 at 12:42 PM Doug Finke @.***> wrote:

how did you solve it? did the data in the CSV need to be converted from a string?

— Reply to this email directly, view it on GitHub https://github.com/dfinke/ImportExcel/issues/1592#issuecomment-2092941291, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZHNLVBFJZYBOJYR4WIWL3ZAOA4PAVCNFSM6AAAAABHCWZCSKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJSHE2DCMRZGE . You are receiving this because you modified the open/close state.Message ID: @.***>