-
Notifications
You must be signed in to change notification settings - Fork 419
Description
I am pretty new to Powershell scripting but have used this module to complete many small projects. So thanks for that.
I am having some problems and am not sure if this is a bug or not understanding how cell formatting should be applied.
The scenario is we have a number of XLSX files that need to be parsed for a particular column, group by that column and then save to a file with only that particular columns data in a stamped folder. There is two particular problems happening and I am not sure how to deal with them.
- The date columns are converted to a 4-5 digit numeric upon Import-Excel.
- The number columns with leading zero's look fine upon Import-Excel but upon Export-Excel the leading zero's are trimmed.
I have tried a number of things to alleviate this but nothing seems to work. These are probably the most relevant attempts.
- Tried converting all usedranges to strings before importing.
- Tried disabling BackgroundChecking to disable Numbers in Text prompts before importing.
Here is the script:
$Files = Get-ChildItem "C:\TEMP\*.xlsx"
ForEach($File in $Files)
{
$path = Split-Path $File -parent
$data = Import-Excel -Path $File
ForEach ($group in $data | Group state)
{
MKDIR ("$path\output\$($group.name)" + "Files") -force
$data | Where-Object {$_.state -eq $group.name}
Export-Excel ("$path\output\$($group.name)" + "Files" + "\" + [System.IO.Path]::GetFileNameWithoutExtension($File)+ "_" + "$($group.name).xlsx")
}
}
As I mentioned, I am an inspiring Powershell programmer so I might have missed something obvious but I do appreciate your work on this module and any help you may have.
Thanks,