├── Demo.ps1 ├── EPPlus.dll ├── ExcelPSLib.dll ├── ExcelPSLib.psd1 ├── ExcelPSLib.psm1 ├── License.txt └── README.md /Demo.ps1: -------------------------------------------------------------------------------- 1 | #Require ExcelPSLib 0.5.7 2 | Import-Module ExcelPSLib -Force 3 | 4 | $ComputerList = @("LOCALHOST") 5 | $RowPosition = 2 6 | $OutputFileName = "c:\temp\EXCELPSLIB_Demo.xlsx" 7 | 8 | [OfficeOpenXml.ExcelPackage]$excel = New-OOXMLPackage -author "Avalon77" -title "ComputerInfos" 9 | [OfficeOpenXml.ExcelWorkbook]$book = $excel | Get-OOXMLWorkbook 10 | 11 | $excel | Add-OOXMLWorksheet -WorkSheetName "Local HDD" -AutofilterRange "A2:E2" 12 | $sheet = $book | Select-OOXMLWorkSheet -WorkSheetNumber 1 13 | 14 | $StyleGreen = New-OOXMLStyleSheet -WorkBook $book -Name "GirlStyle" -Bold -ForeGroundColor Black -FillType Solid -BackGroundColor Green -borderStyle Thin -BorderColor Black -NFormat "#,##0.00" 15 | $StyleRed = New-OOXMLStyleSheet -WorkBook $book -Name "BoyStyle" -Bold -ForeGroundColor Black -FillType Solid -BackGroundColor Red -borderStyle Thin -BorderColor Black -NFormat "#,##0.00" 16 | $StyleHeader = New-OOXMLStyleSheet -WorkBook $book -Name "HeaderStyle" -Bold -ForeGroundColor White -BackGroundColor Black -Size 14 -HAlign Center -VAlign Center -FillType Solid 17 | $StyleNormal = New-OOXMLStyleSheet -WorkBook $book -Name "NormalStyle" -borderStyle Thin -BorderColor Black 18 | $StyleNumber = New-OOXMLStyleSheet -WorkBook $book -Name "Float" -NFormat "#,##0.00" 19 | $StyleConditionalFormatting = New-OOXMLStyleSheet -WorkBook $book -Name "ConditionalF" -Bold -ForeGroundColor Black -FillType Solid -BackGroundColor Orange -borderStyle Double -BorderColor Blue -NFormat "#,##0.0000" -Italic 20 | 21 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 1 -value "Computer" -StyleSheet $StyleHeader | Out-Null 22 | $sheet.Column(1).Width = 22 23 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 2 -value "Drive" -StyleSheet $StyleHeader | Out-Null 24 | $sheet.Column(2).Width = 16 25 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 3 -value "Space" -StyleSheet $StyleHeader | Out-Null 26 | $sheet.Column(3).Width = 22 27 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 4 -value "Freespace" -StyleSheet $StyleHeader | Out-Null 28 | $sheet.Column(4).Width = 22 29 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 5 -value "SpaceRatio" -StyleSheet $StyleHeader | Out-Null 30 | $sheet.Column(5).Width = 22 31 | 32 | $RowPosition++ 33 | 34 | foreach($Computer in $ComputerList){ 35 | 36 | if(Test-Connection -ComputerName $Computer -Count 1 -BufferSize 16){ 37 | $LocaHardDrive = Get-WmiObject -query "Select * FROM win32_logicaldisk where DriveType=3" | Select-Object -Property * 38 | $VolumeSerialNumbers = @() 39 | 40 | foreach($Disk in $LocaHardDrive){ 41 | 42 | if($Disk.size -gt 0){ 43 | 44 | $VolumeSerialNumbers += $Disk.VolumeSerialNumber 45 | 46 | $FreeSpace = $Disk.freespace 47 | $TotalSpace = $Disk.size 48 | $Caption = $Disk.caption 49 | $FreeSpaceRatio = $FreeSpace / $TotalSpace * 100 50 | 51 | $sheet | Set-OOXMLRangeValue -Row $RowPosition -Col 1 -Value $Computer -StyleSheet $StyleGreen | Out-Null 52 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 2 -value $Caption -StyleSheet $StyleGreen | Out-Null 53 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 3 -value $($TotalSpace / 1GB) -StyleSheet $StyleGreen | Out-Null 54 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 4 -value $($FreeSpace / 1GB) -StyleSheet $StyleGreen | Out-Null 55 | 56 | if($FreeSpaceRatio -lt 10){ 57 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 5 -value $FreeSpaceRatio -StyleSheet $StyleRed | Out-Null 58 | }else{ 59 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 5 -value $FreeSpaceRatio -StyleSheet $StyleGreen | Out-Null 60 | } 61 | 62 | $RowPosition++ 63 | } 64 | 65 | } 66 | 67 | Export-OOXML -InputObject $LocaHardDrive -FileFullPath "C:\Temp\$computer.xlsx" -ConditionalFormating @([PSCustomObject]@{Name="DeviceID";Style="Red";Condition="BeginsWith";Value="L"},[PSCustomObject]@{Name="DeviceID";Style="Green";Condition="BeginsWith";Value="B"}) 68 | 69 | }else{ 70 | 71 | $sheet | Set-OOXMLRangeValue -Row $RowPosition -Col 1 -Value $Computer -StyleSheet $StyleRed | Out-Null 72 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 2 -value "N/A" -StyleSheet $StyleRed | Out-Null 73 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 3 -value 0 -StyleSheet $StyleRed | Out-Null 74 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col 4 -value 0 -StyleSheet $StyleRed | Out-Null 75 | 76 | $RowPosition++ 77 | } 78 | 79 | $sheet | Add-OOXMLConditionalFormatting -Addresses "E3:E$($RowPosition-1)" -StyleSheet $StyleConditionalFormatting -RuleType GreaterThanOrEqual -ConditionValue "50" 80 | $sheet | Add-OOXMLConditionalFormatting -Addresses "B3:B$($RowPosition-1)" -StyleSheet $StyleConditionalFormatting -RuleType BeginsWith -ConditionValue "L" 81 | 82 | } 83 | 84 | $excel | Save-OOXMLPackage -FileFullPath $OutputFileName -Dispose 85 | 86 | $ImportedOOXMLData = Import-OOXML -FileFullPath $OutputFileName -WorksheetNumber 1 87 | 88 | $ImportedOOXMLData 89 | 90 | -------------------------------------------------------------------------------- /EPPlus.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avalonzone/ExcelPSLib/dfbb3a6823b9458dfe7ff8f4f0e53dc91fc32116/EPPlus.dll -------------------------------------------------------------------------------- /ExcelPSLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avalonzone/ExcelPSLib/dfbb3a6823b9458dfe7ff8f4f0e53dc91fc32116/ExcelPSLib.dll -------------------------------------------------------------------------------- /ExcelPSLib.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avalonzone/ExcelPSLib/dfbb3a6823b9458dfe7ff8f4f0e53dc91fc32116/ExcelPSLib.psd1 -------------------------------------------------------------------------------- /ExcelPSLib.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | NAME: ExcelPSLib.psm1 4 | AUTHOR: Tomson Philip 5 | CONTRIBUTORS: Singelé Cédric, Haot Vincent, Elliston Jack 6 | DATE: 31/07/13 7 | KEYWORDS: OOXML, MICROSOFT EXCEL 8 | VERSION : 0.7.0 9 | LICENSE: LGPL 2.1 10 | 11 | This PowerShell Module allow simple creation of XLSX file by using the EPPlus 4.1 .Net DLL 12 | made by Jan Kallman and Licensed under LGPL 2.1 and available at http://epplus.codeplex.com/ . 13 | Copyright (C) 2014 Tomson Philip 14 | 15 | This library is free software; you can redistribute it and/or 16 | modify it under the terms of the GNU Lesser General Public 17 | License as published by the Free Software Foundation; either 18 | version 2.1 of the License, or (at your option) any later version. 19 | 20 | This library is distributed in the hope that it will be useful, 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | Lesser General Public License for more details. 24 | 25 | You should have received a copy of the GNU Lesser General Public 26 | License along with this library; if not, write to the Free Software 27 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 28 | 29 | .SYNOPSIS 30 | 31 | VERSION 0.7.0 (27/03/2019) 32 | - Improved Cmdlet : Export-OOXML 33 | It is now possible to do a cumulative export with the -AddToExistingDocument switch parameter 34 | You MUST provide another worksheetname each time or it won't work 35 | 36 | VERSION 0.6.9 (04/10/2017) 37 | - Improved Cmdlet : Add-OOXMLWorksheet 38 | It is now possible to push an array of identical objects at the worksheet creation 39 | There is no style support for the moment 40 | Autofilter will not work 41 | - Fixed Cmdlet : New-OOXMLStyleSheet 42 | If a style name already exists, this is the corresponding stylesheet that will be returned 43 | TODO : Implement data type auto style. 44 | IDEA : Modify Export-OOXML and Add-OOXMLWorksheet so they could use the same code and features 45 | 46 | 47 | VERSION 0.6.8 (26/04/2016) 48 | - Improved Cmdlet : Import-OOXML 49 | The Import-OOXML always consider that first data row is actualy de data header 50 | that will be used to generate the data object model. In the previous versions, 51 | There was no check to see if a header was empty or null. Now the Cmdlet will read 52 | each header and will stop if no header value is found. 53 | 54 | VERSION 0.6.7 (19/04/2016) 55 | - Improved Cmdlet : Import-OOXML 56 | Added worksheetname back as an option to select which worksheet to use 57 | Added range so a range could be used as the import source rather than 58 | the whole worksheet 59 | - Added a new Cmdlet : Open-OOXML 60 | This simply opens an existing Excel file for use 61 | - Added a new Cmdlet : Convert-OOXMLFromExcelCoordinates 62 | This converts an Excel cell address or range into a hash containing 63 | the related row and column numbers 64 | - Added a new Cmdlet : Read-OOXMLCell 65 | Given a worksheet this will return the contents of a cell either 66 | using row/column number or the Excel address 67 | 68 | VERSION 0.6.6 (09/11/2016) 69 | - Improved the Export-OOXML function by allowing you to add data validation per column 70 | - Added a new Cmdlet : Get-OOXMLDataValidationCustomObject 71 | This Cmdlet is a user friendly way to create a custom object 72 | - Added a new Cmdlet : Get-OOXMLDataValidationAssignementCustomObject 73 | This Cmdlet is a user friendly way to create a custom object 74 | - Added a new Cmdlet : Add-OOXMLDataValidation 75 | This Cmdlet assign a data validation constrain on a target range. 76 | - Optimised some part of the code 77 | - Added a complete example of how to use the Export-OOXML Cmdlet 78 | 79 | #TODO 80 | - Refactor the Export-OOXML Cmdlet to a more readable and maintable Cmdlet ! 81 | 82 | version 0.6.5 (14/10/2016) 83 | - Fixed a bug introduced in version 0.6.4 84 | This bug always setted the Conditional formating to the precise mode ! 85 | - "UnPrecise" mode (default) has been improved and can (only) handle the following conditions : 86 | * BeginsWith 87 | * ContainsText 88 | * EndsWith 89 | * Equal 90 | * GreaterThan 91 | * GreaterThanOrEqual 92 | * LessThan 93 | * LessThanOrEqual 94 | 95 | version 0.6.4 (13/10/2016) 96 | - Improved the Export-OOXML function by allowing you to select the columns you want as output instead of 97 | the current behaviour that output each property to a column. (It is an ordered list !!!) 98 | - Imporved the Export-OOXML function by allowing you to order the columns : Ascending or Descending. 99 | This can be combined with the properties/columns selection 100 | - Improved the Export-OOXML function by allowing you to set a freeze pane at the selected column 101 | 102 | version 0.6.3 (07/09/2016) 103 | - Improved the Export-OOXML function, which by default will color a whole row in place of a single cell 104 | For the one who want to keep the previous functionnality just use the switch "Precise" as parameter. 105 | 106 | version 0.6.2 (29/08/2016) 107 | - Added a Dll containing the 3 Enum : 108 | EnumConditionalFormattingRuleTypeand 109 | EnumOperations 110 | EnumColors 111 | - Refactored the .psm1 module file 112 | 113 | version 0.6.1 (10/08/2016) 114 | - Added the parameter "TextRotation" to Set-OOXMLRangeTextOptions 115 | - Added the parameter "TextRotation" to New-OOXMLStyleSheet 116 | - Added the parameter "$HeaderTextRotation" to Export-OOXML 117 | - Added the possibility to define and assign a custom style to one or more column header with the Export-OOXML Cmdlet 118 | - Added the parameters "Merge" + "RowEnd", "ColEnd" to Set-OOXMLRangeValue so you can now merge a range of cells 119 | - Improved Get-OOXMLColumnString (20% faster) by using a native static function : OfficeOpenXml.ExcelCellAddress.GetColumnLetter(int column) 120 | - Added/fixed parameter comments that were wrong or missing 121 | - EPPLUS DLL is now version 4.1 (Stable version) 122 | 123 | version 0.6.0 (08/09/2015) 124 | - Fixed the exception thrown if no HeaderStyle parameter was provided to Export-OOXML (CodePlex - Issue ID #3) 125 | - Added some try/catch pattern into Cmdlet (It's a WIP so not every Cmdlet was updated) 126 | 127 | version 0.5.9 (04/09/2015) 128 | This update in mainly focused on the functionnalities of the Export-OOXML Cmdlet 129 | All The next versions will be added both to Chocolatey and to Codeplex 130 | - Added 2 New Enum: "EnumColors"(141 color name extracted from ) & EnumOperations (5 Basic & 3 Conditional Excel Formula Operators) 131 | - Export-OOXML => Added 137 color styles to the original 4 to use with the Cmdlet Get-OOXMLConditonalFormattingCustomObject 132 | - Export-OOXML => Added Support for basic math operations on columns : "SUM","AVERAGE","COUNT","MAX","MIN" 133 | - Export-OOXML => Added Support for Conditional math operations on columns : "SUMIF","AVERAGEIF","COUNTIF" 134 | - Export-OOXML => Added 137 color Styles for the column headers 135 | - EPPLUS DLL is now version 4.0.4 (Stable version) 136 | 137 | version 0.5.8 (07/08/2015) 138 | 139 | - Improved Import-OOXML cmdlet so it can "auto-sense" data types if asked by adding the "KeepDataType" switch parameter. 140 | *** Warning, for this to work the data type must be the same in the whole column, if one single cell in 141 | the column is of a different data type the data type will always be set to "string" even if the "KeepDataType" 142 | was set. 143 | 144 | version 0.5.7 (29/09/2014) 145 | 146 | - Improved the Export-OOXML cmdlet so it can "auto-sense" data types and apply the correct formatting to cells 147 | - Improved the Export-OOXML cmdlet so it can recognize URI and set the HyperLink propertie of the cell accordingly 148 | - Added Import-OOXML cmdlet to convert an XLSX file to an array of object this function is still basic and requires 149 | some fixed Excel sheet format. If you do an Export-OOXML and then an Import-OOXML with the generated XLSX as 150 | input file, everything should be fine. 151 | - Fixed some small "gliches" 152 | 153 | version 0.5.6 (24/09/2014) 154 | 155 | - Added a new command-line Get-OOXMLConditonalFormattingCustomObject that returns a "PSCustomObject" 156 | ready to be used with the Export-OOXML "ConditionalFormatings" parameter. It has Auto-Complete for "Style" and "Condition" 157 | - Improved the Export-OOXML cmdlet with a new switch parameter "AutoFit" that will resize all the column according 158 | to the size of their content 159 | - Fixed the way that conditional formatting was applied in the Export-OOXML because the range was row count +1 160 | - Fixed the "invoke member w/ expression name" exception introduced in version 0.5.5 for those using PS 3.0... Sorry about this ! 161 | 162 | #TODO 163 | - Add condition priority 164 | - Check if properties are defined in a style sheet before using them with Add-OOXMLConditionalFormatting (DONE) 165 | - Add the possibility to set cell Text/Numberformat per column with the Export-OOXML cmdlet (DONE => Auto-Sensing) 166 | 167 | version 0.5.5 (23/09/2014) 168 | 169 | - Added a reduced enum EnumConditionalFormattingRuleType based on the 170 | OfficeOpenXml.ConditionalFormatting.eExcelConditionalFormattingRuleType enum 171 | - Added a new cmdlet Add-OOXMLConditionalFormatting that let you add conditional formating rules 172 | to single or multiple ranges 173 | - Improved the Export-OOXML Cmdlet with a new parameter that allow you to use 4 Conditional Styles 174 | that are named: Red, Orange, Yellow and Green. This new "ConditionalFormatings" parameter can receives 175 | array of objects of the following format: 176 | 177 | @( 178 | [PSCustomObject]@{ 179 | Name="DeviceID"; 180 | Style="Red"; 181 | Condition="BeginsWith"; 182 | Value="L" 183 | } 184 | ) 185 | 186 | "Name" is the name of one propertie of the array of object you want to export 187 | "Style" is the style you want to apply Red, Orange, Yellow and Green 188 | "Condition" is a string coming from the enum "EnumConditionalFormattingRuleType" 189 | "Value" is the condition value. 190 | 191 | For more informations see the Demo.ps1 file 192 | 193 | version 0.5.4 (16/09/2014) 194 | 195 | - Added a new command-line Export-OOXML that will export an array of object to an XLSX file 196 | 197 | version 0.5.3 (10/07/2014) 198 | 199 | - Fixed the problem with the value in the Set-OOXMLRangeValue that was always a "string" 200 | 201 | Version 0.5.2 (26/03/2014) 202 | 203 | - Added worksheet's name maximum length check in the Add-OOXMLWorksheet cmdlet 204 | 205 | Version 0.5.1 (06/03/2014) 206 | 207 | - Added "OutlineLevel" parameter to the Set-OOXMLRangeValue cmdlet 208 | 209 | Version 0.5 (26/02/2014) 210 | 211 | - The "Color" is no more a "string" but uses the "System.Drawing.Color" type 212 | - Added Set-OOXMLStyleSheet and New-OOXMLStyleSheet so you can now define style and then recall and apply them 213 | - Added a really basic Pivot Table cmdlet New-OOXMLPivotTable 214 | - Modified the Set-OOXMLRangeValue cmdlet to accept 2 more parameters "StyleSheet" and "StyleSheetName" 215 | - Introduction of ParametersetName in some cmdlets to enforce good cmdlet usage. 216 | - Added complete cmdlet info bloc for each cmdlet 217 | - Renamed Get-ColumnString to Get-OOXMLColumnString and created an alias for backward compatibility 218 | 219 | Version 0.4 (25/09/2013) 220 | 221 | - Added ValueFromPipeline to allmost all functions (If relevant) 222 | - Fixed some Class Type casting (OfficeOpenXml.ExcelRange => OfficeOpenXml.ExcelRangeBase) 223 | - Added Return to allmost all functions (If relevant) so you can now chain them like : 224 | $Worksheet | Set-OOXMLRangeValue -row 1 -col 1 -value "Test Value" | Set-OOXMLRangeBorder -borderStyle "DashDotDot" -color "Green" 225 | - Modified the Save-OOXMLPackage "CmdLet" so it now uses the "Dispose" method if the "Dispose" switch is used 226 | - The "BorderStyle" is no more a "string" but uses the Enum "OfficeOpenXml.Style.ExcelBorderStyle" 227 | - The "FillStyle" is no more a "string" but it uses the Enum "OfficeOpenXml.Style.ExcelFillStyle" 228 | - The "HorizontalAlignment" is no more a "string" but it uses the Enum "OfficeOpenXml.Style.ExcelHorizontalAlignment" 229 | - The "VerticalAlignment" is no more a "string" but it uses the Enum "OfficeOpenXml.Style.ExcelVerticalAlignment" 230 | 231 | 232 | VERSION 0.3a (13/08/2013) 233 | 234 | - Fixed the Set-OOXMLRangeBorder cmdlet that was still using the old cmdlet 235 | - Removed the usage example present in this module 236 | 237 | VERSION 0.3 (13/08/2013) 238 | 239 | - Renamed all cmdlets to respect standards 240 | - Added the "Get-OOXMLDeprecatedCommand" to allow you to use the old cmdlets 241 | - Added the "Repair-OOXMLLib" cmdlet to set Aliases 242 | - Added the "Convert-OOXMLOldScripts" to convert you script with 0.2 style cmdlets to the 0.3 style 243 | This cmdlet is very basic and should work in many case but it is more a "brute force" conversion than 244 | something "smart" so use it if you dare ! 245 | - Adde the "Get-OOXMLHelp" to print the syntax of all cmdlets at once (Ex: output it to a file) 246 | - Reformated all comments and infos 247 | - Compatible PowerShell 2.0(*) 248 | * There was an issue with PS 2.0 : 249 | Mmulti-dimentional .Net tables like cells[1,1] or cells[1,1,1,5] were not understood ! 250 | So If you use power try to use literal addressing like "A1" or "A1:E1" 251 | - Added the "Convert-OOXMLCellsCoordinates" cmdlet to convert coordinate like [1,1] to "A1" or like [1,1,1,5] to "A1:E1" 252 | - Added the "Get-ColumnString" cmdlet that is normaly used by "Convert-OOXMLCellsCoordinates" but you can use it to 253 | Convert coordinate like [1,1] to "A1". I recommend the usage of "Convert-OOXMLCellsCoordinates" instead of "Get-ColumnString" 254 | for single cell coordinate convertion. 255 | 256 | VERSION 0.2 (02/08/2013) 257 | 258 | - Added Default Row, Col Size and AutoFilter range at Sheet Creation 259 | - Added a new Cmdlet SetTextOptions allowing to set Text formating options for a cell range 260 | - Added a new Cmdlet SetPrinterSettings allowing to set some printer settings 261 | 262 | VERSION 0.1 (31/07/13) 263 | 264 | This PowerShell Module to allow simple creation of XLSX file by using the EPPlus 3.1 .Net DLL 265 | available at http://epplus.codeplex.com/ and was made by Jan Kallman. 266 | 267 | The current set of feature is the following : 268 | - Create a Microsoft Excel Workbook 269 | - Add Worksheet to a Workbook 270 | - Select a Worksheet in a Workbook 271 | - Define the font style 272 | - Define border style 273 | - Define Cell color and Fill type 274 | - Save the Workbook to a file 275 | - Set the value of a Cell as Text or Hyperlink 276 | - Set AutoFitColumns minimum width 277 | - Select a range of cell 278 | 279 | TODO: 280 | 281 | - Add more error checking within function 282 | 283 | #> 284 | 285 | <#---------------------------------------[ Variables ]---------------------------------------#> 286 | 287 | 288 | <#---------------------------------------[ Functions ]---------------------------------------#> 289 | 290 | Function New-OOXMLPackage { 291 | <# 292 | .SYNOPSIS 293 | Create an ExcelPackage instance, configure the workbook and return the ExcelPackage instance. 294 | 295 | .DESCRIPTION 296 | Create an ExcelPackage instance, configure the workbook and return the ExcelPackage instance. 297 | 298 | .PARAMETER Author 299 | An author to be added to the workbook. 300 | 301 | .PARAMETER Title 302 | A title to be added to the workbook. 303 | 304 | .PARAMETER Comment 305 | A comment to be added to the workbook. 306 | 307 | .PARAMETER Path 308 | The path of XLSX file 309 | 310 | .EXAMPLE 311 | [OfficeOpenXml.ExcelPackage]$excel = $(New-OOXMLPackage -Author "Mr.Excel" -Title "Workbook title" -Comment "Workbook comment") 312 | 313 | Description 314 | ----------- 315 | Calls a function which create and returns a "OfficeOpenXml.ExcelPackage" object 316 | 317 | .NOTES 318 | 319 | .LINK 320 | 321 | #> 322 | [CmdletBinding()] 323 | param ( 324 | [parameter(Mandatory=$true)] 325 | [string]$Author, 326 | [parameter(Mandatory=$true)] 327 | [string]$Title, 328 | [string]$Comment, 329 | [string]$Path 330 | ) 331 | process{ 332 | 333 | if($Path){ 334 | [System.IO.FileInfo]$XLSXFile = New-Object System.IO.FileInfo($Path) 335 | $ExcelInstance = New-Object OfficeOpenXml.ExcelPackage($XLSXFile) 336 | }else{ 337 | $ExcelInstance = New-Object OfficeOpenXml.ExcelPackage 338 | } 339 | 340 | $ExcelInstance.Workbook.Properties.Author = $Author 341 | if($Title){$ExcelInstance.Workbook.Properties.Title = $Title} 342 | if($Comment){$ExcelInstance.Workbook.Properties.Comments = $Comment} 343 | return [OfficeOpenXml.ExcelPackage]$ExcelInstance 344 | } 345 | } 346 | 347 | Function Add-OOXMLWorksheet { 348 | <# 349 | .SYNOPSIS 350 | Add a worksheet to the workbook and configure the worksheet. 351 | 352 | .DESCRIPTION 353 | Add a worksheet to the workbook and configure the worksheet. 354 | 355 | .PARAMETER DefColWidth 356 | Default width of the columns in the worksheet. 357 | 358 | .PARAMETER DefRowHeight 359 | Default height of the rows in the worksheet. 360 | 361 | .PARAMETER AutofilterRange 362 | Set a range on which you want to enable the Auto-Filter feature 363 | 364 | .PARAMETER WorkSheetName 365 | The name of the worksheet 366 | 367 | .PARAMETER ExcelInstance 368 | The Current ExcelPackage instance 369 | 370 | .PARAMETER InputObject 371 | An Optional array of objects and insert it 372 | 373 | .EXAMPLE 374 | Add-OOXMLWorksheet -ExcelInstance $excel -WorkSheetName "New Worksheet" 375 | $excel | Add-OOXMLWorksheet -WorkSheetName "New Worksheet" 376 | $excel | Add-OOXMLWorksheet -WorkSheetName "New Worksheet" -DefColWidth 20 -DefRowHeight 10 377 | 378 | Description 379 | ----------- 380 | Calls a function which create a new worksheet in the workbook of the current ExcelInstance Object 381 | 382 | .NOTES 383 | 384 | .LINK 385 | 386 | #> 387 | [CmdletBinding()] 388 | param ( 389 | [int]$DefColWidth, 390 | [int]$DefRowHeight, 391 | [string]$AutofilterRange, 392 | [parameter(Mandatory=$true)] 393 | [ValidateScript({$_.length -lt 30})] 394 | [String]$WorkSheetName, 395 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 396 | [OfficeOpenXml.ExcelPackage]$ExcelInstance, 397 | [Object[]]$InputObject 398 | ) 399 | process{ 400 | $ExcelInstance.Workbook.Worksheets.Add($WorkSheetName) | Out-Null 401 | $SheetNumber = $ExcelInstance.Workbook.Worksheets.Count 402 | $loop = $true 403 | $i=1 404 | while($loop){ 405 | 406 | if($ExcelInstance.Workbook.Worksheets[$i].Name -eq $WorkSheetName){ 407 | 408 | $sheet = $ExcelInstance.Workbook.Worksheets[$i] 409 | $book = $ExcelInstance.Workbook 410 | 411 | if($InputObject) 412 | { 413 | 414 | $StyleNormal = New-OOXMLStyleSheet -WorkBook $book -Name "NormalStyle" -borderStyle Thin -BorderColor Black -HAlign Right 415 | $StyleURI = New-OOXMLStyleSheet -WorkBook $book -Name "URIStyle" -borderStyle Thin -BorderColor Black -HAlign Left -ForeGroundColor Blue -Underline 416 | 417 | $StyleDate = New-OOXMLStyleSheet -WorkBook $book -Name "DateStyle" -borderStyle Thin -BorderColor Black -HAlign Right -NFormat "$([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortDatePattern) $([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortTimePattern)" 418 | $StyleNumber = New-OOXMLStyleSheet -WorkBook $book -Name "NumberStyle" -borderStyle Thin -BorderColor Black -HAlign Right -NFormat "0" 419 | $StyleFloat = New-OOXMLStyleSheet -WorkBook $book -Name "FloatStyle" -borderStyle Thin -BorderColor Black -HAlign Right -NFormat "0.00" 420 | 421 | $ReferencePropertySet = $($InputObject[0].PSObject.Properties).Name 422 | $ColumnNumber = $ReferencePropertySet.Length 423 | $RowPosition = 1 424 | 425 | $j=1 426 | foreach($Property in $ReferencePropertySet) 427 | { 428 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col $j -value $Property | Out-Null 429 | $sheet.Column($j).Width = 32 430 | $j++ 431 | } 432 | 433 | $RowPosition++ 434 | 435 | foreach($Object in $InputObject){ 436 | $j=1 437 | foreach($Property in $ReferencePropertySet){ 438 | $Value = "Empty Value" 439 | 440 | 441 | if($($Object.$Property) -ne $null){ 442 | $Value = $($Object.$Property) 443 | 444 | } 445 | 446 | $IsURI = $false 447 | $AppliedStyle = $StyleNormal 448 | switch -regex ($($Value.GetType())){ 449 | "(^uint[0-9]{2}$)|(^int[0-9]{2}$)|(^long$)|(^int$)" { 450 | $AppliedStyle = $StyleNumber 451 | } 452 | "(double)|(float)|(decimal)" { 453 | $AppliedStyle = $StyleFloat 454 | } 455 | "datetime" { 456 | $AppliedStyle = $StyleDate 457 | } 458 | "^string$"{ 459 | if($([System.URI]::IsWellFormedUriString([System.URI]::EscapeUriString($Value),[System.UriKind]::Absolute)) -and $($Value -match "(^\\\\)|(^http://)|(^ftp://)|(^[a-zA-Z]:(//|\\))|(^https://)")) 460 | { 461 | $AppliedStyle = $StyleURI 462 | $IsURI = $true 463 | } 464 | } 465 | } 466 | 467 | <# 468 | 469 | if($IsURI){ 470 | $sheet | Set-OOXMLRangeValue -Row $RowPosition -Col $j -Value $Value -StyleSheet $AppliedStyle -Uri | Out-Null 471 | }else{ 472 | $sheet | Set-OOXMLRangeValue -Row $RowPosition -Col $j -Value $Value -StyleSheet $AppliedStyle | Out-Null 473 | } 474 | #> 475 | 476 | $sheet | Set-OOXMLRangeValue -Row $RowPosition -Col $j -Value $Value | Out-Null 477 | 478 | $j++ 479 | 480 | 481 | } 482 | $RowPosition++ 483 | } 484 | 485 | $EndColumn = Get-OOXMLColumnString -ColNumber $($ReferencePropertySet.Length) 486 | $FirstColumn = Get-OOXMLColumnString -ColNumber 1 487 | $Sheet.Cells["$FirstColumn$($Sheet.Dimension.Start.Row):$EndColumn$LastRow"].AutoFitColumns() 488 | 489 | } 490 | 491 | if($DefColWidth){$ExcelInstance.Workbook.Worksheets[$i].DefaultColWidth = $DefColWidth} 492 | if($DefRowHeight){$ExcelInstance.Workbook.Worksheets[$i].DefaultRowHeight = $DefRowHeight} 493 | if($AutofilterRange){$ExcelInstance.Workbook.Worksheets[$i].Cells[$AutofilterRange].AutoFilter=$true} 494 | $loop = $false 495 | 496 | } 497 | $i++ 498 | } 499 | } 500 | } 501 | 502 | Function Get-OOXMLWorkbook { 503 | <# 504 | .SYNOPSIS 505 | Get the workbook in the ExcelInstance object 506 | 507 | .DESCRIPTION 508 | Get the workbook in the ExcelInstance object 509 | 510 | .PARAMETER ExcelInstance 511 | The Current ExcelPackage instance 512 | 513 | .EXAMPLE 514 | $book = $excel | Get-OOXMLWorkbook 515 | $book = Get-OOXMLWorkbook -ExcelInstance ExcelPackage 516 | 517 | Description 518 | ----------- 519 | Calls a function which return the workbook of the current ExcelInstance Object 520 | 521 | .NOTES 522 | 523 | .LINK 524 | 525 | #> 526 | [CmdletBinding()] 527 | param( 528 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 529 | [OfficeOpenXml.ExcelPackage]$ExcelInstance 530 | ) 531 | process{ 532 | return [OfficeOpenXml.ExcelWorkbook]$ExcelInstance.Workbook 533 | } 534 | } 535 | 536 | Function Select-OOXMLWorkSheet { 537 | <# 538 | .SYNOPSIS 539 | Get a worksheet by name or by number from the given workbook in the ExcelInstance object 540 | 541 | .DESCRIPTION 542 | Get a worksheet by name or by number from the given workbook in the ExcelInstance object 543 | 544 | .PARAMETER WorkBook 545 | The workbook in the Excel instance 546 | 547 | .PARAMETER WorkSheetNumber 548 | The worksheet index number 549 | 550 | .PARAMETER WorkSheetName 551 | The worksheet name 552 | 553 | .EXAMPLE 554 | $sheet = $book | Select-OOXMLWorkSheet -WorkSheetNumber 1 555 | $sheet = $book | Select-OOXMLWorkSheet -WorkSheetName "My Worksheet" 556 | 557 | Description 558 | ----------- 559 | Calls a function which return a worksheet in the given workbook object 560 | 561 | .NOTES 562 | 563 | .LINK 564 | 565 | #> 566 | [CmdletBinding()] 567 | param ( 568 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 569 | [OfficeOpenXml.ExcelWorkbook]$WorkBook, 570 | [parameter(ParameterSetName="WorksheetIndex", Mandatory=$true)] 571 | [int]$WorkSheetNumber, 572 | [parameter(ParameterSetName="WorksheetName", Mandatory=$true)] 573 | [string]$WorkSheetName 574 | ) 575 | process{ 576 | if($WorkSheetName){ 577 | $SheetNumberPlusOne = $($Workbook.Worksheets.Count + 1) 578 | $i=1 579 | while($i -lt $SheetNumberPlusOne){ 580 | if($Workbook.Worksheets[$i].Name -like $WorkSheetName){ 581 | return [OfficeOpenXml.ExcelWorksheet]$WorkBook.Worksheets[$i] 582 | } 583 | $i++ 584 | } 585 | } 586 | $WorkSheet = [OfficeOpenXml.ExcelWorksheet]$WorkBook.Worksheets[$WorkSheetNumber] 587 | return [OfficeOpenXml.ExcelWorksheet]$WorkSheet 588 | } 589 | } 590 | <# 591 | Function Get-OOXMLRangeValue 592 | { 593 | 594 | } 595 | #> 596 | 597 | Function Set-OOXMLRangeValue { 598 | <# 599 | .SYNOPSIS 600 | Set the value in a cell and optionally apply a stylesheet to it 601 | 602 | .DESCRIPTION 603 | Set the value in a cell and optionally apply a stylesheet to it 604 | 605 | .PARAMETER Row 606 | The start row index expressed as an integer 607 | 608 | .PARAMETER Col 609 | The start column index expressed as an integer 610 | 611 | .PARAMETER RowEnd 612 | The end row index expressed as an integer 613 | 614 | .PARAMETER ColEnd 615 | The end column index expressed as an integer 616 | 617 | .PARAMETER Value 618 | The value you want to set in the cell 619 | 620 | .PARAMETER WorkSheet 621 | The WorkSheet object where the cell is located 622 | 623 | .PARAMETER Uri 624 | This option will try to convert the value to an hyperlink 625 | 626 | .PARAMETER StyleSheet 627 | The style sheet you want to apply to the cell 628 | 629 | .PARAMETER StyleSheetName 630 | the style sheet name that you want to apply to the cell 631 | 632 | .PARAMETER OutlineLevel 633 | The ouline Level for the whole row containing the cell 634 | 635 | .EXAMPLE 636 | $sheet | Set-OOXMLRangeValue -row 1 -col 1 -value "http:\\excelpslib.codeplex.com" -StyleSheetName "New Style" -Uri 637 | $sheet | Set-OOXMLRangeValue -Merge -Row 1 -Col 1 -RowEnd 10 -ColEnd 10 -Value "Merged Cells" -StyleSheetName "New Style" 638 | $Range = $sheet | Set-OOXMLRangeValue -row 1 -col 1 -value "http:\\excelpslib.codeplex.com" -StyleSheetName "New Style" -Uri 639 | 640 | Description 641 | ----------- 642 | Calls a function which set the value in a cell and optionally apply a stylesheet to it and return a ExcelRangeBase object in the given workbook object 643 | 644 | .NOTES 645 | 646 | .LINK 647 | 648 | #> 649 | [CmdletBinding()] 650 | param ( 651 | [parameter(ParameterSetName="CellRangeMerge", Mandatory=$true)] 652 | [switch]$Merge, 653 | [parameter(ParameterSetName="CellRangeMerge", Mandatory=$true)] 654 | [parameter(ParameterSetName="NoCellRangeMerge", Mandatory=$true)] 655 | [string]$Row, 656 | [parameter(ParameterSetName="CellRangeMerge", Mandatory=$true)] 657 | [parameter(ParameterSetName="NoCellRangeMerge", Mandatory=$true)] 658 | [string]$Col, 659 | [parameter(ParameterSetName="CellRangeMerge", Mandatory=$true)] 660 | [string]$RowEnd, 661 | [parameter(ParameterSetName="CellRangeMerge", Mandatory=$true)] 662 | [string]$ColEnd, 663 | [parameter(ParameterSetName="CellRangeMerge", Mandatory=$true)] 664 | [parameter(ParameterSetName="NoCellRangeMerge", Mandatory=$true)] 665 | [object]$Value, 666 | [parameter(ParameterSetName="CellRangeMerge", Mandatory=$true, ValueFromPipeline=$true)] 667 | [parameter(ParameterSetName="NoCellRangeMerge", Mandatory=$true, ValueFromPipeline=$true)] 668 | [OfficeOpenXml.ExcelWorksheet]$WorkSheet, 669 | [parameter(ParameterSetName="CellRangeMerge")] 670 | [parameter(ParameterSetName="NoCellRangeMerge")] 671 | 672 | [switch]$Uri, 673 | [parameter(ParameterSetName="CellRangeMerge")] 674 | [parameter(ParameterSetName="NoCellRangeMerge")] 675 | [OfficeOpenXml.Style.XmlAccess.ExcelNamedStyleXml]$StyleSheet, 676 | [parameter(ParameterSetName="CellRangeMerge")] 677 | [parameter(ParameterSetName="NoCellRangeMerge")] 678 | [String]$StyleSheetName, 679 | [parameter(ParameterSetName="CellRangeMerge")] 680 | [parameter(ParameterSetName="NoCellRangeMerge")] 681 | [int]$OutlineLevel 682 | 683 | ) 684 | process{ 685 | 686 | if($Merge) 687 | { 688 | $Coordinates = Convert-OOXMLCellsCoordinates -StartRow $row -StartCol $col -EndRow $RowEnd -EndCol $ColEnd 689 | $workSheet.Cells[$Coordinates].Merge = $true 690 | } 691 | else 692 | { 693 | $Coordinates = Convert-OOXMLCellsCoordinates -StartRow $row -StartCol $col 694 | } 695 | 696 | $WorkSheet.SetValue($row, $col, $value) | Out-Null 697 | 698 | if($OutlineLevel){ 699 | $WorkSheet.Row($row).OutlineLevel($OutlineLevel) 700 | } 701 | 702 | if($Uri){ 703 | $workSheet.Cells[$Coordinates].Hyperlink = new-object System.Uri($value) 704 | } 705 | 706 | if($StyleSheet){ 707 | $workSheet.Cells[$Coordinates].StyleName = $StyleSheet.Name 708 | }elseif($StyleSheetName){ 709 | $workSheet.Cells[$Coordinates].StyleName = $StyleSheetName 710 | } 711 | 712 | return [OfficeOpenXml.ExcelRangeBase]$workSheet.Cells[$Coordinates] 713 | } 714 | } 715 | 716 | Function Set-OOXMLRangeBorder { 717 | <# 718 | .SYNOPSIS 719 | Set the border style options for range of cell 720 | 721 | .DESCRIPTION 722 | Set the border style options for range of cell 723 | 724 | .PARAMETER BorderStyle 725 | The border style that will be applied to the range of cell 726 | 727 | .PARAMETER CellRange 728 | The cell range that where the options are to be applied 729 | 730 | .PARAMETER Color 731 | The color that will be applied to the range of cell 732 | 733 | .EXAMPLE 734 | $Range = Set-OOXMLRangeBorder -cellRange $range -borderStyle Thick -color red 735 | $Range = $Range | Set-OOXMLRangeBorder -borderStyle Thick -color red 736 | 737 | Description 738 | ----------- 739 | Calls a function which set the border style options for range of cells and return an ExcelRangeBase object 740 | 741 | .NOTES 742 | 743 | .LINK 744 | 745 | #> 746 | [CmdletBinding()] 747 | param( 748 | [parameter(Mandatory=$true)] 749 | [OfficeOpenXml.Style.ExcelBorderStyle]$BorderStyle, 750 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 751 | [OfficeOpenXml.ExcelRangeBase]$CellRange, 752 | [parameter(Mandatory=$true)] 753 | [System.Drawing.Color]$Color 754 | ) 755 | process{ 756 | Set-OOXMLRangeBorderTop -borderStyle $BorderStyle -cellRange $CellRange -color $Color 757 | Set-OOXMLRangeBorderRight -borderStyle $BorderStyle -cellRange $CellRange -color $Color 758 | Set-OOXMLRangeBorderBottom -borderStyle $BorderStyle -cellRange $CellRange -color $Color 759 | Set-OOXMLRangeBorderLeft -borderStyle $BorderStyle -cellRange $CellRange -color $Color 760 | return [OfficeOpenXml.ExcelRangeBase]$CellRange 761 | } 762 | 763 | } 764 | 765 | Function Set-OOXMLRangeBorderTop { 766 | <# 767 | .SYNOPSIS 768 | Set the top border style options for range of cell 769 | 770 | .DESCRIPTION 771 | Set the top border style options for range of cell 772 | 773 | .PARAMETER BorderStyle 774 | The border style that will be applied to the range of cell 775 | 776 | .PARAMETER CellRange 777 | The cell range that where the options are to be applied 778 | 779 | .PARAMETER Color 780 | The color that will be applied to the range of cell 781 | 782 | .EXAMPLE 783 | $Range = Set-OOXMLRangeBorderTop -cellRange $range -borderStyle Thick -color red 784 | $Range = $Range | Set-OOXMLRangeBorderTop -borderStyle Thick -color red 785 | 786 | Description 787 | ----------- 788 | Calls a function which set the top border style options for range of cells and return an ExcelRangeBase object 789 | 790 | .NOTES 791 | 792 | .LINK 793 | 794 | #> 795 | [CmdletBinding()] 796 | param( 797 | [parameter(Mandatory=$true)] 798 | [OfficeOpenXml.Style.ExcelBorderStyle]$borderStyle, 799 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 800 | [OfficeOpenXml.ExcelRangeBase]$cellRange, 801 | [parameter(Mandatory=$true)] 802 | [System.Drawing.Color]$color 803 | ) 804 | process{ 805 | $cellRange.Style.Border.Top.Style = $borderStyle 806 | $cellRange.Style.Border.Top.Color.SetColor($color) 807 | return [OfficeOpenXml.ExcelRangeBase]$cellRange 808 | } 809 | } 810 | 811 | Function Set-OOXMLRangeBorderRight { 812 | <# 813 | .SYNOPSIS 814 | Set the right border style options for range of cell 815 | 816 | .DESCRIPTION 817 | Set the right border style options for range of cell 818 | 819 | .PARAMETER BorderStyle 820 | The border style that will be applied to the range of cell 821 | 822 | .PARAMETER CellRange 823 | The cell range that where the options are to be applied 824 | 825 | .PARAMETER Color 826 | The color that will be applied to the range of cell 827 | 828 | .EXAMPLE 829 | $Range = Set-OOXMLRangeBorderRight -cellRange $range -borderStyle Thick -color red 830 | $Range = $Range | Set-OOXMLRangeBorderRight -borderStyle Thick -color red 831 | 832 | Description 833 | ----------- 834 | Calls a function which set the right border style options for range of cells and return an ExcelRangeBase object 835 | 836 | .NOTES 837 | 838 | .LINK 839 | 840 | #> 841 | [CmdletBinding()] 842 | param( 843 | [parameter(Mandatory=$true)] 844 | [OfficeOpenXml.Style.ExcelBorderStyle]$borderStyle, 845 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 846 | [OfficeOpenXml.ExcelRangeBase]$cellRange, 847 | [parameter(Mandatory=$true)] 848 | [System.Drawing.Color]$color 849 | ) 850 | process{ 851 | $cellRange.Style.Border.Right.Style = $borderStyle 852 | $cellRange.Style.Border.Right.Color.SetColor($color) 853 | return [OfficeOpenXml.ExcelRangeBase]$cellRange 854 | } 855 | } 856 | 857 | Function Set-OOXMLRangeBorderBottom { 858 | <# 859 | .SYNOPSIS 860 | Set the bottom border style options for range of cell 861 | 862 | .DESCRIPTION 863 | Set the bottom border style options for range of cell 864 | 865 | .PARAMETER BorderStyle 866 | The border style that will be applied to the range of cell 867 | 868 | .PARAMETER CellRange 869 | The cell range that where the options are to be applied 870 | 871 | .PARAMETER Color 872 | The color that will be applied to the range of cell 873 | 874 | .EXAMPLE 875 | $Range = Set-OOXMLRangeBorderBottom -cellRange $range -borderStyle Thick -color red 876 | $Range = $Range | Set-OOXMLRangeBorderBottom -borderStyle Thick -color red 877 | 878 | Description 879 | ----------- 880 | Calls a function which set the bottom border style options for range of cells and return an ExcelRangeBase object 881 | 882 | .NOTES 883 | 884 | .LINK 885 | 886 | #> 887 | [CmdletBinding()] 888 | param( 889 | [parameter(Mandatory=$true)] 890 | [OfficeOpenXml.Style.ExcelBorderStyle]$borderStyle, 891 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 892 | [OfficeOpenXml.ExcelRangeBase]$cellRange, 893 | [parameter(Mandatory=$true)] 894 | [System.Drawing.Color]$color 895 | ) 896 | process{ 897 | $cellRange.Style.Border.Bottom.Style = $borderStyle 898 | $cellRange.Style.Border.Bottom.Color.SetColor($color) 899 | return [OfficeOpenXml.ExcelRangeBase]$cellRange 900 | } 901 | } 902 | 903 | Function Set-OOXMLRangeBorderLeft { 904 | <# 905 | .SYNOPSIS 906 | Set the left border style options for range of cell 907 | 908 | .DESCRIPTION 909 | Set the left border style options for range of cell 910 | 911 | .PARAMETER BorderStyle 912 | The border style that will be applied to the range of cell 913 | 914 | .PARAMETER CellRange 915 | The cell range that where the options are to be applied 916 | 917 | .PARAMETER Color 918 | The color that will be applied to the range of cell 919 | 920 | .EXAMPLE 921 | $Range = Set-OOXMLRangeBorderLeft -cellRange $range -borderStyle Thick -color red 922 | $Range = $Range | Set-OOXMLRangeBorderLeft -borderStyle Thick -color red 923 | 924 | Description 925 | ----------- 926 | Calls a function which set the left border style options for range of cells and return an ExcelRangeBase object 927 | 928 | .NOTES 929 | 930 | .LINK 931 | 932 | #> 933 | [CmdletBinding()] 934 | param( 935 | [parameter(Mandatory=$true)] 936 | [OfficeOpenXml.Style.ExcelBorderStyle]$borderStyle, 937 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 938 | [OfficeOpenXml.ExcelRangeBase]$cellRange, 939 | [System.Drawing.Color]$color 940 | ) 941 | process{ 942 | $cellRange.Style.Border.Left.Style = $borderStyle 943 | $cellRange.Style.Border.Left.Color.SetColor($color) 944 | return [OfficeOpenXml.ExcelRangeBase]$cellRange 945 | } 946 | } 947 | 948 | Function Set-OOXMLRangeFill { 949 | <# 950 | .SYNOPSIS 951 | Set the fill style options for range of cell 952 | 953 | .DESCRIPTION 954 | Set the fill style options for range of cell 955 | 956 | .PARAMETER Type 957 | The fill type that will be applied to the range of cell 958 | 959 | .PARAMETER Color 960 | The color that will be applied to the range of cell 961 | 962 | .PARAMETER CellRange 963 | The cell range that where the options are to be applied 964 | 965 | .EXAMPLE 966 | $Range = Set-OOXMLRangeFill -cellRange $range -Type Solid -color red 967 | $Range = $Range | Set-OOXMLRangeFill -Type Solid -color red 968 | 969 | Description 970 | ----------- 971 | Calls a function which set the fill style options for range of cells and return an ExcelRangeBase object 972 | 973 | .NOTES 974 | 975 | .LINK 976 | 977 | #> 978 | [CmdletBinding()] 979 | param( 980 | [parameter(Mandatory=$true)] 981 | [OfficeOpenXml.Style.ExcelFillStyle]$Type, 982 | [parameter(Mandatory=$true)] 983 | [System.Drawing.Color]$color, 984 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 985 | [OfficeOpenXml.ExcelRangeBase]$cellRange, 986 | [switch]$Pass 987 | ) 988 | process{ 989 | $cellRange.Style.Fill.PatternType = $Type 990 | $cellRange.Style.Fill.BackgroundColor.SetColor($color) 991 | return [OfficeOpenXml.ExcelRangeBase]$cellRange 992 | } 993 | } 994 | 995 | Function Set-OOXMLRangeFont { 996 | <# 997 | .SYNOPSIS 998 | Set the font options for range of cell 999 | 1000 | .DESCRIPTION 1001 | Set the font options for range of cell 1002 | 1003 | .PARAMETER Bold 1004 | Set the font to bold 1005 | 1006 | .PARAMETER Italic 1007 | Set the font to italic 1008 | 1009 | .PARAMETER Underline 1010 | Set the font to underlined 1011 | 1012 | .PARAMETER Strike 1013 | Set the font to striked 1014 | 1015 | .PARAMETER Size 1016 | Set the font size 1017 | 1018 | .PARAMETER Color 1019 | The color that will be applied to the range of cell 1020 | 1021 | .PARAMETER CellRange 1022 | The cell range that where the options are to be applied 1023 | 1024 | .EXAMPLE 1025 | $Range = Set-OOXMLRangeFont -bold -italic -underline -strike -size 12 -color red -cellRange $Range 1026 | $Range = $Range | Set-OOXMLRangeFont -bold -italic -underline -strike -size 12 -color red 1027 | Set-OOXMLRangeFont -bold -italic -underline -strike -size 12 -color red 1028 | 1029 | Description 1030 | ----------- 1031 | Calls a function which set the font options for range of cells and return an ExcelRangeBase object 1032 | 1033 | .NOTES 1034 | 1035 | .LINK 1036 | 1037 | #> 1038 | [CmdletBinding()] 1039 | param( 1040 | [switch]$bold, 1041 | [switch]$italic, 1042 | [switch]$underline, 1043 | [switch]$strike, 1044 | [float]$size, 1045 | [System.Drawing.Color]$color, 1046 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 1047 | [OfficeOpenXml.ExcelRangeBase]$cellRange 1048 | ) 1049 | process{ 1050 | if($bold){$cellRange.Style.Font.Bold = $true}else{$cellRange.Style.Font.Bold = $false} 1051 | if($italic){$cellRange.Style.Font.Italic = $true}else{$cellRange.Style.Font.Italic = $false} 1052 | if($underline){$cellRange.Style.Font.UnderLine = $true}else{$cellRange.Style.Font.UnderLine = $false} 1053 | if($strike){$cellRange.Style.Font.Strike = $true}else{$cellRange.Style.Font.Strike = $false} 1054 | if($size){$cellRange.Style.Font.Size = $size} 1055 | if($color){$cellRange.Style.Font.Color.SetColor($color)} 1056 | return [OfficeOpenXml.ExcelRangeBase]$cellRange 1057 | } 1058 | } 1059 | 1060 | Function Set-OOXMLRangeTextOptions { 1061 | <# 1062 | .SYNOPSIS 1063 | Set some text options linked to how text must be displayed within a range of cell 1064 | 1065 | .DESCRIPTION 1066 | Set some text options linked to how text must be displayed within a range of cell 1067 | 1068 | .PARAMETER HAlign 1069 | Set the horizontal text alignement 1070 | 1071 | .PARAMETER VAlign 1072 | Set the vertical alignement type 1073 | 1074 | .PARAMETER NFormat 1075 | Format a number according to a definited patern 1076 | 1077 | .PARAMETER Wrap 1078 | Force end of the for line that are bigger than the cell 1079 | 1080 | .PARAMETER Shrink 1081 | Reduce the size of the text to fit in cell 1082 | 1083 | .PARAMETER Locked 1084 | Prevent text edition within a cell 1085 | 1086 | .PARAMETER TextRotation 1087 | Set the angle of the text 1088 | 1089 | .PARAMETER CellRange 1090 | The cell range that where the options are to be applied 1091 | 1092 | .EXAMPLE 1093 | $Range = Set-OOXMLRangeTextOptions -cellRange $Range -HAlign Center -VAlign Bottom -Wrap -Locked 1094 | $Range = $Range | Set-OOXMLRangeTextOptions -HAlign Center -VAlign Bottom -Wrap -Locked 1095 | Set-OOXMLRangeTextOptions -cellRange $Range -HAlign Center -VAlign Bottom -Wrap -Locked -TextRotation 90 1096 | 1097 | Description 1098 | ----------- 1099 | Calls a function which set some text options linked to how text must be displayed within a range of cells and return an ExcelRangeBase object 1100 | 1101 | .NOTES 1102 | 1103 | .LINK 1104 | 1105 | #> 1106 | [CmdletBinding()] 1107 | param( 1108 | [OfficeOpenXml.Style.ExcelHorizontalAlignment]$HAlign, 1109 | [OfficeOpenXml.Style.ExcelVerticalAlignment]$VAlign, 1110 | [string]$NFormat, 1111 | [switch]$Wrap, 1112 | [switch]$Shrink, 1113 | [switch]$Locked, 1114 | [ValidateScript({($_ -ge 0) -and ($_ -le 180)})] 1115 | [int]$TextRotation, 1116 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 1117 | [OfficeOpenXml.ExcelRangeBase]$cellRange 1118 | ) 1119 | process{ 1120 | if($HAlign){$cellRange.Style.HorizontalAlignment = $HAlign} 1121 | if($VAlign){$cellRange.Style.VerticalAlignment = $VAlign} 1122 | if($Wrap){$cellRange.Style.WrapText = $true}else{$cellRange.Style.WrapText = $false} 1123 | if($Shrink){$cellRange.Style.ShrinkToFit = $true}else{$cellRange.Style.ShrinkToFit = $false} 1124 | if($NFormat){$cellRange.Style.Numberformat.Format = $NFormat} 1125 | if($Locked){$cellRange.Style.Locked = $true}else{$cellRange.Style.Locked = $false} 1126 | if($TextRotation){$cellRange.Style.TextRotation = $TextRotation} 1127 | return [OfficeOpenXml.ExcelRangeBase]$cellRange 1128 | } 1129 | } 1130 | 1131 | Function Set-OOXMLPrinterSettings { 1132 | <# 1133 | .SYNOPSIS 1134 | Set some general printer settings 1135 | 1136 | .DESCRIPTION 1137 | Set some general printer settings 1138 | 1139 | .PARAMETER HorizontalCentered 1140 | Center horizontaly the sheet on the page 1141 | 1142 | .PARAMETER VerticalCentered 1143 | Center verticaly the sheet on the page 1144 | 1145 | .PARAMETER ShowGridLines 1146 | Print gridlines on the page 1147 | 1148 | .PARAMETER BlackAndWhite 1149 | Print in black and white only 1150 | 1151 | .PARAMETER FitToPage 1152 | Resize the sheet to fit in the page 1153 | 1154 | .PARAMETER RowRange 1155 | The cell row range to repeat on every pages 1156 | 1157 | .PARAMETER ColRange 1158 | The cell column range to repeat on every pages 1159 | 1160 | .PARAMETER WorkSheet 1161 | The WorkSheet object where the cell is located 1162 | 1163 | .EXAMPLE 1164 | $sheet = $sheet | Set-OOXMLPrinterSettings -HorizontalCentered -VerticalCentered -FitToPage -ShowGridLines 1165 | $sheet | Set-OOXMLPrinterSettings -HorizontalCentered -VerticalCentered -FitToPage -ShowGridLines 1166 | Set-OOXMLPrinterSettings -WorkSheet $sheet -HorizontalCentered -VerticalCentered -FitToPage -ShowGridLines 1167 | 1168 | Description 1169 | ----------- 1170 | Calls a function which set some print options linked to how the sheet must be printed and return an ExcelWorksheet object 1171 | 1172 | .NOTES 1173 | 1174 | .LINK 1175 | 1176 | #> 1177 | [CmdletBinding()] 1178 | param( 1179 | [switch]$HorizontalCentered, 1180 | [switch]$VerticalCentered, 1181 | [switch]$ShowGridLines, 1182 | [switch]$BlackAndWhite, 1183 | [switch]$FitToPage, 1184 | [OfficeOpenXml.ExcelRangeBase]$RowRange, 1185 | [OfficeOpenXml.ExcelRangeBase]$ColRange, 1186 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 1187 | [OfficeOpenXml.ExcelWorksheet]$WorkSheet 1188 | ) 1189 | process{ 1190 | if($ColRange){$WorkSheet.PrinterSettings.RepeatColumns = $ColRange} 1191 | if($RowRange){$WorkSheet.PrinterSettings.RepeatRows = $RowRange} 1192 | if($BlackAndWhite){$WorkSheet.PrinterSettings.BlackAndWhite = $true}else{$WorkSheet.PrinterSettings.BlackAndWhite = $false} 1193 | if($ShowGridLines){$WorkSheet.PrinterSettings.ShowGridLines = $true}else{$WorkSheet.PrinterSettings.ShowGridLines = $false} 1194 | if($HorizontalCentered){$WorkSheet.PrinterSettings.HorizontalCentered = $true}else{$WorkSheet.PrinterSettings.HorizontalCentered = $false} 1195 | if($VerticalCentered){$WorkSheet.PrinterSettings.VerticalCentered = $true}else{$WorkSheet.PrinterSettings.VerticalCentered = $false} 1196 | if($FitToPage){$WorkSheet.PrinterSettings.FitToPage = $true}else{$WorkSheet.PrinterSettings.FitToPage = $false} 1197 | return [OfficeOpenXml.ExcelWorksheet]$WorkSheet 1198 | } 1199 | 1200 | } 1201 | 1202 | Function Get-OOXMLHelp { 1203 | <# 1204 | .SYNOPSIS 1205 | Display the full OOXML Module Help File 1206 | 1207 | .DESCRIPTION 1208 | Display the full OOXML Module Help File 1209 | 1210 | .EXAMPLE 1211 | Get-OOXMLHelp 1212 | 1213 | Description 1214 | ----------- 1215 | Calls a function that will display the full OOXML Module Help File 1216 | 1217 | .NOTES 1218 | 1219 | .LINK 1220 | 1221 | #> 1222 | foreach($Command in $(Get-Command -Module excelpslib)){ 1223 | Get-Help -Name $($Command.Name) 1224 | } 1225 | } 1226 | 1227 | Function Get-OOXMLDeprecatedCommand { 1228 | <# 1229 | .SYNOPSIS 1230 | Generate aliases for backward compatibility 1231 | 1232 | .DESCRIPTION 1233 | Generate aliases for backward compatibility 1234 | 1235 | .EXAMPLE 1236 | Get-OOXMLDeprecatedCommand 1237 | 1238 | Description 1239 | ----------- 1240 | Calls a function that will generate aliases for backward compatibility 1241 | 1242 | .NOTES 1243 | 1244 | .LINK 1245 | 1246 | #> 1247 | Set-Alias CreateExcelInstance New-OOXMLPackage -Scope "Global" 1248 | Set-Alias CreateWorkSheet Add-OOXMLWorksheet -Scope "Global" 1249 | Set-Alias GetWorkBook Get-OOXMLWorkbook -Scope "Global" 1250 | Set-Alias SelectWorkSheet Select-OOXMLWorkSheet -Scope "Global" 1251 | Set-Alias SetValueAt Set-OOXMLRangeValue -Scope "Global" 1252 | Set-Alias SetBorder Set-OOXMLRangeBorder -Scope "Global" 1253 | Set-Alias SetBorderTop Set-OOXMLRangeBorderTop -Scope "Global" 1254 | Set-Alias SetBorderRight Set-OOXMLRangeBorderRight -Scope "Global" 1255 | Set-Alias SetBorderBottom Set-OOXMLRangeBorderBottom -Scope "Global" 1256 | Set-Alias SetBorderLeft Set-OOXMLRangeBorderLeft -Scope "Global" 1257 | Set-Alias SetFont Set-OOXMLRangeFont -Scope "Global" 1258 | Set-Alias SetFill Set-OOXMLRangeFill -Scope "Global" 1259 | Set-Alias SetTextOptions Set-OOXMLRangeTextOptions -Scope "Global" 1260 | Set-Alias SetPrinterSettings Set-OOXMLPrinterSettings -Scope "Global" 1261 | Set-Alias SaveFile Save-OOXMLPackage -Scope "Global" 1262 | Set-Alias Get-ColumnString Get-OOXMLColumnString -Scope "Global" 1263 | } 1264 | 1265 | Function Convert-OOXMLOldScripts { 1266 | <# 1267 | .SYNOPSIS 1268 | Convert to the new format all the old commands 1269 | 1270 | .DESCRIPTION 1271 | Convert to the new format all the old commands 1272 | 1273 | .PARAMETER InputFile 1274 | The row decimal coordinate 1275 | 1276 | .PARAMETER OutputFile 1277 | The column decimal coordinate 1278 | 1279 | .EXAMPLE 1280 | Convert-OOXMLOldScripts -InputFile "C:\Old_Script.ps1" -OutpuFile "C:\New_Script.ps1" 1281 | 1282 | Description 1283 | ----------- 1284 | Calls a function to convert to the new format all the old commands 1285 | 1286 | .NOTES 1287 | 1288 | .LINK 1289 | 1290 | #> 1291 | [CmdletBinding()] 1292 | param( 1293 | [parameter(Mandatory=$true)] 1294 | [string]$InputFile, 1295 | [parameter(Mandatory=$true)] 1296 | [string]$OutputFile 1297 | ) 1298 | process { 1299 | $lookupTable = @{ 1300 | 'CreateExcelInstance' = 'New-OOXMLPackage' 1301 | 'CreateWorkSheet' = 'Add-OOXMLWorksheet' 1302 | 'GetWorkBook' = 'Get-OOXMLWorkbook' 1303 | 'SelectWorkSheet' = 'Select-OOXMLWorkSheet' 1304 | 'SetValueAt' = 'Set-OOXMLRangeValue' 1305 | 'SetBorder' = 'Set-OOXMLRangeBorder' 1306 | 'SetFont' = 'Set-OOXMLRangeFont' 1307 | 'SetFill' = 'Set-OOXMLRangeFill' 1308 | 'SetPrinterSettings' = 'Set-OOXMLPrinterSettings' 1309 | 'SetTextOptions' = 'Set-OOXMLRangeTextOptions' 1310 | 'Get-ColumnString' ='Get-OOXMLColumnString' 1311 | 'SaveFile' = 'Save-OOXMLPackage' 1312 | } 1313 | if(Test-Path -Path $inputFile){ 1314 | Get-Content -Path $inputFile | ForEach-Object { 1315 | $line = $_ 1316 | $lookupTable.GetEnumerator() | ForEach-Object { 1317 | if ($line -match $_.Key) {$line = $line -replace $_.Key, $_.Value} 1318 | } 1319 | $line 1320 | } | Set-Content -Path $outputFile 1321 | } 1322 | } 1323 | } 1324 | 1325 | Function Convert-OOXMLCellsCoordinates { 1326 | <# 1327 | .SYNOPSIS 1328 | Convert decimal coordinate(s) to an excel coordinate style numbering 1329 | 1330 | .DESCRIPTION 1331 | Convert decimal coordinate(s) to an excel coordinate style numbering 1332 | 1333 | .PARAMETER StartRow 1334 | The row decimal coordinate 1335 | 1336 | .PARAMETER StartCol 1337 | The column decimal coordinate 1338 | 1339 | .PARAMETER EndRow 1340 | The row decimal coordinate 1341 | 1342 | .PARAMETER EndCol 1343 | The column decimal coordinate 1344 | 1345 | .EXAMPLE 1346 | $coordinates = Convert-OOXMLCellsCoordinates -StartRow 1 -StartCol 1 -EndRow 100 -EndCol 16 1347 | 1348 | Description 1349 | ----------- 1350 | Calls a function to convert decimal coordinate(s) to an excel coordinate style numbering and return it 1351 | 1352 | .NOTES 1353 | 1354 | .LINK 1355 | 1356 | #> 1357 | [CmdletBinding(DefaultParametersetName="None")] 1358 | param ( 1359 | 1360 | [parameter(Mandatory=$true)] 1361 | [int]$StartRow, 1362 | 1363 | [parameter(Mandatory=$true)] 1364 | [int]$StartCol, 1365 | 1366 | [parameter(ParameterSetName="MultipleCells", Mandatory=$true)] 1367 | [int]$EndRow, 1368 | 1369 | [parameter(ParameterSetName="MultipleCells", Mandatory=$true)] 1370 | [int]$EndCol 1371 | ) 1372 | process{ 1373 | [string]$Coordinates = [string]::Empty 1374 | [string]$StartString = Get-OOXMLColumnString -ColNumber $StartCol 1375 | $Coordinates = $StartString+$StartRow 1376 | if($EndRow -and $EndCol){ 1377 | [string]$EndString = Get-OOXMLColumnString -ColNumber $EndCol 1378 | $Coordinates = $Coordinates+":"+$EndString+$EndRow 1379 | } 1380 | return [string]$Coordinates 1381 | } 1382 | } 1383 | 1384 | Function Get-OOXMLColumnString { 1385 | <# 1386 | .SYNOPSIS 1387 | Convert a decimal number to an excel column style numbering 1388 | 1389 | .DESCRIPTION 1390 | Convert a decimal number to an excel column style numbering 1391 | 1392 | .PARAMETER ColNumber 1393 | The decimal colomn number to be converted 1394 | 1395 | .EXAMPLE 1396 | Get-OOXMLColumnString -ColNumber 34 1397 | 1398 | Description 1399 | ----------- 1400 | Calls a function Convert a decimal number to an excel column style numbering and return it 1401 | 1402 | .NOTES 1403 | 1404 | .LINK 1405 | 1406 | #> 1407 | [CmdletBinding()] 1408 | param ( 1409 | [ValidateScript({$_ -ge 1})] 1410 | [int]$ColNumber 1411 | ) 1412 | return [OfficeOpenXml.ExcelCellAddress]::GetColumnLetter($ColNumber) 1413 | } 1414 | 1415 | Function New-OOXMLPivotTable { 1416 | <# 1417 | .SYNOPSIS 1418 | Create a PivotTable in the given worksheet and return the created PivotTable 1419 | 1420 | .DESCRIPTION 1421 | Create a PivotTable in the given worksheet and return the created PivotTable 1422 | 1423 | .PARAMETER WorkSheet 1424 | Worksheet where are the data located 1425 | 1426 | .PARAMETER Origin 1427 | Location of the upper left corner of the pivot table 1428 | 1429 | .PARAMETER Datas 1430 | The data to be processed by the pivot table 1431 | 1432 | .PARAMETER Name 1433 | The name of the pivot table 1434 | 1435 | .EXAMPLE 1436 | New-OOXMLPivotTable -WorkSheet $sheet -origin "$A$932" -Datas "$A$1:$E$910" -Name "New Pivot Table" 1437 | 1438 | Description 1439 | ----------- 1440 | Calls a function which create a PivotTable in the given worksheet and return an ExcelPivotTable object 1441 | 1442 | .NOTES 1443 | This function is really basic and must be improved 1444 | 1445 | .LINK 1446 | 1447 | #> 1448 | [CmdletBinding()] 1449 | param( 1450 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 1451 | [OfficeOpenXml.ExcelWorksheet]$WorkSheet, 1452 | [parameter(Mandatory=$true)] 1453 | [string]$Origin = [string]::Empty, 1454 | [parameter(Mandatory=$true)] 1455 | [string]$Datas = [string]::Empty, 1456 | [parameter(Mandatory=$true)] 1457 | [string]$Name = [string]::Empty 1458 | ) 1459 | process{ 1460 | [OfficeOpenXml.Table.PivotTable.ExcelPivotTable]$Pivot = $WorkSheet.PivotTables.Add($WorkSheet.Cells[$Origin],$WorkSheet.Cells[$Datas], $Name) 1461 | return [OfficeOpenXml.Table.PivotTable.ExcelPivotTable]$Pivot 1462 | } 1463 | 1464 | } 1465 | 1466 | Function Set-OOXMLStyleSheet { 1467 | <# 1468 | .SYNOPSIS 1469 | Assign a style sheet to a range of cell 1470 | 1471 | .DESCRIPTION 1472 | Assign a style sheet to a range of cell 1473 | 1474 | .PARAMETER CellRange 1475 | The cell range that style sheet is to be applied 1476 | 1477 | .PARAMETER StyleSheet 1478 | The style sheet object that you want to use 1479 | 1480 | .PARAMETER StyleSheetName 1481 | The style sheet object name that you want to use 1482 | 1483 | 1484 | .EXAMPLE 1485 | $Range | Set-OOXMLStyleSheet -StyleSheet $Style 1486 | Set-OOXMLStyleSheet -cellRange $Range -StyleSheet $Style 1487 | 1488 | Description 1489 | ----------- 1490 | Calls a function which assign a style sheet to a range of cell and return an ExcelRangeBase object 1491 | 1492 | .NOTES 1493 | 1494 | .LINK 1495 | 1496 | #> 1497 | [CmdletBinding()] 1498 | param( 1499 | [parameter(ParameterSetName="WithStyleSheetObject", Mandatory=$true, ValueFromPipeline=$true)] 1500 | [parameter(ParameterSetName="WithStyleSheetName", Mandatory=$true, ValueFromPipeline=$true)] 1501 | [OfficeOpenXml.ExcelRangeBase]$cellRange, 1502 | 1503 | [parameter(ParameterSetName="WithStyleSheetObject", Mandatory=$true)] 1504 | [OfficeOpenXml.Style.XmlAccess.ExcelNamedStyleXml]$StyleSheet, 1505 | 1506 | [parameter(ParameterSetName="WithStyleSheetName", Mandatory=$true)] 1507 | [string]$StyleSheetName 1508 | ) 1509 | process{ 1510 | if($StyleSheet){ 1511 | $cellRange.StyleName = $StyleSheet.Name 1512 | }else{ 1513 | $cellRange.StyleName = $StyleSheetName 1514 | } 1515 | return [OfficeOpenXml.ExcelRangeBase]$cellRange 1516 | } 1517 | } 1518 | 1519 | Function New-OOXMLStyleSheet { 1520 | <# 1521 | .SYNOPSIS 1522 | Create a style sheet object 1523 | 1524 | .DESCRIPTION 1525 | Create a style sheet object 1526 | 1527 | .PARAMETER WorkBook 1528 | The workbook in the Excel instance 1529 | 1530 | .PARAMETER Name 1531 | The name you want to give to your style sheet 1532 | 1533 | .PARAMETER HAlign 1534 | Set the horizontal text alignement 1535 | 1536 | .PARAMETER VAlign 1537 | Set the vertical alignement type 1538 | 1539 | .PARAMETER NFormat 1540 | Format a number according to a definited patern 1541 | 1542 | .PARAMETER Wrap 1543 | Force end of the for line that are bigger than the cell 1544 | 1545 | .PARAMETER Shrink 1546 | Reduce the size of the text to fit in cell 1547 | 1548 | .PARAMETER Locked 1549 | Prevent text edition within a cell 1550 | 1551 | .PARAMETER Bold 1552 | Set the font to bold 1553 | 1554 | .PARAMETER Italic 1555 | Set the font to italic 1556 | 1557 | .PARAMETER Underline 1558 | Set the font to underlined 1559 | 1560 | .PARAMETER Strike 1561 | Set the font to striked 1562 | 1563 | .PARAMETER Size 1564 | Set the font size 1565 | 1566 | .PARAMETER TextRotation 1567 | Set the angle of the text 1568 | 1569 | .PARAMETER ForeGroundColor 1570 | The color that will be applied to the text 1571 | 1572 | .PARAMETER FillType 1573 | The type of fill style to use on the background 1574 | 1575 | .PARAMETER BackGroundColor 1576 | The color that will be applied to the background 1577 | 1578 | .PARAMETER BorderStyle 1579 | The border style that will be applied to the range of cell 1580 | 1581 | .PARAMETER BorderColor 1582 | The color that will be applied to the border 1583 | 1584 | .EXAMPLE 1585 | $Style = New-OOXMLStyleSheet -WorkBook $book -Name "FirstStyle" -FillType solid -HAlign Center -Italic -Size 14 -BackGroundColor Red -TextRotation 90 1586 | $Style = $book | New-OOXMLStyleSheet -Name "FirstStyle" -FillType solid -HAlign Center -Italic -Size 14 -BackGroundColor Red 1587 | 1588 | Description 1589 | ----------- 1590 | Calls a function which will create, configure and return an ExcelNamedStyleXml object 1591 | 1592 | .NOTES 1593 | 1594 | .LINK 1595 | 1596 | #> 1597 | [CmdletBinding(DefaultParametersetName="None")] 1598 | param( 1599 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 1600 | [OfficeOpenXml.ExcelWorkbook]$WorkBook, 1601 | [parameter(Mandatory=$true)] 1602 | [string]$Name, 1603 | [OfficeOpenXml.Style.ExcelHorizontalAlignment]$HAlign, 1604 | [OfficeOpenXml.Style.ExcelVerticalAlignment]$VAlign, 1605 | [string]$NFormat, 1606 | [switch]$Wrap, 1607 | [switch]$Shrink, 1608 | [switch]$Locked, 1609 | [switch]$Bold, 1610 | [switch]$Italic, 1611 | [switch]$Underline, 1612 | [switch]$Strike, 1613 | [float]$Size, 1614 | [ValidateScript({($_ -ge 0) -and ($_ -le 180)})] 1615 | [int]$TextRotation, 1616 | [System.Drawing.Color]$ForeGroundColor, 1617 | [OfficeOpenXml.Style.ExcelFillStyle]$FillType, 1618 | [System.Drawing.Color]$BackGroundColor, 1619 | [OfficeOpenXml.Style.ExcelBorderStyle]$borderStyle, 1620 | [System.Drawing.Color]$BorderColor 1621 | ) 1622 | process{ 1623 | 1624 | if($WorkBook.Styles.NamedStyles.Name -notcontains $Name) 1625 | { 1626 | $StyleSheet = $WorkBook.Styles.CreateNamedStyle($Name) 1627 | 1628 | if($borderStyle){ 1629 | $StyleSheet.Style.Border.Left.Style = $borderStyle 1630 | $StyleSheet.Style.Border.Bottom.Style = $borderStyle 1631 | $StyleSheet.Style.Border.Right.Style = $borderStyle 1632 | $StyleSheet.Style.Border.Top.Style = $borderStyle 1633 | } 1634 | 1635 | if($BorderColor){ 1636 | $StyleSheet.Style.Border.Left.Color.SetColor($BorderColor) 1637 | $StyleSheet.Style.Border.Bottom.Color.SetColor($BorderColor) 1638 | $StyleSheet.Style.Border.Right.Color.SetColor($BorderColor) 1639 | $StyleSheet.Style.Border.Top.Color.SetColor($BorderColor) 1640 | } 1641 | 1642 | if($FillType){$StyleSheet.Style.Fill.PatternType = $FillType} 1643 | if($BackGroundColor){$StyleSheet.Style.Fill.BackgroundColor.SetColor($BackGroundColor)} 1644 | 1645 | if($bold){$StyleSheet.Style.Font.Bold = $true}else{$StyleSheet.Style.Font.Bold = $false} 1646 | if($italic){$StyleSheet.Style.Font.Italic = $true}else{$StyleSheet.Style.Font.Italic = $false} 1647 | if($underline){$StyleSheet.Style.Font.UnderLine = $true}else{$StyleSheet.Style.Font.UnderLine = $false} 1648 | if($strike){$StyleSheet.Style.Font.Strike = $true}else{$StyleSheet.Style.Font.Strike = $false} 1649 | if($size){$StyleSheet.Style.Font.Size = $size} 1650 | if($ForeGroundColor){$StyleSheet.Style.Font.Color.SetColor($ForeGroundColor)} 1651 | 1652 | if($HAlign){$StyleSheet.Style.HorizontalAlignment = $HAlign} 1653 | if($VAlign){$StyleSheet.Style.VerticalAlignment = $VAlign} 1654 | if($Wrap){$StyleSheet.Style.WrapText = $true}else{$StyleSheet.Style.WrapText = $false} 1655 | if($Shrink){$StyleSheet.Style.ShrinkToFit = $true}else{$StyleSheet.Style.ShrinkToFit = $false} 1656 | if($NFormat){$StyleSheet.Style.Numberformat.Format = $NFormat} 1657 | if($Locked){$StyleSheet.Style.Locked = $true}else{$StyleSheet.Style.Locked = $false} 1658 | if($TextRotation){$StyleSheet.Style.TextRotation = $TextRotation} 1659 | } 1660 | else 1661 | { 1662 | for($i=0;$i -lt $Book.Styles.NamedStyles.Count; $i++) 1663 | { 1664 | if($Book.Styles.NamedStyles[$i].Name -like $Name) 1665 | { 1666 | return [OfficeOpenXml.Style.XmlAccess.ExcelNamedStyleXml]$WorkBook.Styles.NamedStyles[$i] 1667 | } 1668 | } 1669 | } 1670 | 1671 | return [OfficeOpenXml.Style.XmlAccess.ExcelNamedStyleXml]$StyleSheet 1672 | } 1673 | } 1674 | 1675 | Function New-OOXMLStyleSheetData { 1676 | <# 1677 | .SYNOPSIS 1678 | Create a style sheet data object 1679 | 1680 | .DESCRIPTION 1681 | Create a style sheet data object 1682 | 1683 | .PARAMETER Name 1684 | The name you want to give to your style sheet 1685 | 1686 | .PARAMETER HAlign 1687 | Set the horizontal text alignement 1688 | 1689 | .PARAMETER VAlign 1690 | Set the vertical alignement type 1691 | 1692 | .PARAMETER NFormat 1693 | Format a number according to a definited patern 1694 | 1695 | .PARAMETER Wrap 1696 | Force end of the for line that are bigger than the cell 1697 | 1698 | .PARAMETER Shrink 1699 | Reduce the size of the text to fit in cell 1700 | 1701 | .PARAMETER Locked 1702 | Prevent text edition within a cell 1703 | 1704 | .PARAMETER Bold 1705 | Set the font to bold 1706 | 1707 | .PARAMETER Italic 1708 | Set the font to italic 1709 | 1710 | .PARAMETER Underline 1711 | Set the font to underlined 1712 | 1713 | .PARAMETER Strike 1714 | Set the font to striked 1715 | 1716 | .PARAMETER Size 1717 | Set the font size 1718 | 1719 | .PARAMETER TextRotation 1720 | Set the angle of the text 1721 | 1722 | .PARAMETER ForeGroundColor 1723 | The color that will be applied to the text 1724 | 1725 | .PARAMETER FillType 1726 | The type of fill style to use on the background 1727 | 1728 | .PARAMETER BackGroundColor 1729 | The color that will be applied to the background 1730 | 1731 | .PARAMETER BorderStyle 1732 | The border style that will be applied to the range of cell 1733 | 1734 | .PARAMETER BorderColor 1735 | The color that will be applied to the border 1736 | 1737 | .EXAMPLE 1738 | $Style = New-OOXMLStyleSheetData -Name "FirstStyle" -FillType solid -HAlign Center -Italic -Size 14 -BackGroundColor Red -TextRotation 90 1739 | 1740 | Description 1741 | ----------- 1742 | Calls a function which will return an style data object to be used in Export-OOXML 1743 | 1744 | .NOTES 1745 | 1746 | .LINK 1747 | 1748 | #> 1749 | param( 1750 | [parameter(Mandatory=$true)] 1751 | [string]$Name, 1752 | [OfficeOpenXml.Style.ExcelHorizontalAlignment]$HAlign = [OfficeOpenXml.Style.ExcelHorizontalAlignment]::Center, 1753 | [OfficeOpenXml.Style.ExcelVerticalAlignment]$VAlign = [OfficeOpenXml.Style.ExcelHorizontalAlignment]::Center, 1754 | [string]$NFormat, 1755 | [switch]$Wrap = $true, 1756 | [switch]$Shrink = $false, 1757 | [switch]$Locked = $false, 1758 | [switch]$Bold = $false, 1759 | [switch]$Italic = $false, 1760 | [switch]$Underline = $false, 1761 | [switch]$Strike = $false, 1762 | [float]$Size = 14, 1763 | [ValidateScript({($_ -ge 0) -and ($_ -le 180)})] 1764 | [int]$TextRotation, 1765 | [System.Drawing.Color]$ForeGroundColor = [System.Drawing.Color]::White, 1766 | [OfficeOpenXml.Style.ExcelFillStyle]$FillType = [OfficeOpenXml.Style.ExcelFillStyle]::Solid, 1767 | [System.Drawing.Color]$BackGroundColor = [System.Drawing.Color]::Black, 1768 | [OfficeOpenXml.Style.ExcelBorderStyle]$borderStyle = [OfficeOpenXml.Style.ExcelBorderStyle]::Thick, 1769 | [System.Drawing.Color]$BorderColor = [System.Drawing.Color]::Black 1770 | ) 1771 | process{ 1772 | return [pscustomobject]@{ 1773 | Name = $Name 1774 | HAlign = $HAlign 1775 | VAlign = $VAlign 1776 | NFormat= $NFormat 1777 | Wrap = $Wrap 1778 | Shrink = $Shrink 1779 | Locked = $Locked 1780 | Bold = $Bold 1781 | Italic = $Italic 1782 | Underline = $Underline 1783 | Strike = $Strike 1784 | Size = $Size 1785 | TextRotation = $TextRotation 1786 | ForeGroundColor = $ForeGroundColor 1787 | FillType = $FillType 1788 | BackGroundColor = $BackGroundColor 1789 | borderStyle = $borderStyle 1790 | BorderColor = $BorderColor 1791 | } 1792 | } 1793 | } 1794 | 1795 | Function Export-OOXML { 1796 | <# 1797 | .SYNOPSIS 1798 | Export an array of objects to an XLSX File 1799 | 1800 | .DESCRIPTION 1801 | Export an array of objects to an XLSX File 1802 | 1803 | .PARAMETER InputObject 1804 | The array object that will be exported to an XLSX File 1805 | 1806 | .PARAMETER FileFullPath 1807 | The full path of the XLSX File 1808 | 1809 | .PARAMETER DocumentName 1810 | The name of the XLSX Document 1811 | 1812 | .PARAMETER WorksheetName 1813 | The name of the worksheet in the XLSX Document 1814 | 1815 | .PARAMETER IncludedProperties 1816 | An array object containing the names of the object properties you want to export. This list is ordered !!! 1817 | 1818 | .PARAMETER ConditionalFormatings 1819 | The conditional formating you want to apply 1820 | 1821 | .PARAMETER FormulaObjects 1822 | The formula you want to apply to a whole column 1823 | 1824 | .PARAMETER OrderedProperties 1825 | This allow you to order the columns either Ascending or Descending 1826 | 1827 | .PARAMETER AutoFit 1828 | Auto size the columns 1829 | 1830 | .PARAMETER HeaderStyle 1831 | Set the style of the header to a predefinited style 1832 | 1833 | .PARAMETER HeaderTextRotation 1834 | Set the orientation of the header 1835 | 1836 | .PARAMETER HeaderCustomStyles 1837 | This parameter will change the style of one or more header You must give an array of Hashtable as argument : @{Name=;Data=} 1838 | 1839 | .PARAMETER Precise 1840 | This parameter will toogle the conditional formating mode to the precise mode by formating only a given column 1841 | in place of the entire row. 1842 | 1843 | .PARAMETER DataValidationLists 1844 | This parameter shoud receive an array of objects in the format produced by the Get-OOXMLDataValidationCustomObject this will only add data on an 1845 | addtional "REF_DATA" worksheet. This parameter must by used in combination with .... 1846 | 1847 | .PARAMETER DataValidationAssignements 1848 | 1849 | 1850 | 1851 | .EXAMPLE 1852 | 1853 | $p = Get-Process 1854 | 1855 | Import-Module -Name ExcelPSLib -Force 1856 | 1857 | $FirstList = Get-OOXMLDataValidationCustomObject -Name "FirstList" -Values @("Value001","Value002","Value003") 1858 | $secondList = Get-OOXMLDataValidationCustomObject -Name "SecondList" -Values @("Value00X","Value00Y","Value00Z") 1859 | 1860 | $FirstAssignement = Get-OOXMLDataValidationAssignementCustomObject -DataValidationName "FirstList" -ColumnNames @("Name","Handles") 1861 | $SecondAssignement = Get-OOXMLDataValidationAssignementCustomObject -DataValidationName "SecondList" -ColumnNames @("WS","VM") 1862 | 1863 | $Red = Get-OOXMLConditonalFormattingCustomObject -Name "Name" -Style Red -Condition ContainsText -Value "host" 1864 | $Green = Get-OOXMLConditonalFormattingCustomObject -Name "Name" -Style Green -Condition ContainsText -Value "32" 1865 | 1866 | $FormulaOne = Get-OOXMLFormulaObject -Name "Handles" -Style Beige -Operation AVERAGE 1867 | 1868 | $HeaderStyle = New-OOXMLStyleSheetData -Name "HeaderDemoStyle" -FillType solid -HAlign Center -Italic -Size 14 -BackGroundColor Red -TextRotation 90 1869 | 1870 | Export-OOXML -InputObject $p ` 1871 | -FileFullPath "C:\temp\datavalidationtestX.xlsx" ` 1872 | -DataValidationLists @($FirstList,$secondList) ` 1873 | -DataValidationAssignements @($FirstAssignement,$SecondAssignement) ` 1874 | -FreezedColumnName "VM" ` 1875 | -AutoFit ` 1876 | -DocumentName "OOXMLDemo" ` 1877 | -HeaderStyle Gray ` 1878 | -WorksheetName "OOXMLDemo" ` 1879 | -ConditionalFormatings @($Red,$Green) ` 1880 | -FormulaObjects @($FormulaOne) ` 1881 | -HeaderCustomStyles @(@{Name="Company";Data=$HeaderStyle}) ` 1882 | -OrderedProperties Ascending 1883 | 1884 | Description 1885 | ----------- 1886 | Calls a function that will export the content of an array to an XLSX file 1887 | 1888 | .NOTES 1889 | 1890 | .LINK 1891 | 1892 | #> 1893 | [CmdletBinding()] 1894 | param( 1895 | [parameter(Mandatory=$true, ValueFromPipeline=$true)] 1896 | [object[]]$InputObject, 1897 | [ValidateScript({Test-Path -Path $_ -PathType Leaf -IsValid})] 1898 | [parameter(Mandatory=$true)] 1899 | [string]$FileFullPath, 1900 | [string]$DocumentName = "ExcelPSLib", 1901 | [string]$WorksheetName = "ExcelPSLib", 1902 | [string[]]$IncludedProperties, 1903 | [string]$FreezedColumnName, 1904 | [object[]]$ConditionalFormatings, 1905 | [object[]]$FormulaObjects, 1906 | [switch]$AutoFit, 1907 | [ValidateSet("Ascending","Descending")] 1908 | [string]$OrderedProperties, 1909 | [ExcelPSLib.EnumColors]$HeaderStyle = [ExcelPSLib.EnumColors]::Black, 1910 | [ValidateScript({($_ -ge 0) -and ($_ -le 180)})] 1911 | [int]$HeaderTextRotation = 0, 1912 | [object[]]$HeaderCustomStyles, 1913 | [switch]$Precise, 1914 | [parameter(ParameterSetName="DataValidation")] 1915 | [object[]]$DataValidationLists, 1916 | [parameter(ParameterSetName="DataValidation")] 1917 | [object[]]$DataValidationAssignements, 1918 | [object[]]$CustomFormatings, 1919 | [switch]$AddToExistingDocument 1920 | ) 1921 | process{ 1922 | 1923 | try 1924 | { 1925 | if($IncludedProperties){ 1926 | 1927 | $RawReferencePropertySet = $($InputObject[0].PSObject.Properties).Name 1928 | [string[]]$ReferencePropertySet = @() 1929 | 1930 | foreach($IncludedProperty in $IncludedProperties) 1931 | { 1932 | if($RawReferencePropertySet -contains $IncludedProperty) 1933 | { 1934 | $ReferencePropertySet += $IncludedProperty 1935 | } 1936 | } 1937 | } 1938 | else 1939 | { 1940 | $ReferencePropertySet = $($InputObject[0].PSObject.Properties).Name 1941 | } 1942 | 1943 | if($OrderedProperties -like "Ascending") 1944 | { 1945 | [System.Array]::Sort($ReferencePropertySet) 1946 | } 1947 | 1948 | if($OrderedProperties -like "Descending") 1949 | { 1950 | [System.Array]::Sort($ReferencePropertySet) 1951 | [System.Array]::Reverse($ReferencePropertySet) 1952 | } 1953 | 1954 | $ColumnNumber = $ReferencePropertySet.Length 1955 | 1956 | $RowPosition = 2 1957 | 1958 | if($AddToExistingDocument) 1959 | { 1960 | [OfficeOpenXml.ExcelPackage]$excel = New-OOXMLPackage -author "ExcelPSLib" -title $DocumentName -Path $FileFullPath 1961 | [OfficeOpenXml.ExcelWorkbook]$book = $excel | Get-OOXMLWorkbook 1962 | 1963 | $AutofilterRange = Convert-OOXMLCellsCoordinates -StartRow $RowPosition -EndRow $RowPosition -StartCol 1 -EndCol $ColumnNumber 1964 | 1965 | $excel | Add-OOXMLWorksheet -WorkSheetName $WorksheetName -AutofilterRange $AutofilterRange 1966 | $sheet = $book | Select-OOXMLWorkSheet -WorkSheetName $WorksheetName 1967 | } 1968 | else 1969 | { 1970 | [OfficeOpenXml.ExcelPackage]$excel = New-OOXMLPackage -author "ExcelPSLib" -title $DocumentName 1971 | [OfficeOpenXml.ExcelWorkbook]$book = $excel | Get-OOXMLWorkbook 1972 | 1973 | $AutofilterRange = Convert-OOXMLCellsCoordinates -StartRow $RowPosition -EndRow $RowPosition -StartCol 1 -EndCol $ColumnNumber 1974 | 1975 | $excel | Add-OOXMLWorksheet -WorkSheetName $WorksheetName -AutofilterRange $AutofilterRange 1976 | $sheet = $book | Select-OOXMLWorkSheet -WorkSheetName $WorksheetName 1977 | } 1978 | 1979 | 1980 | 1981 | $StyleHeaderCollection = @{ 1982 | "AliceBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "AliceBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor AliceBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1983 | "AntiqueWhite" = New-OOXMLStyleSheet -WorkBook $book -Name "AntiqueWhiteStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor AntiqueWhite -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1984 | "Aqua" = New-OOXMLStyleSheet -WorkBook $book -Name "AquaStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Aqua -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1985 | "Aquamarine" = New-OOXMLStyleSheet -WorkBook $book -Name "AquamarineStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Aquamarine -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1986 | "Azure" = New-OOXMLStyleSheet -WorkBook $book -Name "AzureStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Azure -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1987 | "Beige" = New-OOXMLStyleSheet -WorkBook $book -Name "BeigeStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Beige -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1988 | "Bisque" = New-OOXMLStyleSheet -WorkBook $book -Name "BisqueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Bisque -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1989 | "Black" = New-OOXMLStyleSheet -WorkBook $book -Name "BlackStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Black -FillType Solid -ForeGroundColor White -TextRotation $HeaderTextRotation 1990 | "BlanchedAlmond" = New-OOXMLStyleSheet -WorkBook $book -Name "BlanchedAlmondStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor BlanchedAlmond -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1991 | "Blue" = New-OOXMLStyleSheet -WorkBook $book -Name "BlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Blue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1992 | "BlueViolet" = New-OOXMLStyleSheet -WorkBook $book -Name "BlueVioletStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor BlueViolet -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1993 | "Brown" = New-OOXMLStyleSheet -WorkBook $book -Name "BrownStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Brown -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1994 | "BurlyWood" = New-OOXMLStyleSheet -WorkBook $book -Name "BurlyWoodStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor BurlyWood -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1995 | "CadetBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "CadetBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor CadetBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1996 | "Chartreuse" = New-OOXMLStyleSheet -WorkBook $book -Name "ChartreuseStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Chartreuse -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1997 | "Chocolate" = New-OOXMLStyleSheet -WorkBook $book -Name "ChocolateStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Chocolate -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1998 | "Coral" = New-OOXMLStyleSheet -WorkBook $book -Name "CoralStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Coral -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 1999 | "CornflowerBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "CornflowerBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor CornflowerBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2000 | "Cornsilk" = New-OOXMLStyleSheet -WorkBook $book -Name "CornsilkStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Cornsilk -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2001 | "Crimson" = New-OOXMLStyleSheet -WorkBook $book -Name "CrimsonStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Crimson -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2002 | "Cyan" = New-OOXMLStyleSheet -WorkBook $book -Name "CyanStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Cyan -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2003 | "DarkBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2004 | "DarkCyan" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkCyanStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkCyan -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2005 | "DarkGoldenrod" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkGoldenrodStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkGoldenrod -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2006 | "DarkGray" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkGrayStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkGray -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2007 | "DarkGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkGreen -FillType Solid -ForeGroundColor White -TextRotation $HeaderTextRotation 2008 | "DarkKhaki" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkKhakiStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkKhaki -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2009 | "DarkMagenta" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkMagentaStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkMagenta -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2010 | "DarkOliveGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkOliveGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkOliveGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2011 | "DarkOrange" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkOrangeStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkOrange -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2012 | "DarkOrchid" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkOrchidStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkOrchid -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2013 | "DarkRed" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkRedStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkRed -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2014 | "DarkSalmon" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkSalmonStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkSalmon -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2015 | "DarkSeaGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkSeaGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkSeaGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2016 | "DarkSlateBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkSlateBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkSlateBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2017 | "DarkSlateGray" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkSlateGrayStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkSlateGray -FillType Solid -ForeGroundColor White -TextRotation $HeaderTextRotation 2018 | "DarkTurquoise" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkTurquoiseStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkTurquoise -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2019 | "DarkViolet" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkVioletStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DarkViolet -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2020 | "DeepPink" = New-OOXMLStyleSheet -WorkBook $book -Name "DeepPinkStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DeepPink -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2021 | "DeepSkyBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "DeepSkyBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DeepSkyBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2022 | "DimGray" = New-OOXMLStyleSheet -WorkBook $book -Name "DimGrayStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DimGray -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2023 | "DodgerBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "DodgerBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor DodgerBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2024 | "Firebrick" = New-OOXMLStyleSheet -WorkBook $book -Name "FirebrickStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Firebrick -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2025 | "FloralWhite" = New-OOXMLStyleSheet -WorkBook $book -Name "FloralWhiteStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor FloralWhite -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2026 | "ForestGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "ForestGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor ForestGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2027 | "Fuchsia" = New-OOXMLStyleSheet -WorkBook $book -Name "FuchsiaStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Fuchsia -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2028 | "Gainsboro" = New-OOXMLStyleSheet -WorkBook $book -Name "GainsboroStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Gainsboro -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2029 | "GhostWhite" = New-OOXMLStyleSheet -WorkBook $book -Name "GhostWhiteStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor GhostWhite -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2030 | "Gold" = New-OOXMLStyleSheet -WorkBook $book -Name "GoldStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Gold -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2031 | "Goldenrod" = New-OOXMLStyleSheet -WorkBook $book -Name "GoldenrodStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Goldenrod -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2032 | "Gray" = New-OOXMLStyleSheet -WorkBook $book -Name "GrayStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Gray -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2033 | "Green" = New-OOXMLStyleSheet -WorkBook $book -Name "GreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Green -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2034 | "GreenYellow" = New-OOXMLStyleSheet -WorkBook $book -Name "GreenYellowStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor GreenYellow -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2035 | "Honeydew" = New-OOXMLStyleSheet -WorkBook $book -Name "HoneydewStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Honeydew -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2036 | "HotPink" = New-OOXMLStyleSheet -WorkBook $book -Name "HotPinkStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor HotPink -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2037 | "IndianRed" = New-OOXMLStyleSheet -WorkBook $book -Name "IndianRedStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor IndianRed -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2038 | "Indigo" = New-OOXMLStyleSheet -WorkBook $book -Name "IndigoStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Indigo -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2039 | "Ivory" = New-OOXMLStyleSheet -WorkBook $book -Name "IvoryStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Ivory -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2040 | "Khaki" = New-OOXMLStyleSheet -WorkBook $book -Name "KhakiStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Khaki -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2041 | "Lavender" = New-OOXMLStyleSheet -WorkBook $book -Name "LavenderStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Lavender -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2042 | "LavenderBlush" = New-OOXMLStyleSheet -WorkBook $book -Name "LavenderBlushStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LavenderBlush -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2043 | "LawnGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "LawnGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LawnGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2044 | "LemonChiffon" = New-OOXMLStyleSheet -WorkBook $book -Name "LemonChiffonStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LemonChiffon -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2045 | "LightBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "LightBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2046 | "LightCoral" = New-OOXMLStyleSheet -WorkBook $book -Name "LightCoralStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightCoral -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2047 | "LightCyan" = New-OOXMLStyleSheet -WorkBook $book -Name "LightCyanStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightCyan -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2048 | "LightGoldenrodYellow" = New-OOXMLStyleSheet -WorkBook $book -Name "LightGoldenrodYellowStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightGoldenrodYellow -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2049 | "LightGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "LightGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2050 | "LightGray" = New-OOXMLStyleSheet -WorkBook $book -Name "LightGrayStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightGray -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2051 | "LightPink" = New-OOXMLStyleSheet -WorkBook $book -Name "LightPinkStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightPink -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2052 | "LightSalmon" = New-OOXMLStyleSheet -WorkBook $book -Name "LightSalmonStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightSalmon -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2053 | "LightSeaGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "LightSeaGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightSeaGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2054 | "LightSkyBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "LightSkyBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightSkyBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2055 | "LightSlateGray" = New-OOXMLStyleSheet -WorkBook $book -Name "LightSlateGrayStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightSlateGray -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2056 | "LightSteelBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "LightSteelBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightSteelBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2057 | "LightYellow" = New-OOXMLStyleSheet -WorkBook $book -Name "LightYellowStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LightYellow -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2058 | "Lime" = New-OOXMLStyleSheet -WorkBook $book -Name "LimeStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Lime -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2059 | "LimeGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "LimeGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor LimeGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2060 | "Linen" = New-OOXMLStyleSheet -WorkBook $book -Name "LinenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Linen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2061 | "Magenta" = New-OOXMLStyleSheet -WorkBook $book -Name "MagentaStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Magenta -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2062 | "Maroon" = New-OOXMLStyleSheet -WorkBook $book -Name "MaroonStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Maroon -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2063 | "MediumAquamarine" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumAquamarineStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MediumAquamarine -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2064 | "MediumBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MediumBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2065 | "MediumOrchid" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumOrchidStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MediumOrchid -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2066 | "MediumPurple" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumPurpleStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MediumPurple -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2067 | "MediumSeaGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumSeaGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MediumSeaGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2068 | "MediumSlateBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumSlateBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MediumSlateBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2069 | "MediumSpringGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumSpringGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MediumSpringGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2070 | "MediumTurquoise" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumTurquoiseStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MediumTurquoise -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2071 | "MediumVioletRed" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumVioletRedStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MediumVioletRed -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2072 | "MidnightBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "MidnightBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MidnightBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2073 | "MintCream" = New-OOXMLStyleSheet -WorkBook $book -Name "MintCreamStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MintCream -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2074 | "MistyRose" = New-OOXMLStyleSheet -WorkBook $book -Name "MistyRoseStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor MistyRose -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2075 | "Moccasin" = New-OOXMLStyleSheet -WorkBook $book -Name "MoccasinStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Moccasin -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2076 | "NavajoWhite" = New-OOXMLStyleSheet -WorkBook $book -Name "NavajoWhiteStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor NavajoWhite -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2077 | "Navy" = New-OOXMLStyleSheet -WorkBook $book -Name "NavyStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Navy -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2078 | "OldLace" = New-OOXMLStyleSheet -WorkBook $book -Name "OldLaceStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor OldLace -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2079 | "Olive" = New-OOXMLStyleSheet -WorkBook $book -Name "OliveStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Olive -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2080 | "OliveDrab" = New-OOXMLStyleSheet -WorkBook $book -Name "OliveDrabStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor OliveDrab -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2081 | "Orange" = New-OOXMLStyleSheet -WorkBook $book -Name "OrangeStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Orange -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2082 | "OrangeRed" = New-OOXMLStyleSheet -WorkBook $book -Name "OrangeRedStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor OrangeRed -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2083 | "Orchid" = New-OOXMLStyleSheet -WorkBook $book -Name "OrchidStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Orchid -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2084 | "PaleGoldenrod" = New-OOXMLStyleSheet -WorkBook $book -Name "PaleGoldenrodStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor PaleGoldenrod -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2085 | "PaleGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "PaleGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor PaleGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2086 | "PaleTurquoise" = New-OOXMLStyleSheet -WorkBook $book -Name "PaleTurquoiseStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor PaleTurquoise -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2087 | "PaleVioletRed" = New-OOXMLStyleSheet -WorkBook $book -Name "PaleVioletRedStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor PaleVioletRed -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2088 | "PapayaWhip" = New-OOXMLStyleSheet -WorkBook $book -Name "PapayaWhipStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor PapayaWhip -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2089 | "PeachPuff" = New-OOXMLStyleSheet -WorkBook $book -Name "PeachPuffStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor PeachPuff -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2090 | "Peru" = New-OOXMLStyleSheet -WorkBook $book -Name "PeruStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Peru -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2091 | "Pink" = New-OOXMLStyleSheet -WorkBook $book -Name "PinkStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Pink -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2092 | "Plum" = New-OOXMLStyleSheet -WorkBook $book -Name "PlumStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Plum -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2093 | "PowderBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "PowderBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor PowderBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2094 | "Purple" = New-OOXMLStyleSheet -WorkBook $book -Name "PurpleStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Purple -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2095 | "Red" = New-OOXMLStyleSheet -WorkBook $book -Name "RedStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Red -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2096 | "RosyBrown" = New-OOXMLStyleSheet -WorkBook $book -Name "RosyBrownStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor RosyBrown -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2097 | "RoyalBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "RoyalBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor RoyalBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2098 | "SaddleBrown" = New-OOXMLStyleSheet -WorkBook $book -Name "SaddleBrownStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor SaddleBrown -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2099 | "Salmon" = New-OOXMLStyleSheet -WorkBook $book -Name "SalmonStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Salmon -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2100 | "SandyBrown" = New-OOXMLStyleSheet -WorkBook $book -Name "SandyBrownStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor SandyBrown -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2101 | "SeaGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "SeaGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor SeaGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2102 | "SeaShell" = New-OOXMLStyleSheet -WorkBook $book -Name "SeaShellStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor SeaShell -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2103 | "Sienna" = New-OOXMLStyleSheet -WorkBook $book -Name "SiennaStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Sienna -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2104 | "Silver" = New-OOXMLStyleSheet -WorkBook $book -Name "SilverStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Silver -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2105 | "SkyBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "SkyBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor SkyBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2106 | "SlateBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "SlateBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor SlateBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2107 | "SlateGray" = New-OOXMLStyleSheet -WorkBook $book -Name "SlateGrayStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor SlateGray -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2108 | "Snow" = New-OOXMLStyleSheet -WorkBook $book -Name "SnowStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Snow -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2109 | "SpringGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "SpringGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor SpringGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2110 | "SteelBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "SteelBlueStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor SteelBlue -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2111 | "Tan" = New-OOXMLStyleSheet -WorkBook $book -Name "TanStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Tan -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2112 | "Teal" = New-OOXMLStyleSheet -WorkBook $book -Name "TealStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Teal -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2113 | "Thistle" = New-OOXMLStyleSheet -WorkBook $book -Name "ThistleStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Thistle -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2114 | "Tomato" = New-OOXMLStyleSheet -WorkBook $book -Name "TomatoStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Tomato -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2115 | "Turquoise" = New-OOXMLStyleSheet -WorkBook $book -Name "TurquoiseStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Turquoise -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2116 | "Violet" = New-OOXMLStyleSheet -WorkBook $book -Name "VioletStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Violet -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2117 | "Wheat" = New-OOXMLStyleSheet -WorkBook $book -Name "WheatStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Wheat -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2118 | "White" = New-OOXMLStyleSheet -WorkBook $book -Name "WhiteStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor White -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2119 | "WhiteSmoke" = New-OOXMLStyleSheet -WorkBook $book -Name "WhiteSmokeStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor WhiteSmoke -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2120 | "Yellow" = New-OOXMLStyleSheet -WorkBook $book -Name "YellowStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor Yellow -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2121 | "YellowGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "YellowGreenStyleHeader" -Size 14 -Bold -HAlign Center -VAlign Center -BackGroundColor YellowGreen -FillType Solid -ForeGroundColor Black -TextRotation $HeaderTextRotation 2122 | } 2123 | 2124 | $StyleNormal = New-OOXMLStyleSheet -WorkBook $book -Name "NormalStyle" -borderStyle Thin -BorderColor Black -HAlign Right 2125 | $StyleURI = New-OOXMLStyleSheet -WorkBook $book -Name "URIStyle" -borderStyle Thin -BorderColor Black -HAlign Left -ForeGroundColor Blue -Underline 2126 | 2127 | $StyleDate = New-OOXMLStyleSheet -WorkBook $book -Name "DateStyle" -borderStyle Thin -BorderColor Black -HAlign Right -NFormat "$([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortDatePattern) $([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortTimePattern)" 2128 | $StyleNumber = New-OOXMLStyleSheet -WorkBook $book -Name "NumberStyle" -borderStyle Thin -BorderColor Black -HAlign Right -NFormat "0" 2129 | $StyleFloat = New-OOXMLStyleSheet -WorkBook $book -Name "FloatStyle" -borderStyle Thin -BorderColor Black -HAlign Right -NFormat "0.00" 2130 | 2131 | $StyleCollection = @{ 2132 | "AliceBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "AliceBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor AliceBlue -FillType Solid -ForeGroundColor Black 2133 | "AntiqueWhite" = New-OOXMLStyleSheet -WorkBook $book -Name "AntiqueWhiteStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor AntiqueWhite -FillType Solid -ForeGroundColor Black 2134 | "Aqua" = New-OOXMLStyleSheet -WorkBook $book -Name "AquaStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Aqua -FillType Solid -ForeGroundColor Black 2135 | "Aquamarine" = New-OOXMLStyleSheet -WorkBook $book -Name "AquamarineStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Aquamarine -FillType Solid -ForeGroundColor Black 2136 | "Azure" = New-OOXMLStyleSheet -WorkBook $book -Name "AzureStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Azure -FillType Solid -ForeGroundColor Black 2137 | "Beige" = New-OOXMLStyleSheet -WorkBook $book -Name "BeigeStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Beige -FillType Solid -ForeGroundColor Black 2138 | "Bisque" = New-OOXMLStyleSheet -WorkBook $book -Name "BisqueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Bisque -FillType Solid -ForeGroundColor Black 2139 | "Black" = New-OOXMLStyleSheet -WorkBook $book -Name "BlackStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Black -FillType Solid -ForeGroundColor White 2140 | "BlanchedAlmond" = New-OOXMLStyleSheet -WorkBook $book -Name "BlanchedAlmondStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor BlanchedAlmond -FillType Solid -ForeGroundColor Black 2141 | "Blue" = New-OOXMLStyleSheet -WorkBook $book -Name "BlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Blue -FillType Solid -ForeGroundColor Black 2142 | "BlueViolet" = New-OOXMLStyleSheet -WorkBook $book -Name "BlueVioletStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor BlueViolet -FillType Solid -ForeGroundColor Black 2143 | "Brown" = New-OOXMLStyleSheet -WorkBook $book -Name "BrownStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Brown -FillType Solid -ForeGroundColor Black 2144 | "BurlyWood" = New-OOXMLStyleSheet -WorkBook $book -Name "BurlyWoodStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor BurlyWood -FillType Solid -ForeGroundColor Black 2145 | "CadetBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "CadetBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor CadetBlue -FillType Solid -ForeGroundColor Black 2146 | "Chartreuse" = New-OOXMLStyleSheet -WorkBook $book -Name "ChartreuseStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Chartreuse -FillType Solid -ForeGroundColor Black 2147 | "Chocolate" = New-OOXMLStyleSheet -WorkBook $book -Name "ChocolateStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Chocolate -FillType Solid -ForeGroundColor Black 2148 | "Coral" = New-OOXMLStyleSheet -WorkBook $book -Name "CoralStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Coral -FillType Solid -ForeGroundColor Black 2149 | "CornflowerBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "CornflowerBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor CornflowerBlue -FillType Solid -ForeGroundColor Black 2150 | "Cornsilk" = New-OOXMLStyleSheet -WorkBook $book -Name "CornsilkStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Cornsilk -FillType Solid -ForeGroundColor Black 2151 | "Crimson" = New-OOXMLStyleSheet -WorkBook $book -Name "CrimsonStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Crimson -FillType Solid -ForeGroundColor Black 2152 | "Cyan" = New-OOXMLStyleSheet -WorkBook $book -Name "CyanStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Cyan -FillType Solid -ForeGroundColor Black 2153 | "DarkBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkBlue -FillType Solid -ForeGroundColor Black 2154 | "DarkCyan" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkCyanStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkCyan -FillType Solid -ForeGroundColor Black 2155 | "DarkGoldenrod" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkGoldenrodStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkGoldenrod -FillType Solid -ForeGroundColor Black 2156 | "DarkGray" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkGrayStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkGray -FillType Solid -ForeGroundColor Black 2157 | "DarkGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkGreen -FillType Solid -ForeGroundColor White 2158 | "DarkKhaki" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkKhakiStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkKhaki -FillType Solid -ForeGroundColor Black 2159 | "DarkMagenta" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkMagentaStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkMagenta -FillType Solid -ForeGroundColor Black 2160 | "DarkOliveGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkOliveGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkOliveGreen -FillType Solid -ForeGroundColor Black 2161 | "DarkOrange" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkOrangeStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkOrange -FillType Solid -ForeGroundColor Black 2162 | "DarkOrchid" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkOrchidStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkOrchid -FillType Solid -ForeGroundColor Black 2163 | "DarkRed" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkRedStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkRed -FillType Solid -ForeGroundColor Black 2164 | "DarkSalmon" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkSalmonStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkSalmon -FillType Solid -ForeGroundColor Black 2165 | "DarkSeaGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkSeaGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkSeaGreen -FillType Solid -ForeGroundColor Black 2166 | "DarkSlateBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkSlateBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkSlateBlue -FillType Solid -ForeGroundColor Black 2167 | "DarkSlateGray" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkSlateGrayStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkSlateGray -FillType Solid -ForeGroundColor White 2168 | "DarkTurquoise" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkTurquoiseStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkTurquoise -FillType Solid -ForeGroundColor Black 2169 | "DarkViolet" = New-OOXMLStyleSheet -WorkBook $book -Name "DarkVioletStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DarkViolet -FillType Solid -ForeGroundColor Black 2170 | "DeepPink" = New-OOXMLStyleSheet -WorkBook $book -Name "DeepPinkStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DeepPink -FillType Solid -ForeGroundColor Black 2171 | "DeepSkyBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "DeepSkyBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DeepSkyBlue -FillType Solid -ForeGroundColor Black 2172 | "DimGray" = New-OOXMLStyleSheet -WorkBook $book -Name "DimGrayStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DimGray -FillType Solid -ForeGroundColor Black 2173 | "DodgerBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "DodgerBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor DodgerBlue -FillType Solid -ForeGroundColor Black 2174 | "Firebrick" = New-OOXMLStyleSheet -WorkBook $book -Name "FirebrickStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Firebrick -FillType Solid -ForeGroundColor Black 2175 | "FloralWhite" = New-OOXMLStyleSheet -WorkBook $book -Name "FloralWhiteStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor FloralWhite -FillType Solid -ForeGroundColor Black 2176 | "ForestGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "ForestGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor ForestGreen -FillType Solid -ForeGroundColor Black 2177 | "Fuchsia" = New-OOXMLStyleSheet -WorkBook $book -Name "FuchsiaStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Fuchsia -FillType Solid -ForeGroundColor Black 2178 | "Gainsboro" = New-OOXMLStyleSheet -WorkBook $book -Name "GainsboroStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Gainsboro -FillType Solid -ForeGroundColor Black 2179 | "GhostWhite" = New-OOXMLStyleSheet -WorkBook $book -Name "GhostWhiteStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor GhostWhite -FillType Solid -ForeGroundColor Black 2180 | "Gold" = New-OOXMLStyleSheet -WorkBook $book -Name "GoldStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Gold -FillType Solid -ForeGroundColor Black 2181 | "Goldenrod" = New-OOXMLStyleSheet -WorkBook $book -Name "GoldenrodStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Goldenrod -FillType Solid -ForeGroundColor Black 2182 | "Gray" = New-OOXMLStyleSheet -WorkBook $book -Name "GrayStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Gray -FillType Solid -ForeGroundColor Black 2183 | "Green" = New-OOXMLStyleSheet -WorkBook $book -Name "GreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Green -FillType Solid -ForeGroundColor Black 2184 | "GreenYellow" = New-OOXMLStyleSheet -WorkBook $book -Name "GreenYellowStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor GreenYellow -FillType Solid -ForeGroundColor Black 2185 | "Honeydew" = New-OOXMLStyleSheet -WorkBook $book -Name "HoneydewStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Honeydew -FillType Solid -ForeGroundColor Black 2186 | "HotPink" = New-OOXMLStyleSheet -WorkBook $book -Name "HotPinkStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor HotPink -FillType Solid -ForeGroundColor Black 2187 | "IndianRed" = New-OOXMLStyleSheet -WorkBook $book -Name "IndianRedStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor IndianRed -FillType Solid -ForeGroundColor Black 2188 | "Indigo" = New-OOXMLStyleSheet -WorkBook $book -Name "IndigoStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Indigo -FillType Solid -ForeGroundColor Black 2189 | "Ivory" = New-OOXMLStyleSheet -WorkBook $book -Name "IvoryStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Ivory -FillType Solid -ForeGroundColor Black 2190 | "Khaki" = New-OOXMLStyleSheet -WorkBook $book -Name "KhakiStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Khaki -FillType Solid -ForeGroundColor Black 2191 | "Lavender" = New-OOXMLStyleSheet -WorkBook $book -Name "LavenderStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Lavender -FillType Solid -ForeGroundColor Black 2192 | "LavenderBlush" = New-OOXMLStyleSheet -WorkBook $book -Name "LavenderBlushStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LavenderBlush -FillType Solid -ForeGroundColor Black 2193 | "LawnGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "LawnGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LawnGreen -FillType Solid -ForeGroundColor Black 2194 | "LemonChiffon" = New-OOXMLStyleSheet -WorkBook $book -Name "LemonChiffonStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LemonChiffon -FillType Solid -ForeGroundColor Black 2195 | "LightBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "LightBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightBlue -FillType Solid -ForeGroundColor Black 2196 | "LightCoral" = New-OOXMLStyleSheet -WorkBook $book -Name "LightCoralStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightCoral -FillType Solid -ForeGroundColor Black 2197 | "LightCyan" = New-OOXMLStyleSheet -WorkBook $book -Name "LightCyanStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightCyan -FillType Solid -ForeGroundColor Black 2198 | "LightGoldenrodYellow" = New-OOXMLStyleSheet -WorkBook $book -Name "LightGoldenrodYellowStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightGoldenrodYellow -FillType Solid -ForeGroundColor Black 2199 | "LightGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "LightGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightGreen -FillType Solid -ForeGroundColor Black 2200 | "LightGray" = New-OOXMLStyleSheet -WorkBook $book -Name "LightGrayStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightGray -FillType Solid -ForeGroundColor Black 2201 | "LightPink" = New-OOXMLStyleSheet -WorkBook $book -Name "LightPinkStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightPink -FillType Solid -ForeGroundColor Black 2202 | "LightSalmon" = New-OOXMLStyleSheet -WorkBook $book -Name "LightSalmonStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightSalmon -FillType Solid -ForeGroundColor Black 2203 | "LightSeaGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "LightSeaGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightSeaGreen -FillType Solid -ForeGroundColor Black 2204 | "LightSkyBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "LightSkyBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightSkyBlue -FillType Solid -ForeGroundColor Black 2205 | "LightSlateGray" = New-OOXMLStyleSheet -WorkBook $book -Name "LightSlateGrayStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightSlateGray -FillType Solid -ForeGroundColor Black 2206 | "LightSteelBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "LightSteelBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightSteelBlue -FillType Solid -ForeGroundColor Black 2207 | "LightYellow" = New-OOXMLStyleSheet -WorkBook $book -Name "LightYellowStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LightYellow -FillType Solid -ForeGroundColor Black 2208 | "Lime" = New-OOXMLStyleSheet -WorkBook $book -Name "LimeStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Lime -FillType Solid -ForeGroundColor Black 2209 | "LimeGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "LimeGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor LimeGreen -FillType Solid -ForeGroundColor Black 2210 | "Linen" = New-OOXMLStyleSheet -WorkBook $book -Name "LinenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Linen -FillType Solid -ForeGroundColor Black 2211 | "Magenta" = New-OOXMLStyleSheet -WorkBook $book -Name "MagentaStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Magenta -FillType Solid -ForeGroundColor Black 2212 | "Maroon" = New-OOXMLStyleSheet -WorkBook $book -Name "MaroonStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Maroon -FillType Solid -ForeGroundColor Black 2213 | "MediumAquamarine" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumAquamarineStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MediumAquamarine -FillType Solid -ForeGroundColor Black 2214 | "MediumBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MediumBlue -FillType Solid -ForeGroundColor Black 2215 | "MediumOrchid" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumOrchidStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MediumOrchid -FillType Solid -ForeGroundColor Black 2216 | "MediumPurple" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumPurpleStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MediumPurple -FillType Solid -ForeGroundColor Black 2217 | "MediumSeaGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumSeaGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MediumSeaGreen -FillType Solid -ForeGroundColor Black 2218 | "MediumSlateBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumSlateBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MediumSlateBlue -FillType Solid -ForeGroundColor Black 2219 | "MediumSpringGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumSpringGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MediumSpringGreen -FillType Solid -ForeGroundColor Black 2220 | "MediumTurquoise" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumTurquoiseStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MediumTurquoise -FillType Solid -ForeGroundColor Black 2221 | "MediumVioletRed" = New-OOXMLStyleSheet -WorkBook $book -Name "MediumVioletRedStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MediumVioletRed -FillType Solid -ForeGroundColor Black 2222 | "MidnightBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "MidnightBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MidnightBlue -FillType Solid -ForeGroundColor Black 2223 | "MintCream" = New-OOXMLStyleSheet -WorkBook $book -Name "MintCreamStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MintCream -FillType Solid -ForeGroundColor Black 2224 | "MistyRose" = New-OOXMLStyleSheet -WorkBook $book -Name "MistyRoseStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor MistyRose -FillType Solid -ForeGroundColor Black 2225 | "Moccasin" = New-OOXMLStyleSheet -WorkBook $book -Name "MoccasinStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Moccasin -FillType Solid -ForeGroundColor Black 2226 | "NavajoWhite" = New-OOXMLStyleSheet -WorkBook $book -Name "NavajoWhiteStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor NavajoWhite -FillType Solid -ForeGroundColor Black 2227 | "Navy" = New-OOXMLStyleSheet -WorkBook $book -Name "NavyStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Navy -FillType Solid -ForeGroundColor Black 2228 | "OldLace" = New-OOXMLStyleSheet -WorkBook $book -Name "OldLaceStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor OldLace -FillType Solid -ForeGroundColor Black 2229 | "Olive" = New-OOXMLStyleSheet -WorkBook $book -Name "OliveStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Olive -FillType Solid -ForeGroundColor Black 2230 | "OliveDrab" = New-OOXMLStyleSheet -WorkBook $book -Name "OliveDrabStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor OliveDrab -FillType Solid -ForeGroundColor Black 2231 | "Orange" = New-OOXMLStyleSheet -WorkBook $book -Name "OrangeStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Orange -FillType Solid -ForeGroundColor Black 2232 | "OrangeRed" = New-OOXMLStyleSheet -WorkBook $book -Name "OrangeRedStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor OrangeRed -FillType Solid -ForeGroundColor Black 2233 | "Orchid" = New-OOXMLStyleSheet -WorkBook $book -Name "OrchidStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Orchid -FillType Solid -ForeGroundColor Black 2234 | "PaleGoldenrod" = New-OOXMLStyleSheet -WorkBook $book -Name "PaleGoldenrodStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor PaleGoldenrod -FillType Solid -ForeGroundColor Black 2235 | "PaleGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "PaleGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor PaleGreen -FillType Solid -ForeGroundColor Black 2236 | "PaleTurquoise" = New-OOXMLStyleSheet -WorkBook $book -Name "PaleTurquoiseStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor PaleTurquoise -FillType Solid -ForeGroundColor Black 2237 | "PaleVioletRed" = New-OOXMLStyleSheet -WorkBook $book -Name "PaleVioletRedStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor PaleVioletRed -FillType Solid -ForeGroundColor Black 2238 | "PapayaWhip" = New-OOXMLStyleSheet -WorkBook $book -Name "PapayaWhipStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor PapayaWhip -FillType Solid -ForeGroundColor Black 2239 | "PeachPuff" = New-OOXMLStyleSheet -WorkBook $book -Name "PeachPuffStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor PeachPuff -FillType Solid -ForeGroundColor Black 2240 | "Peru" = New-OOXMLStyleSheet -WorkBook $book -Name "PeruStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Peru -FillType Solid -ForeGroundColor Black 2241 | "Pink" = New-OOXMLStyleSheet -WorkBook $book -Name "PinkStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Pink -FillType Solid -ForeGroundColor Black 2242 | "Plum" = New-OOXMLStyleSheet -WorkBook $book -Name "PlumStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Plum -FillType Solid -ForeGroundColor Black 2243 | "PowderBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "PowderBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor PowderBlue -FillType Solid -ForeGroundColor Black 2244 | "Purple" = New-OOXMLStyleSheet -WorkBook $book -Name "PurpleStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Purple -FillType Solid -ForeGroundColor Black 2245 | "Red" = New-OOXMLStyleSheet -WorkBook $book -Name "RedStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Red -FillType Solid -ForeGroundColor Black 2246 | "RosyBrown" = New-OOXMLStyleSheet -WorkBook $book -Name "RosyBrownStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor RosyBrown -FillType Solid -ForeGroundColor Black 2247 | "RoyalBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "RoyalBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor RoyalBlue -FillType Solid -ForeGroundColor Black 2248 | "SaddleBrown" = New-OOXMLStyleSheet -WorkBook $book -Name "SaddleBrownStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor SaddleBrown -FillType Solid -ForeGroundColor Black 2249 | "Salmon" = New-OOXMLStyleSheet -WorkBook $book -Name "SalmonStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Salmon -FillType Solid -ForeGroundColor Black 2250 | "SandyBrown" = New-OOXMLStyleSheet -WorkBook $book -Name "SandyBrownStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor SandyBrown -FillType Solid -ForeGroundColor Black 2251 | "SeaGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "SeaGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor SeaGreen -FillType Solid -ForeGroundColor Black 2252 | "SeaShell" = New-OOXMLStyleSheet -WorkBook $book -Name "SeaShellStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor SeaShell -FillType Solid -ForeGroundColor Black 2253 | "Sienna" = New-OOXMLStyleSheet -WorkBook $book -Name "SiennaStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Sienna -FillType Solid -ForeGroundColor Black 2254 | "Silver" = New-OOXMLStyleSheet -WorkBook $book -Name "SilverStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Silver -FillType Solid -ForeGroundColor Black 2255 | "SkyBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "SkyBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor SkyBlue -FillType Solid -ForeGroundColor Black 2256 | "SlateBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "SlateBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor SlateBlue -FillType Solid -ForeGroundColor Black 2257 | "SlateGray" = New-OOXMLStyleSheet -WorkBook $book -Name "SlateGrayStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor SlateGray -FillType Solid -ForeGroundColor Black 2258 | "Snow" = New-OOXMLStyleSheet -WorkBook $book -Name "SnowStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Snow -FillType Solid -ForeGroundColor Black 2259 | "SpringGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "SpringGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor SpringGreen -FillType Solid -ForeGroundColor Black 2260 | "SteelBlue" = New-OOXMLStyleSheet -WorkBook $book -Name "SteelBlueStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor SteelBlue -FillType Solid -ForeGroundColor Black 2261 | "Tan" = New-OOXMLStyleSheet -WorkBook $book -Name "TanStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Tan -FillType Solid -ForeGroundColor Black 2262 | "Teal" = New-OOXMLStyleSheet -WorkBook $book -Name "TealStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Teal -FillType Solid -ForeGroundColor Black 2263 | "Thistle" = New-OOXMLStyleSheet -WorkBook $book -Name "ThistleStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Thistle -FillType Solid -ForeGroundColor Black 2264 | "Tomato" = New-OOXMLStyleSheet -WorkBook $book -Name "TomatoStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Tomato -FillType Solid -ForeGroundColor Black 2265 | "Turquoise" = New-OOXMLStyleSheet -WorkBook $book -Name "TurquoiseStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Turquoise -FillType Solid -ForeGroundColor Black 2266 | "Violet" = New-OOXMLStyleSheet -WorkBook $book -Name "VioletStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Violet -FillType Solid -ForeGroundColor Black 2267 | "Wheat" = New-OOXMLStyleSheet -WorkBook $book -Name "WheatStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Wheat -FillType Solid -ForeGroundColor Black 2268 | "White" = New-OOXMLStyleSheet -WorkBook $book -Name "WhiteStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor White -FillType Solid -ForeGroundColor Black 2269 | "WhiteSmoke" = New-OOXMLStyleSheet -WorkBook $book -Name "WhiteSmokeStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor WhiteSmoke -FillType Solid -ForeGroundColor Black 2270 | "Yellow" = New-OOXMLStyleSheet -WorkBook $book -Name "YellowStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor Yellow -FillType Solid -ForeGroundColor Black 2271 | "YellowGreen" = New-OOXMLStyleSheet -WorkBook $book -Name "YellowGreenStyle" -borderStyle Thin -BorderColor Black -HAlign Right -BackGroundColor YellowGreen -FillType Solid -ForeGroundColor Black 2272 | } 2273 | 2274 | $i=1 2275 | $AssociatedConditionalFormattings = @() 2276 | $AssociatedFormulaInformations = @() 2277 | 2278 | $DefaultHeaderStyle = $StyleHeaderCollection[$HeaderStyle.ToString()] 2279 | 2280 | foreach($Property in $ReferencePropertySet) 2281 | { 2282 | $StyleHeader = $DefaultHeaderStyle 2283 | foreach($HeaderCustomStyle in $HeaderCustomStyles) 2284 | { 2285 | if($($HeaderCustomStyle.Name) -eq $Property){ 2286 | 2287 | $StyleHeader = New-OOXMLStyleSheet -WorkBook $book ` 2288 | -Name $HeaderCustomStyle.Data.Name ` 2289 | -HAlign $HeaderCustomStyle.Data.HAlign ` 2290 | -VAlign $HeaderCustomStyle.Data.VAlign ` 2291 | -NFormat $HeaderCustomStyle.Data.NFormat ` 2292 | -Wrap:$($HeaderCustomStyle.Data.Wrap) ` 2293 | -Shrink:$($HeaderCustomStyle.Data.Shrink) ` 2294 | -Locked:$($HeaderCustomStyle.Data.Locked) ` 2295 | -Bold:$($HeaderCustomStyle.Data.Bold) ` 2296 | -Italic:$($HeaderCustomStyle.Data.Italic) ` 2297 | -Underline:$($HeaderCustomStyle.Data.Underline) ` 2298 | -Strike:$($HeaderCustomStyle.Data.Strike) ` 2299 | -Size $HeaderCustomStyle.Data.Size ` 2300 | -TextRotation $HeaderCustomStyle.Data.TextRotation ` 2301 | -ForeGroundColor $HeaderCustomStyle.Data.ForeGroundColor ` 2302 | -FillType $HeaderCustomStyle.Data.FillType ` 2303 | -BackGroundColor $HeaderCustomStyle.Data.BackGroundColor ` 2304 | -borderStyle $HeaderCustomStyle.Data.borderStyle ` 2305 | -BorderColor $HeaderCustomStyle.Data.BorderColor 2306 | } 2307 | } 2308 | 2309 | $sheet | Set-OOXMLRangeValue -row $RowPosition -col $i -value $Property -StyleSheet $StyleHeader | Out-Null 2310 | $sheet.Column($i).Width = 32 2311 | 2312 | foreach($FormulaObject in $FormulaObjects) 2313 | { 2314 | if($Property -eq $FormulaObject.Name) 2315 | { 2316 | $AssociatedFormulaInformations += [PSCustomObject]@{ 2317 | FormulaObject = $FormulaObject 2318 | ColumnName = $Property 2319 | ColumnIndex = $i 2320 | } 2321 | } 2322 | } 2323 | 2324 | foreach($ConditionalFormating in $ConditionalFormatings) 2325 | { 2326 | if($Property -eq $ConditionalFormating.Name) 2327 | { 2328 | $AssociatedConditionalFormattings += [PSCustomObject]@{ 2329 | FormattingObject = $ConditionalFormating 2330 | ColumnName = $Property 2331 | ColumnIndex = $i 2332 | } 2333 | } 2334 | } 2335 | $i++ 2336 | } 2337 | 2338 | $RowPosition++ 2339 | 2340 | foreach($Object in $InputObject){ 2341 | $i=1 2342 | foreach($Property in $ReferencePropertySet){ 2343 | $Value = "Empty Value" 2344 | $IsURI = $false 2345 | if($($Object.$Property) -ne $null){ 2346 | $Value = $($Object.$Property) 2347 | 2348 | } 2349 | $AppliedStyle = $StyleNormal 2350 | switch -regex ($($Value.GetType())){ 2351 | "(^uint[0-9]{2}$)|(^int[0-9]{2}$)|(^long$)|(^int$)" { 2352 | $AppliedStyle = $StyleNumber 2353 | } 2354 | "(double)|(float)|(decimal)" { 2355 | $AppliedStyle = $StyleFloat 2356 | } 2357 | "datetime" { 2358 | $AppliedStyle = $StyleDate 2359 | } 2360 | "^string$"{ 2361 | if($([System.URI]::IsWellFormedUriString([System.URI]::EscapeUriString($Value),[System.UriKind]::Absolute)) -and $($Value -match "(^\\\\)|(^http://)|(^ftp://)|(^[a-zA-Z]:(//|\\))|(^https://)")) 2362 | { 2363 | $AppliedStyle = $StyleURI 2364 | $IsURI = $true 2365 | } 2366 | } 2367 | } 2368 | 2369 | if($IsURI){ 2370 | $sheet | Set-OOXMLRangeValue -Row $RowPosition -Col $i -Value $Value -StyleSheet $AppliedStyle -Uri | Out-Null 2371 | }else{ 2372 | $sheet | Set-OOXMLRangeValue -Row $RowPosition -Col $i -Value $Value -StyleSheet $AppliedStyle | Out-Null 2373 | } 2374 | $i++ 2375 | } 2376 | $RowPosition++ 2377 | } 2378 | 2379 | $LastRow = $($RowPosition - 1) 2380 | $FirstDataRowIndex = $($Sheet.Dimension.Start.Row + 1) 2381 | 2382 | $StartColumn = Get-OOXMLColumnString -ColNumber $($Sheet.Dimension.Start.Column) 2383 | $EndColumn = Get-OOXMLColumnString -ColNumber $($Sheet.Dimension.End.Column) 2384 | 2385 | foreach($AssociatedFormulaInformation in $AssociatedFormulaInformations) 2386 | { 2387 | $FormulaColumnName = Get-OOXMLColumnString -ColNumber $($AssociatedFormulaInformation.ColumnIndex) 2388 | $FormulaRangeAddress = $("$FormulaColumnName" + "$FirstDataRowIndex" + ":" + "$FormulaColumnName$LastRow") 2389 | $FormulaAddress = $("$FormulaColumnName$RowPosition") 2390 | 2391 | Switch($AssociatedFormulaInformation.FormulaObject.Operation) 2392 | { 2393 | "SUM" { 2394 | $Sheet.Cells[$FormulaAddress].Formula = "=SUM($FormulaRangeAddress)" 2395 | } 2396 | "SUMIF" { 2397 | $Sheet.Cells[$FormulaAddress].Formula = "=SUMIF($FormulaRangeAddress,`"$($AssociatedFormulaInformation.FormulaObject.Criteria)`")" 2398 | } 2399 | "AVERAGE" { 2400 | $Sheet.Cells[$FormulaAddress].Formula = "=AVERAGE($FormulaRangeAddress)" 2401 | } 2402 | "AVERAGEIF" { 2403 | $Sheet.Cells[$FormulaAddress].Formula = "=AVERAGEIF($FormulaRangeAddress,`"$($AssociatedFormulaInformation.FormulaObject.Criteria)`")" 2404 | } 2405 | "COUNT" { 2406 | $Sheet.Cells[$FormulaAddress].Formula = "=COUNT($FormulaRangeAddress)" 2407 | } 2408 | "COUNTIF" { 2409 | $Sheet.Cells[$FormulaAddress].Formula = "=COUNTIF($FormulaRangeAddress,`"$($AssociatedFormulaInformation.FormulaObject.Criteria)`")" 2410 | } 2411 | "MAX" { 2412 | $Sheet.Cells[$FormulaAddress].Formula = "=MAX($FormulaRangeAddress)" 2413 | } 2414 | "MIN" { 2415 | $Sheet.Cells[$FormulaAddress].Formula = "=MAX($FormulaRangeAddress)" 2416 | } 2417 | } 2418 | 2419 | $FormulaObjectStyle = $StyleCollection[$AssociatedFormulaInformation.FormulaObject.Style] 2420 | $sheet.Cells[$FormulaAddress].StyleName = $FormulaObjectStyle.Name 2421 | } 2422 | 2423 | foreach($AssociatedConditionalFormatting in $AssociatedConditionalFormattings) 2424 | { 2425 | 2426 | $ColumnName = Get-OOXMLColumnString -ColNumber $($AssociatedConditionalFormatting.ColumnIndex) 2427 | 2428 | $Address = $("$ColumnName" + "$FirstDataRowIndex" + ":" + "$ColumnName" + "$LastRow") 2429 | $AddressWide = $("$StartColumn" + "$FirstDataRowIndex" + ":" + "$EndColumn" + "$LastRow") 2430 | 2431 | if($Precise) 2432 | { 2433 | $sheet | Add-OOXMLConditionalFormatting -Addresses $Address -RuleType $($AssociatedConditionalFormatting.FormattingObject.Condition) -StyleSheet $StyleCollection[$AssociatedConditionalFormatting.FormattingObject.Style] -ConditionValue $($AssociatedConditionalFormatting.FormattingObject.Value) 2434 | } 2435 | else 2436 | { 2437 | $Expression = [string]::Empty 2438 | $StringEscape = [string]::Empty 2439 | 2440 | switch -regex ($($($AssociatedConditionalFormatting.FormattingObject.Value).GetType())){ 2441 | "^string$"{ 2442 | $StringEscape = "`"" 2443 | } 2444 | } 2445 | 2446 | switch($($AssociatedConditionalFormatting.FormattingObject.Condition)) 2447 | { 2448 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::GreaterThan) 2449 | { 2450 | $Symbol = ">" 2451 | $Expression = "$" + "$ColumnName" + "$FirstDataRowIndex" + $Symbol + $StringEscape + $($AssociatedConditionalFormatting.FormattingObject.Value) + $StringEscape 2452 | } 2453 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::GreaterThanOrEqual) 2454 | { 2455 | $Symbol = ">=" 2456 | $Expression = "$" + "$ColumnName" + "$FirstDataRowIndex" + $Symbol + $StringEscape + $($AssociatedConditionalFormatting.FormattingObject.Value) + $StringEscape 2457 | } 2458 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::LessThan) 2459 | { 2460 | $Symbol = "<" 2461 | $Expression = "$" + "$ColumnName" + "$FirstDataRowIndex" + $Symbol + $StringEscape + $($AssociatedConditionalFormatting.FormattingObject.Value) + $StringEscape 2462 | } 2463 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::LessThanOrEqual) 2464 | { 2465 | $Symbol = "<=" 2466 | $Expression = "$" + "$ColumnName" + "$FirstDataRowIndex" + $Symbol + $StringEscape + $($AssociatedConditionalFormatting.FormattingObject.Value) + $StringEscape 2467 | } 2468 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::NotEqual) 2469 | { 2470 | $Symbol = "<>" 2471 | $Expression = "$" + "$ColumnName" + "$FirstDataRowIndex" + $Symbol + $StringEscape + $($AssociatedConditionalFormatting.FormattingObject.Value) + $StringEscape 2472 | } 2473 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::Equal) 2474 | { 2475 | $Symbol = "=" 2476 | $Expression = "$" + "$ColumnName" + "$FirstDataRowIndex" + $Symbol + $StringEscape + $($AssociatedConditionalFormatting.FormattingObject.Value) + $StringEscape 2477 | } 2478 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::ContainsText) 2479 | { 2480 | $Expression = "IF(COUNTIF($" + "$ColumnName" + "$FirstDataRowIndex" + "," + $StringEscape + "*" + $($AssociatedConditionalFormatting.FormattingObject.Value) + "*" + $StringEscape + ") > 0,TRUE,FALSE)" 2481 | } 2482 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::BeginsWith) 2483 | { 2484 | $Expression = "IF(COUNTIF($" + "$ColumnName" + "$FirstDataRowIndex" + "," + $StringEscape + $($AssociatedConditionalFormatting.FormattingObject.Value) + "*" + $StringEscape + ") > 0,TRUE,FALSE)" 2485 | } 2486 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::EndsWith) 2487 | { 2488 | $Expression = "IF(COUNTIF($" + "$ColumnName" + "$FirstDataRowIndex" + "," + $StringEscape + "*" + $($AssociatedConditionalFormatting.FormattingObject.Value) + $StringEscape + ") > 0,TRUE,FALSE)" 2489 | } 2490 | } 2491 | 2492 | Write-Host $Expression 2493 | 2494 | if($Expression.Length -gt 0) 2495 | { 2496 | $sheet | Add-OOXMLConditionalFormatting -Addresses $AddressWide -RuleType $([ExcelPSLib.EnumConditionalFormattingRuleType]::Expression) -StyleSheet $StyleCollection[$AssociatedConditionalFormatting.FormattingObject.Style] -ConditionValue $Expression 2497 | } 2498 | } 2499 | } 2500 | 2501 | if($AutoFit){ 2502 | $EndColumn = Get-OOXMLColumnString -ColNumber $($ReferencePropertySet.Length) 2503 | $FirstColumn = Get-OOXMLColumnString -ColNumber 1 2504 | $Sheet.Cells["$FirstColumn$($Sheet.Dimension.Start.Row):$EndColumn$LastRow"].AutoFitColumns() 2505 | } 2506 | 2507 | <# 2508 | if($FreezedColumnName) 2509 | { 2510 | $ColIdx = 1 2511 | foreach($Property in $ReferencePropertySet) 2512 | { 2513 | if($FreezedColumnName -eq $Property) 2514 | { 2515 | $Sheet.View.FreezePanes($FirstDataRowIndex,$ColIdx) 2516 | } 2517 | $ColIdx++ 2518 | } 2519 | } 2520 | #> 2521 | 2522 | if($FreezedColumnName) 2523 | { 2524 | $ColIdx = $ReferencePropertySet.IndexOf($FreezedColumnName) + 1 2525 | if($ColIdx -gt 0){ 2526 | $Sheet.View.FreezePanes($FirstDataRowIndex,$ColIdx) 2527 | } 2528 | } 2529 | 2530 | foreach($CustomFormating in $CustomFormatings) 2531 | { 2532 | #TODO 2533 | } 2534 | 2535 | if($DataValidationLists) 2536 | { 2537 | 2538 | $excel | Add-OOXMLWorksheet -WorkSheetName "REF_DATA" 2539 | $DataWorkSheet = Select-OOXMLWorkSheet -WorkBook $book -WorkSheetName "REF_DATA" 2540 | foreach($DataValidationList in $DataValidationLists) 2541 | { 2542 | $DataColumnIndex = ($book.Names.Count + 1) 2543 | 2544 | Write-Host "Named Range Count : $($book.Names.Count)" 2545 | 2546 | $ValueIndex = 1; 2547 | 2548 | foreach($Value in $DataValidationList.Values) 2549 | { 2550 | $DataWorkSheet | Set-OOXMLRangeValue -Row $ValueIndex -Col $DataColumnIndex -Value $Value 2551 | $ValueIndex++ 2552 | } 2553 | 2554 | $DataRange = Convert-OOXMLCellsCoordinates -StartRow 1 -StartCol $DataColumnIndex -EndRow $ValueIndex -EndCol $DataColumnIndex 2555 | $book.Names.Add($DataValidationList.Name,$DataWorkSheet.Cells[$DataRange]) 2556 | } 2557 | 2558 | $FromCol = Get-OOXMLColumnString -ColNumber $($DataWorkSheet.Dimension.Start.Column) 2559 | $ToCol = Get-OOXMLColumnString -ColNumber $($DataWorkSheet.Dimension.End.Column) 2560 | $FromRow = $DataWorkSheet.Dimension.Start.Row 2561 | $ToRow = $DataWorkSheet.Dimension.End.Row 2562 | 2563 | $DataWorkSheet.Cells[$("$FromCol$FromRow" + ":" + "$ToCol$ToRow")].AutoFitColumns() 2564 | 2565 | if($DataValidationAssignements) 2566 | { 2567 | foreach($DataValidationAssignement in $DataValidationAssignements) 2568 | { 2569 | $Name = $DataValidationAssignement.Name 2570 | $NamedRange = $book.Names.Item($Name) 2571 | $ColumnNames = $($DataValidationAssignement.ColumnNames) 2572 | 2573 | foreach($ColumnName in $ColumnNames) 2574 | { 2575 | $SelectedColumn = $($($ReferencePropertySet.IndexOf($ColumnName)) + 1) 2576 | $ViewRangeAddress = Convert-OOXMLCellsCoordinates -StartRow $($Sheet.Dimension.Start.Row) -StartCol $SelectedColumn -EndRow $LastRow -EndCol $SelectedColumn 2577 | $sheet | Add-OOXMLDataValidation -NamedRange $NamedRange -ViewRangeAddress $ViewRangeAddress 2578 | } 2579 | } 2580 | } 2581 | } 2582 | 2583 | $excel | Save-OOXMLPackage -FileFullPath $FileFullPath -Dispose 2584 | return $true 2585 | } 2586 | catch 2587 | { 2588 | return $_.Exception.Message 2589 | } 2590 | 2591 | } 2592 | } 2593 | 2594 | Function Add-OOXMLDataValidation { 2595 | <# 2596 | .SYNOPSIS 2597 | Apply a data validation on a given range on a given worksheet 2598 | 2599 | .DESCRIPTION 2600 | Apply a data validation on a given range on a given worksheet 2601 | 2602 | .PARAMETER ExcelWorksheet 2603 | The WorkSheet object where the data range is located 2604 | 2605 | .PARAMETER ViewRangeAddress 2606 | The targeted range where data validation will be applied 2607 | 2608 | .PARAMETER NamedRange 2609 | This is the ExcelNamedRange containing the list of valid value 2610 | 2611 | .PARAMETER ErrorStyle 2612 | This the style of the error message 2613 | 2614 | .PARAMETER ErrorTitle 2615 | This is the title of the error message 2616 | 2617 | .PARAMETER Error 2618 | This is the description of the error 2619 | 2620 | .EXAMPLE 2621 | Add-OOXMLConditionalFormatting -WorkSheet $sheet -Addresses "A1:A23" -StyleSheet $StyleGreen -RuleType GreaterThanOrEqual 2622 | 2623 | Description 2624 | ----------- 2625 | Calls a function that will apply a data validation on a given range on a given worksheet 2626 | 2627 | .NOTES 2628 | 2629 | .LINK 2630 | 2631 | #> 2632 | [CmdletBinding()] 2633 | param( 2634 | [parameter(Mandatory=$true, ValueFromPipeline=$true)] 2635 | [OfficeOpenXml.ExcelWorksheet]$ExcelWorksheet, 2636 | [parameter(Mandatory=$true)] 2637 | [string]$ViewRangeAddress, 2638 | [parameter(Mandatory=$true)] 2639 | [OfficeOpenXml.ExcelNamedRange]$NamedRange, 2640 | [OfficeOpenXml.DataValidation.ExcelDataValidationWarningStyle]$ErrorStyle = [OfficeOpenXml.DataValidation.ExcelDataValidationWarningStyle]::stop, 2641 | [string]$ErrorTitle = "Error", 2642 | [string]$Error = "Invalid Data entered !" 2643 | ) 2644 | process 2645 | { 2646 | [OfficeOpenXml.DataValidation.ExcelDataValidationList]$ExcelDataValidationList = $ExcelWorksheet.DataValidations.AddListValidation($ViewRangeAddress) 2647 | $ExcelDataValidationList.ShowErrorMessage = $true 2648 | $ExcelDataValidationList.ErrorStyle = $ErrorStyle 2649 | $ExcelDataValidationList.ErrorTitle = $ErrorTitle 2650 | $ExcelDataValidationList.Error = $Error 2651 | $ExcelDataValidationList.Formula.ExcelFormula = "=" + $NamedRange.FullAddressAbsolute 2652 | } 2653 | 2654 | } 2655 | 2656 | Function Add-OOXMLConditionalFormatting { 2657 | <# 2658 | .SYNOPSIS 2659 | Apply a stylesheet based on a conditional rule on a given range 2660 | 2661 | .DESCRIPTION 2662 | Apply a stylesheet based on a conditional rule on a given range 2663 | 2664 | .PARAMETER WorkSheet 2665 | The WorkSheet object where the cell is located 2666 | 2667 | .PARAMETER Addresses 2668 | The targeted adresses where conditional formatting will be applied 2669 | 2670 | .PARAMETER RuleType 2671 | The contitional formating rule type (Reduced set) 2672 | 2673 | .PARAMETER StyleSheet 2674 | The style sheet you want to apply to the cell 2675 | 2676 | .EXAMPLE 2677 | Add-OOXMLConditionalFormatting -WorkSheet $sheet -Addresses "A1:A23" -StyleSheet $StyleGreen -RuleType GreaterThanOrEqual 2678 | 2679 | Description 2680 | ----------- 2681 | Calls a function that will apply a stylesheet based on a conditional rule on a given range 2682 | 2683 | .NOTES 2684 | 2685 | .LINK 2686 | 2687 | #> 2688 | [CmdletBinding()] 2689 | param ( 2690 | [parameter(Mandatory=$true, ValueFromPipeline=$true)] 2691 | [OfficeOpenXml.ExcelWorksheet]$WorkSheet, 2692 | [parameter(Mandatory=$true)] 2693 | [string[]]$Addresses, 2694 | [parameter(Mandatory=$true)] 2695 | [ExcelPSLib.EnumConditionalFormattingRuleType]$RuleType, 2696 | [parameter(Mandatory=$true)] 2697 | [OfficeOpenXml.Style.XmlAccess.ExcelNamedStyleXml]$StyleSheet, 2698 | [parameter(Mandatory=$true)] 2699 | [string]$ConditionValue 2700 | ) 2701 | process{ 2702 | try 2703 | { 2704 | $AddressString = "" 2705 | $First = $true 2706 | foreach($Address in $Addresses){ 2707 | if(-not $First){ 2708 | $AddressString += "," 2709 | $First = $false 2710 | } 2711 | $AddressString += "$Address" 2712 | } 2713 | 2714 | $ExcelAddress = New-Object OfficeOpenXml.ExcelAddress($AddressString) 2715 | 2716 | Switch($RuleType){ 2717 | 2718 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::BeginsWith) { 2719 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddBeginsWith($ExcelAddress) 2720 | $ConditionalFormatted.Text = $ConditionValue 2721 | } 2722 | 2723 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::ContainsBlanks) { 2724 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddContainsBlanks($ExcelAddress) 2725 | } 2726 | 2727 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::ContainsErrors) { 2728 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddContainsErrors($ExcelAddress) 2729 | } 2730 | 2731 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::ContainsText) { 2732 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddContainsText($ExcelAddress) 2733 | $ConditionalFormatted.Text = $ConditionValue 2734 | } 2735 | 2736 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::EndsWith) { 2737 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddEndsWith($ExcelAddress) 2738 | $ConditionalFormatted.Text = $ConditionValue 2739 | } 2740 | 2741 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::Equal) { 2742 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddEqual($ExcelAddress) 2743 | $ConditionalFormatted.Formula = $ConditionValue 2744 | } 2745 | 2746 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::Expression) { 2747 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddExpression($ExcelAddress) 2748 | $ConditionalFormatted.Formula = $ConditionValue 2749 | } 2750 | 2751 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::GreaterThan) { 2752 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddGreaterThan($ExcelAddress) 2753 | $ConditionalFormatted.Formula = $ConditionValue 2754 | } 2755 | 2756 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::GreaterThanOrEqual) { 2757 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddGreaterThanOrEqual($ExcelAddress) 2758 | $ConditionalFormatted.Formula = $ConditionValue 2759 | } 2760 | 2761 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::LessThan) { 2762 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddLessThan($ExcelAddress) 2763 | $ConditionalFormatted.Formula = $ConditionValue 2764 | } 2765 | 2766 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::LessThanOrEqual) { 2767 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddLessThanOrEqual($ExcelAddress) 2768 | $ConditionalFormatted.Formula = $ConditionValue 2769 | } 2770 | 2771 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::NotContainsBlanks) { 2772 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddNotContainsBlanks($ExcelAddress) 2773 | } 2774 | 2775 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::NotContainsErrors) { 2776 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddNotContainsErrors($ExcelAddress) 2777 | } 2778 | 2779 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::NotContainsText) { 2780 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddNotContainsText($ExcelAddress) 2781 | $ConditionalFormatted.Text = $ConditionValue 2782 | } 2783 | 2784 | $([ExcelPSLib.EnumConditionalFormattingRuleType]::NotEqual) { 2785 | $ConditionalFormatted = $WorkSheet.ConditionalFormatting.AddNotEqual($ExcelAddress) 2786 | $ConditionalFormatted.Formula = $ConditionValue 2787 | } 2788 | } 2789 | 2790 | $ConditionalFormatted.Style.Fill.PatternType = $StyleSheet.Style.Fill.PatternType 2791 | 2792 | $ConvertedBackgroundColor = [System.Convert]::ToInt32($($StyleSheet.Style.Fill.BackgroundColor.Rgb),16) 2793 | $ConditionalFormatted.Style.Fill.BackgroundColor.Color = [System.Drawing.Color]::FromArgb($ConvertedBackgroundColor) 2794 | 2795 | if($StyleSheet.Style.Border.Left.Style){$ConditionalFormatted.Style.Border.Left.Style = $StyleSheet.Style.Border.Left.Style} 2796 | 2797 | if($StyleSheet.Style.Border.Right.Style){$ConditionalFormatted.Style.Border.Right.Style = $StyleSheet.Style.Border.Right.Style} 2798 | 2799 | if($StyleSheet.Style.Border.Top.Style){$ConditionalFormatted.Style.Border.Top.Style = $StyleSheet.Style.Border.Top.Style} 2800 | 2801 | if($StyleSheet.Style.Border.Bottom.Style){$ConditionalFormatted.Style.Border.Bottom.Style = $StyleSheet.Style.Border.Bottom.Style} 2802 | 2803 | $ConvertedLeftBorderColor = [System.Convert]::ToInt32($($StyleSheet.Style.Border.Left.Color.Rgb),16) 2804 | $ConditionalFormatted.Style.Border.Left.Color.Color = [System.Drawing.Color]::FromArgb($ConvertedLeftBorderColor) 2805 | 2806 | $ConvertedRightBorderColor = [System.Convert]::ToInt32($($StyleSheet.Style.Border.Right.Color.Rgb),16) 2807 | $ConditionalFormatted.Style.Border.Right.Color.Color = [System.Drawing.Color]::FromArgb($ConvertedRightBorderColor) 2808 | 2809 | $ConvertedTopBorderColor = [System.Convert]::ToInt32($($StyleSheet.Style.Border.Top.Color.Rgb),16) 2810 | $ConditionalFormatted.Style.Border.Top.Color.Color = [System.Drawing.Color]::FromArgb($ConvertedTopBorderColor) 2811 | 2812 | $ConvertedBottomBorderColor = [System.Convert]::ToInt32($($StyleSheet.Style.Border.Bottom.Color.Rgb),16) 2813 | $ConditionalFormatted.Style.Border.Bottom.Color.Color = [System.Drawing.Color]::FromArgb($ConvertedBottomBorderColor) 2814 | 2815 | $ConvertedFontColor = [System.Convert]::ToInt32($($StyleSheet.Style.Font.Color.Rgb),16) 2816 | $ConditionalFormatted.Style.Font.Color.Color = [System.Drawing.Color]::FromArgb($ConvertedFontColor) 2817 | 2818 | $ConditionalFormatted.Style.Font.Italic = $StyleSheet.Style.Font.Italic 2819 | $ConditionalFormatted.Style.Font.Bold = $StyleSheet.Style.Font.Bold 2820 | 2821 | $ConditionalFormatted.Style.NumberFormat.Format = $StyleSheet.Style.Numberformat.Format 2822 | } 2823 | catch 2824 | { 2825 | return $_.Exception.Message 2826 | } 2827 | } 2828 | } 2829 | 2830 | Function Get-OOXMLFormulaObject { 2831 | <# 2832 | .SYNOPSIS 2833 | This function is just an helper that will return a pscustomobject compliant with the Export-OOXML cmdlet (-FormulaObject) 2834 | 2835 | .DESCRIPTION 2836 | This function is just an helper that will return a pscustomobject compliant with the Export-OOXML cmdlet (-FormulaObject) 2837 | 2838 | .PARAMETER Name 2839 | This is the property targeted by the conditional formatting 2840 | 2841 | .PARAMETER Style 2842 | Is one of the 141 style available that will be applied 2843 | 2844 | .PARAMETER Operation 2845 | The operation you want to perform on the column "SUM","AVERAGE","COUNT","MAX","MIN","SUMIF","AVERAGEIF","COUNTIF" 2846 | 2847 | .PARAMETER Criteria 2848 | The criteria for the following conditional operations "SUMIF","AVERAGEIF","COUNTIF" 2849 | 2850 | .EXAMPLE 2851 | Get-OOXMLFormulaObject -Name Size -Style DarkGray -Operation "COUNTIF" -Criteria ">5" 2852 | 2853 | Description 2854 | ----------- 2855 | Calls a function which will return a pscustomobject compliant with the Export-OOXML cmdlet (-FormulaObject) 2856 | 2857 | .NOTES 2858 | 2859 | .LINK 2860 | 2861 | #> 2862 | [CmdletBinding()] 2863 | param( 2864 | [alias("N")] 2865 | [parameter(Mandatory=$true)] 2866 | [string]$Name, 2867 | [alias("S")] 2868 | [parameter(Mandatory=$true)] 2869 | [ExcelPSLib.EnumColors]$Style, 2870 | [alias("O")] 2871 | [parameter(Mandatory=$true)] 2872 | [ExcelPSLib.EnumOperations]$Operation, 2873 | [alias("C")] 2874 | [string]$Criteria = [String]::Empty 2875 | ) 2876 | process{ 2877 | return [PSCustomObject]@{Name=$Name;Style=$($Style.ToString());Operation=$($Operation.ToString());Criteria=$Criteria} 2878 | } 2879 | } 2880 | 2881 | Function Get-OOXMLConditonalFormattingCustomObject{ 2882 | <# 2883 | .SYNOPSIS 2884 | This function is just an helper that will return a pscustomobject compliant with the Export-OOXML cmdlet (-ConditionalFormatings) 2885 | 2886 | .DESCRIPTION 2887 | This function is just an helper that will return a pscustomobject compliant with the Export-OOXML cmdlet (-ConditionalFormatings) 2888 | 2889 | .PARAMETER Name 2890 | This is the property targeted by the conditional formatting 2891 | 2892 | .PARAMETER Style 2893 | Is one of the four style available that will be applied if the condition is true 2894 | 2895 | .PARAMETER Condition 2896 | Condition is one of the condition present in the following enum EnumConditionalFormattingRuleType 2897 | 2898 | .PARAMETER Value 2899 | Is the value that will be used on the propoertie according to the choosen condition 2900 | 2901 | .EXAMPLE 2902 | $ConditionalObject = Get-OOXMLConditonalFormattingCustomObject -Name "__PROPERTY_COUNT" -Style Red -Condition GreaterThan -Value 30 2903 | 2904 | Description 2905 | ----------- 2906 | Calls a function which will return a pscustomobject compliant with the Export-OOXML cmdlet (-ConditionalFormatings) 2907 | 2908 | .NOTES 2909 | 2910 | .LINK 2911 | 2912 | #> 2913 | [CmdletBinding()] 2914 | param( 2915 | [alias("N")] 2916 | [parameter(Mandatory=$true)] 2917 | [string]$Name, 2918 | [alias("S")] 2919 | [parameter(Mandatory=$true)] 2920 | [ExcelPSLib.EnumColors]$Style, 2921 | [alias("C")] 2922 | [parameter(Mandatory=$true)] 2923 | [ExcelPSLib.EnumConditionalFormattingRuleType]$Condition, 2924 | [alias("V")] 2925 | [parameter(Mandatory=$true)] 2926 | $Value 2927 | ) 2928 | process{ 2929 | return [PSCustomObject]@{Name=$Name;Style=$($Style.ToString());Condition=$Condition;Value=$Value} 2930 | } 2931 | } 2932 | 2933 | Function Test-DataTypeIntegrity{ 2934 | <# 2935 | .SYNOPSIS 2936 | This function was made to test that all data under the header of a column are of the same data type 2937 | 2938 | .DESCRIPTION 2939 | This function was made to test that all data under the header of a column are of the same data type 2940 | 2941 | .PARAMETER Worksheet 2942 | This is the worksheet targeted by this test function 2943 | 2944 | .PARAMETER Column 2945 | This is the column targeted by this test function 2946 | 2947 | .EXAMPLE 2948 | Test-DataTypeIntegrity -Worksheet $Worksheet -Column 4 2949 | 2950 | Description 2951 | ----------- 2952 | Calls a function which will test that all data under the header of a column are of the same data type 2953 | 2954 | .NOTES 2955 | 2956 | .LINK 2957 | 2958 | #> 2959 | [CmdletBinding()] 2960 | param( 2961 | [parameter(Mandatory=$true)] 2962 | [OfficeOpenXml.ExcelWorksheet]$Worksheet, 2963 | [parameter(Mandatory=$true)] 2964 | [int]$Column 2965 | ) 2966 | process{ 2967 | $Top = $Worksheet.Dimension.Start.Row 2968 | $Left = $Worksheet.Dimension.Start.Column 2969 | $Bottom = $Worksheet.Dimension.End.Row 2970 | $Right = $Worksheet.Dimension.End.Column 2971 | 2972 | for($i=$Top+1; $i -lt ($Bottom+1); $i++){ 2973 | [string]$CurrentDataType = $($Worksheet.GetValue($i,$Column).GetType().FullName) 2974 | if($i -eq ($Top+1)){[string]$DataType = $CurrentDataType} 2975 | if($DataType -inotmatch $CurrentDataType){ 2976 | return "string" 2977 | } 2978 | } 2979 | return $DataType 2980 | } 2981 | } 2982 | 2983 | Function Import-OOXML{ 2984 | <# 2985 | .SYNOPSIS 2986 | Import an XLSX File an convert it to an array of objects 2987 | 2988 | .DESCRIPTION 2989 | Import an XLSX File an convert it to an array of objects 2990 | 2991 | .PARAMETER FileFullPath 2992 | The full path of the XLSX File 2993 | 2994 | .PARAMETER WorksheetName 2995 | The name of the worksheet in the XLSX Document 2996 | 2997 | .PARAMETER WorksheetID 2998 | The id of the worksheet in the XLSX Document 2999 | 3000 | .PARAMETER KeepDataType 3001 | This is a switch parameter that when set will indicate to the import function that it should try to detect and keep data type per column 3002 | 3003 | .PARAMETER Range 3004 | This is an optional parameter which allow one to specify a range to use for the input. The range is specified in the normal Excel format e.g. C10:J22 3005 | 3006 | .EXAMPLE 3007 | Import-OOXML -FileFullPath C:\Temp\DevBook.xlsx -WorksheetNumber 1 3008 | 3009 | .EXAMPLE 3010 | Import-OOXML -FileFullPath C:\Temp\DevBook.xlsx -WorksheetName Sheet1 3011 | 3012 | .EXAMPLE 3013 | Import-OOXML -FileFullPath C:\Temp\DevBook.xlsx -WorksheetNumber 1 -Range "C4:J10" 3014 | 3015 | Description 3016 | ----------- 3017 | Calls a function that will import an XLSX File an convert it to an array of objects 3018 | 3019 | .NOTES 3020 | 3021 | .LINK 3022 | 3023 | #> 3024 | [CmdletBinding()] 3025 | param( 3026 | [parameter(Mandatory=$true)] 3027 | [ValidateScript({Test-Path -Path $_ -PathType Leaf})] 3028 | [String]$FileFullPath, 3029 | [parameter(ParameterSetName="WorksheetIndex", Mandatory=$true)] 3030 | [int]$WorkSheetNumber, 3031 | [parameter(ParameterSetName="WorksheetName", Mandatory=$true)] 3032 | [string]$WorkSheetName, 3033 | [string]$Range, 3034 | [switch]$KeepDataType=$false 3035 | ) 3036 | begin{ 3037 | Function Get-ColumnHeaders{ 3038 | $ColumHeaders = @() 3039 | } 3040 | } 3041 | process{ 3042 | try 3043 | { 3044 | [System.IO.FileInfo]$XLSXFile = New-Object System.IO.FileInfo($FileFullPath) 3045 | $ExcelInstance = New-Object OfficeOpenXml.ExcelPackage($XLSXFile) 3046 | [OfficeOpenXml.ExcelWorkbook]$Workbook = $ExcelInstance | Get-OOXMLWorkbook 3047 | if($Workbook -ne $null){ 3048 | if($Workbook.Worksheets.Count -ge $WorksheetId){ 3049 | if($WorkSheetName){ 3050 | [OfficeOpenXml.ExcelWorksheet]$Worksheet = $Workbook | Select-OOXMLWorkSheet -WorksheetName $WorksheetName 3051 | }else{ 3052 | [OfficeOpenXml.ExcelWorksheet]$Worksheet = $Workbook | Select-OOXMLWorkSheet -WorkSheetNumber $WorkSheetNumber 3053 | } 3054 | 3055 | $Top = $Worksheet.Dimension.Start.Row 3056 | $Left = $Worksheet.Dimension.Start.Column 3057 | $Bottom = $Worksheet.Dimension.End.Row 3058 | $Right = $Worksheet.Dimension.End.Column 3059 | 3060 | If($Range){ 3061 | $addrHash = Convert-OOXMLFromExcelCoordinates -Address $Range 3062 | $Top = $addrHash["TopRow"] 3063 | $Left = $addrHash["LeftCol"] 3064 | $Bottom = $addrHash["BottomRow"] 3065 | $Right = $addrHash["RightCol"] 3066 | } 3067 | 3068 | $ClassGuidName = "Custom_" + [System.Guid]::NewGuid().ToString().Replace("-","") 3069 | 3070 | $ClassDeclaration = "public class $ClassGuidName" 3071 | $ClassDeclaration += [System.Environment]::NewLine 3072 | $ClassDeclaration += "{" 3073 | $TestString = "" 3074 | 3075 | $PropertyList = @() 3076 | 3077 | ######### If column header has no data, Stop !!! 3078 | $i=$left 3079 | While($i -lt ($Right+1)) 3080 | { 3081 | [string]$Data = $($Worksheet.GetValue($top,$i)) 3082 | if(!$Data) 3083 | { 3084 | $i = $Right 3085 | } 3086 | else 3087 | { 3088 | $Data = [Regex]::Replace($Data, "[^0-9a-zA-Z_]", "") 3089 | $PropertyList += $Data 3090 | $ClassDeclaration += $([System.Environment]::NewLine) 3091 | 3092 | if($KeepDataType){ 3093 | $ClassDeclaration += "public $(Test-DataTypeIntegrity -Worksheet $Worksheet -Column $i) @$($Data);" 3094 | }else{ 3095 | $ClassDeclaration += "public string @$($Data);" 3096 | } 3097 | 3098 | } 3099 | $i++; 3100 | } 3101 | 3102 | $ClassDeclaration += $([System.Environment]::NewLine) 3103 | $ClassDeclaration += "}" 3104 | 3105 | $FinalClassDefinition = @" 3106 | $ClassDeclaration 3107 | "@ 3108 | 3109 | try {Add-Type -Language CSharp -TypeDefinition $FinalClassDefinition;} catch { return $_.Exception.Message } 3110 | 3111 | $FullArray = @() 3112 | for($i=$Top+1; $i -lt ($Bottom+1); $i++){ 3113 | $TempObject = New-Object $ClassGuidName 3114 | $idx=0 3115 | foreach($Prop in $PropertyList){ 3116 | $TempObject.$Prop = $($Worksheet.GetValue($i,$($Left+$idx))) 3117 | $idx++ 3118 | } 3119 | $FullArray += $TempObject 3120 | } 3121 | $FullArray 3122 | 3123 | }else{ 3124 | Write-Error "This worksheet doesn't exist !" 3125 | } 3126 | }else{ 3127 | Write-Error "There is no workbook in this document !" 3128 | } 3129 | } 3130 | catch 3131 | { 3132 | return $_.Exception.Message 3133 | } 3134 | } 3135 | } 3136 | 3137 | Function Save-OOXMLPackage { 3138 | <# 3139 | .SYNOPSIS 3140 | Save the Excel Instance to a definited XLSX File 3141 | 3142 | .DESCRIPTION 3143 | Save the Excel Instance to a definited XLSX File 3144 | 3145 | .PARAMETER FileFullPath 3146 | The full path of the XLSX File 3147 | 3148 | .PARAMETER ExcelInstance 3149 | The Current ExcelPackage instance 3150 | 3151 | .PARAMETER Dispose 3152 | Free the memory by closing the Excel Instance 3153 | 3154 | .EXAMPLE 3155 | $excel | Save-OOXMLPackage -FileFullPath $OutputFileName -Dispose 3156 | 3157 | Description 3158 | ----------- 3159 | Calls a function which will save the Current ExcelPackage instance to an XLSX file 3160 | 3161 | .NOTES 3162 | 3163 | .LINK 3164 | 3165 | #> 3166 | [CmdletBinding()] 3167 | param ( 3168 | [string]$FileFullPath, 3169 | [parameter(Mandatory=$true,ValueFromPipeline=$true)] 3170 | [OfficeOpenXml.ExcelPackage]$ExcelInstance, 3171 | [switch]$Dispose 3172 | ) 3173 | process{ 3174 | try 3175 | { 3176 | if($FileFullPath){ 3177 | $bin = $ExcelInstance.GetAsByteArray(); 3178 | [io.file]::WriteAllBytes($FileFullPath,$bin) 3179 | }else{ 3180 | $ExcelInstance.Save() 3181 | } 3182 | 3183 | if($Dispose){ 3184 | $ExcelInstance.Dispose() 3185 | } 3186 | } 3187 | catch 3188 | { 3189 | return $_.Exception.Message 3190 | } 3191 | } 3192 | } 3193 | 3194 | Function Get-OOXMLDataValidationCustomObject { 3195 | <# 3196 | .SYNOPSIS 3197 | Return a Data Validation Object of the correct format 3198 | 3199 | .DESCRIPTION 3200 | Return a Data Validation Object of the correct format 3201 | 3202 | .PARAMETER Name 3203 | The name that will be given to the Data Range 3204 | 3205 | .PARAMETER Values 3206 | The values that will be inserted into the Data Range 3207 | 3208 | 3209 | .EXAMPLE 3210 | Get-OOXMLDataValidationCustomObject -Name "Data Name" -Values @("Value_01","Value_02","Value_03") 3211 | 3212 | Description 3213 | ----------- 3214 | Calls a function that will return a Data Validation Object of the correct format : 3215 | 3216 | [pscustomobject]@{ 3217 | Name = "Name" 3218 | Values = @("Value_01","Value_02","Value_03") 3219 | } 3220 | 3221 | .NOTES 3222 | 3223 | .LINK 3224 | 3225 | #> 3226 | [CmdletBinding()] 3227 | param( 3228 | [parameter(Mandatory=$true)] 3229 | [string]$Name, 3230 | [parameter(Mandatory=$true)] 3231 | [object[]]$Values 3232 | ) 3233 | process 3234 | { 3235 | return [pscustomobject]@{ 3236 | Name = $Name 3237 | Values = $Values 3238 | } 3239 | } 3240 | } 3241 | 3242 | Function Get-OOXMLDataValidationAssignementCustomObject { 3243 | <# 3244 | .SYNOPSIS 3245 | Return a Data Validation Assignement Object of the correct format 3246 | 3247 | .DESCRIPTION 3248 | Return a Data Validation Assignement Object of the correct format 3249 | 3250 | .PARAMETER Name 3251 | The name of the named list containing the alowed value 3252 | 3253 | .PARAMETER ColumnNames 3254 | The name of the columns that should receive data validation 3255 | 3256 | .EXAMPLE 3257 | Get-OOXMLDataValidationAssignementCustomObject -DataValidationName "FirstList" -ColumnNames @("Name","Handles") 3258 | 3259 | Description 3260 | ----------- 3261 | Calls a function that will return a Data Validation Object of the correct format : 3262 | 3263 | [pscustomobject]@{ 3264 | Name = "Name" 3265 | ColumnNames = @("Col_01","Col_02","Col_03") 3266 | } 3267 | 3268 | .NOTES 3269 | 3270 | .LINK 3271 | 3272 | #> 3273 | [CmdletBinding()] 3274 | param( 3275 | [string]$DataValidationName, 3276 | [string[]]$ColumnNames 3277 | ) 3278 | process{ 3279 | return [pscustomobject]@{ 3280 | Name = $DataValidationName 3281 | ColumnNames = $ColumnNames 3282 | } 3283 | } 3284 | } 3285 | 3286 | Function Open-OOXML{ 3287 | <# 3288 | .SYNOPSIS 3289 | Opens an existing Excel file 3290 | 3291 | .DESCRIPTION 3292 | Opens an existing Excel file 3293 | 3294 | .PARAMETER FileFullPath 3295 | The location of the Excel file 3296 | 3297 | .EXAMPLE 3298 | open-OOXML -FileFullPath C:\Temp\DevBook.xlsx 3299 | 3300 | Description 3301 | ----------- 3302 | Returns the "OfficeOpenXml.ExcelPackage" object for the file 3303 | 3304 | .NOTES 3305 | 3306 | .LINK 3307 | 3308 | #> 3309 | [CmdletBinding()] 3310 | param( 3311 | [parameter(Mandatory=$true)] 3312 | [ValidateScript({Test-Path -Path $_ -PathType Leaf})] 3313 | [String]$FileFullPath 3314 | ) 3315 | begin{ 3316 | 3317 | } 3318 | process{ 3319 | $retval=$null 3320 | try{ 3321 | [System.IO.FileInfo]$XLSXFile = New-Object System.IO.FileInfo($FileFullPath) 3322 | $ExcelInstance = New-Object OfficeOpenXml.ExcelPackage($XLSXFile) 3323 | }catch{ 3324 | $retval = $_.Exception.Message 3325 | } 3326 | 3327 | if($retval -ne $null){ 3328 | return $retval 3329 | }else{ 3330 | return $ExcelInstance 3331 | } 3332 | } 3333 | } 3334 | 3335 | Function Convert-OOXMLFromExcelCoordinates{ 3336 | <# 3337 | .SYNOPSIS 3338 | Utility function to convert an Excel location reference to row and column numbers 3339 | 3340 | .DESCRIPTION 3341 | Converts an Excel range reference to row and column numbers. It returns a hash containing the values 3342 | 3343 | .PARAMETER Address 3344 | The Excel format of the cell address e.g. C22 or B22:G99 3345 | 3346 | .EXAMPLE 3347 | Convert-OOXMLFromExcelCoordinates -address "B3". This returns a hash containing: 3348 | Name Value 3349 | ---- ----- 3350 | RightCol 2 3351 | BottomRow 3 3352 | TopRow 3 3353 | LeftCol 2 3354 | 3355 | .EXAMPLE 3356 | Convert-OOXMLFromExcelCoordinates -address "B3:H10". This returns a hash containing: 3357 | Name Value 3358 | ---- ----- 3359 | RightCol 8 3360 | BottomRow 10 3361 | TopRow 3 3362 | LeftCol 2 3363 | 3364 | Description 3365 | ----------- 3366 | Returns a hash containing the numeric location of the cell. 3367 | 3368 | .NOTES 3369 | 3370 | .LINK 3371 | 3372 | #> 3373 | param( 3374 | [parameter(Mandatory=$true)][string]$Address 3375 | ) 3376 | 3377 | 3378 | $coordinates=@{} 3379 | $ExcelAddress = New-Object OfficeOpenXml.ExcelAddress($Address) 3380 | 3381 | $coordinates["TopRow"]=$ExcelAddress.Start.Row 3382 | $coordinates["LeftCol"]=$ExcelAddress.Start.Column 3383 | $coordinates["BottomRow"]=$ExcelAddress.end.Row 3384 | $coordinates["RightCol"]=$ExcelAddress.end.Column 3385 | 3386 | return $coordinates 3387 | } 3388 | 3389 | function Read-OOXMLcell{ 3390 | <# 3391 | .SYNOPSIS 3392 | Reads a single Excel cel 3393 | 3394 | .DESCRIPTION 3395 | Retrieves the value of a given cell 3396 | 3397 | .PARAMETER Row 3398 | The numeric row 3399 | 3400 | .PARAMETER Col 3401 | The numeric culumn 3402 | 3403 | .PARAMETER Address 3404 | The Excel format of the cell address e.g. C22 3405 | 3406 | .PARAMETER WorkSheet 3407 | The worksheet holding the information 3408 | 3409 | .EXAMPLE 3410 | read-oosmlcell -Worksheet $sheet -Row 3 -Col 2 3411 | 3412 | .EXAMPLE 3413 | read-oosmlcell -Worksheet $sheet -Address "B3" 3414 | 3415 | Description 3416 | ----------- 3417 | Returns the value in a specified cell 3418 | 3419 | .NOTES 3420 | 3421 | .LINK 3422 | 3423 | #> 3424 | param( 3425 | [parameter(ParameterSetName="RowCol",Mandatory=$true)][string]$Row, 3426 | [parameter(ParameterSetName="RowCol",Mandatory=$true)][string]$Col, 3427 | [parameter(ParameterSetName="Address",Mandatory=$true)][string]$Address, 3428 | [parameter(Mandatory=$true, ValueFromPipeline=$true)][OfficeOpenXml.ExcelWorksheet]$WorkSheet 3429 | ) 3430 | if($Address){ 3431 | $range = Convert-OOXMLFromExcelCoordinates($Address) 3432 | $Row = $range["TopRow"] 3433 | $col = $range["LeftCol"] 3434 | } 3435 | $retVal = $WorkSheet.GetValue($Row,$Col) 3436 | 3437 | return $retVal 3438 | } 3439 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ExcelPSLib 2 | ExcelPSLib is a PowerShell Module that allows creation of XLSX file by using the EPPlus 4.1 .Net Dynamic Link Library available at http://epplus.codeplex.com/ and made by Jan Kallman. 3 | 4 | I've started this project because I wanted to improve and automate XLSX report creation and manipulation. 5 | There are known issues and limitations but in general it is fine to use it in production. 6 | 7 | Enjoy ! 8 | --------------------------------------------------------------------------------