Sorting Columns Conditionally with Custom Parameters #1613
Replies: 4 comments 2 replies
-
Based on Doug's suggestion in another thread to look at the XML in the spreadsheet, here are the pertinent column sort entries:
https://epplussoftware.com/docs/6.2/api/OfficeOpenXml.Sorting.SortCondition.html |
Beta Was this translation helpful? Give feedback.
-
I've always deferred sorting to PowerShell Did you figure it out? |
Beta Was this translation helpful? Give feedback.
-
I've spent the last week going through the OfficeXML references and trying to come to terms with what is involved with the sorting. As my tech-writer sister-in-law once said, "There are no answers. Only Cross-References". I've spent time looking at the files in the Public folder and have an inkling of where I'm headed (slowly). The EPPlus.dll included with ImportExcel is v4.5.3.2, so I went back to the archived site for references and will try to keep it compatible with that version. I have Office 2016 on my system, which may or may not cause confusion when looking at the ImportExcel output files vs Excel. Looking at the sheet1.xml from each of them has actually helped, though. There are some differences. I'm thinking it will be a separate Set-SortCondition module eventually, with as much parity as I can figure out how to build in. There's a lot more to it than just ascending/descending and Custom List... I am struggling looking through the modules trying to figure out how things within them relate. I did some Googling and keyboard head-bashing, and came up with the attached script. It will produce a .csv for each of the (56) .ps1 files in the Public folder. The Function Name, ParameterName, Type, Default Values, and the Script Contents used to derive the last three are enumerated for each file. When I get mine going, I can use the script to monitor progress and verify values are what they should be. Rename from .txt to .ps1 and edit the path variables to suit your system. I run them in VS Code. (Edit) I added another script that combines all of the Public scripts into a single file, in case anyone would rather not create individual files. Export-ModuleInfo.txt |
Beta Was this translation helpful? Give feedback.
-
Wow, one heck of a rabitt hole. Hope you strapped a two by four to your butt so you don't fall too deep. |
Beta Was this translation helpful? Give feedback.
-
I haven't found any documentation or examples covering sorting by columns. If it does exist, please post a link in a reply.
I have a pair of reports that can be generated from .nessus Vulnerability and Compliance scan files. I've used Import-Excel to format them about 95% of the way, and I have to do the final step manually. I'd like to know if there's a way to sort columns based on custom properties. If that exists, I'll be able to automate the entire process.
Vuln Script Example:
Compliance Script Example:
If it doesn't exist, I'd like to request that this be investigated and added as a feature if possible.
Here's the section of the Compliance script that takes care of the formatting. The vuln script is similar:
` $tempfilepath = "$WorkDir$ScanFile-PreFormat.xlsx"
$excelpath = "$WorkDir$ReportFile"
Write-Host "Generating report for $($entries.Count) items..."
$entries | Export-Excel $tempfilepath -WorksheetName "Compliance Report"
$TotalRows = $entries.Count + 1 # Add 1 for the Header Row
Beta Was this translation helpful? Give feedback.
All reactions