mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Updates after proof reading help
This commit is contained in:
@@ -5,11 +5,12 @@
|
||||
.Description
|
||||
Conditional formatting allows Excel to:
|
||||
* Mark cells with icons depending on their value
|
||||
* Show a databar whose length indicates the value or a 2 or 3 color scale where the color indicates the relative value
|
||||
* Show a databar whose length indicates the value or a two or three color scale where the color indicates the relative value
|
||||
* Change the color, font, or number format of cells which meet given criteria
|
||||
Add-ConditionalFormatting allows these parameters to be set; for fine tuning of the rules the -PassThru switch,
|
||||
will return the rule so that you can modify things which are specific to that type of rule,
|
||||
for example the values which correspond to each icon in an Icon-Set.
|
||||
Add-ConditionalFormatting allows these parameters to be set; for fine tuning of
|
||||
the rules, the -PassThru switch will return the rule so that you can modify
|
||||
things which are specific to that type of rule, example, the values which
|
||||
correspond to each icon in an Icon-Set.
|
||||
.Example
|
||||
>
|
||||
$excel = $avdata | Export-Excel -Path (Join-path $FilePath "\Machines.XLSX" ) -WorksheetName "Server Anti-Virus" -AutoSize -FreezeTopRow -AutoFilter -PassThru
|
||||
@@ -19,31 +20,37 @@
|
||||
$excel.Workbook.Worksheets[1].Row(1).style.font.bold = $true
|
||||
$excel.Save() ; $excel.Dispose()
|
||||
|
||||
Here Export-Excel is called with the -PassThru parameter so the Excel Package object representing Machines.XLSX is stored in $Excel.
|
||||
The desired worksheet is selected and then columns" B" and "I" are conditionally formatted (excluding the top row) to show red text if
|
||||
they contain "2003" or "Disabled" respectively. A fixed date format is then applied to columns D..G, and the top row is formatted.
|
||||
Here Export-Excel is called with the -PassThru parameter so the ExcelPackage object
|
||||
representing Machines.XLSX is stored in $Excel.The desired worksheet is selected
|
||||
and then columns" B" and "I" are conditionally formatted (excluding the top row)
|
||||
to show red text if they contain "2003" or "Disabled" respectively.
|
||||
A fixed date format is then applied to columns D to G, and the top row is formatted.
|
||||
Finally the workbook is saved and the Excel package object is closed.
|
||||
.Example
|
||||
>
|
||||
$r = Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets[1] -Range "B1:B100" -ThreeIconsSet Flags -Passthru
|
||||
$r.Reverse = $true ; $r.Icon1.Type = "Num"; $r.Icon2.Type = "Num" ; $r.Icon2.value = 100 ; $r.Icon3.type = "Num" ;$r.Icon3.value = 1000
|
||||
|
||||
Again Export-Excel has been called with -Passthru leaving a package object in $Excel
|
||||
This time B1:B100 has been conditionally formatted with 3 icons, using the "Flags" Icon-Set.
|
||||
Add-ConditionalFormatting does not provide access to every option in the formatting rule, so passthru has been used and the
|
||||
rule is modified to apply the flags in reverse order, and transitions between flags are set to 100 and 1000
|
||||
Again Export-Excel has been called with -PassThru leaving a package object
|
||||
in $Excel. This time B1:B100 has been conditionally formatted with 3 icons,
|
||||
using the "Flags" Icon-Set. Add-ConditionalFormatting does not provide access
|
||||
to every option in the formatting rule, so -PassThru has been used and the
|
||||
rule is modified to apply the flags in reverse order, and transitions
|
||||
between flags are set to 100 and 1000.
|
||||
.Example
|
||||
Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red
|
||||
|
||||
This time $sheet holds an ExcelWorkseet object and databars are added to column D excluding the top row.
|
||||
This time $sheet holds an ExcelWorkshseet object and databars are added to
|
||||
column D, excluding the top row.
|
||||
.Example
|
||||
Add-ConditionalFormatting -Address $worksheet.cells["FinishPosition"] -RuleType Equal -ConditionValue 1 -ForeGroundColor Purple -Bold -Priority 1 -StopIfTrue
|
||||
Add-ConditionalFormatting -Address $worksheet.cells["FinishPosition"] -RuleType Equal -ConditionValue 1 -ForeGroundColor Purple -Bold -Priority 1 -StopIfTrue
|
||||
|
||||
In this example a named range is used to select the cells where the condition should apply,
|
||||
and instead of specifying a sheet and range within the sheet as separate paramters,
|
||||
the cells where the format should apply are specified directly.
|
||||
If a cell in the "FinishPosition" range is 1, then the text is turned to Bold & Purple.
|
||||
This rule is moved to first in the priority list, and where cells have a value of 1, no other rules will be processed.
|
||||
In this example a named range is used to select the cells where the condition
|
||||
should apply, and instead of specifying a sheet and range within the sheet as
|
||||
separate parameters, the cells where the format should apply are specified
|
||||
directly. If a cell in the "FinishPosition" range is 1, then the text is
|
||||
turned to Bold & Purple. This rule is moved to first in the priority list,
|
||||
and where cells have a value of 1, no other rules will be processed.
|
||||
.Example
|
||||
>
|
||||
$excel = Get-ChildItem | Select-Object -Property Name,Length,LastWriteTime,CreationTime | Export-Excel "$env:temp\test43.xlsx" -PassThru -AutoSize
|
||||
@@ -60,22 +67,30 @@
|
||||
|
||||
Close-ExcelPackage -Show $excel
|
||||
|
||||
The first few lines of code export a list of file and directory names, sizes and dates to a spreadsheet. It puts the date of the export in Cell F1.
|
||||
The first Conditional format changes the color of files and folders that begin with a ".", "_" or anything else which sorts before "A"
|
||||
The second Conditional format changes the Number format of numbers bigger than 1 million for example 1,234,567,890 will dispay as "1,234.57M"
|
||||
The third looks highlights datestamps of files less than a week old when the export was run.
|
||||
The = is necessary in the condition value to otherwise the rule will look for the the text INT($F$1-7).
|
||||
The cell address for the date is fixed using the standard Excel $ notation.
|
||||
The final Conditional format looks for files which have not changed since they were created. Here the condition value is "=C2". The = Sign means C2 is
|
||||
treated as a formula, not literal text. Unlike the file age, we want the cell used to change for each cell where the conditional format applies.
|
||||
The first cell in the conditional format range is D2, which is compared against C2, then D3 is compared against C3 and so on.
|
||||
A common mistake is to include the title row in the range and accidentally apply conditional formatting to it,
|
||||
or to begin the range at row 2 but use row 1 as the starting point for comparisons.
|
||||
The first few lines of code export a list of file and directory names, sizes
|
||||
and dates to a spreadsheet. It puts the date of the export in cell F1.
|
||||
The first Conditional format changes the color of files and folders that begin
|
||||
with a ".", "_" or anything else which sorts before "A".
|
||||
The second Conditional format changes the Number format of numbers bigger than
|
||||
1 million, for example 1,234,567,890 will dispay as "1,234.57M"
|
||||
The third highlights datestamps of files less than a week old when the export
|
||||
was run; the = is necessary in the condition value otherwise the rule will
|
||||
look for the the text INT($F$1-7), and the cell address for the date is fixed
|
||||
using the standard Excel $ notation.
|
||||
The final Conditional format looks for files which have not changed since they
|
||||
were created. Here the condition value is "=C2". The = sign means C2 is treated
|
||||
as a formula, not literal text. Unlike the file age, we want the cell used to
|
||||
change for each cell where the conditional format applies. The first cell in
|
||||
the conditional format range is D2, which is compared against C2, then D3 is
|
||||
compared against C3 and so on. A common mistake is to include the title row in
|
||||
the range and accidentally apply conditional formatting to it, or to begin the
|
||||
range at row 2 but use row 1 as the starting point for comparisons.
|
||||
.Example
|
||||
Add-ConditionalFormatting $ws.Cells["B:B"] GreaterThan 10000000 -Fore Red -Stop -Pri 1
|
||||
|
||||
This version shows the shortest syntax - the Address, Ruletype, and Conditionvalue can be identified from their position,
|
||||
and ForegroundColor, StopIfTrue and Priority can all be shortend.
|
||||
This version shows the shortest syntax - the Address, Ruletype, and
|
||||
Conditionvalue can be identified from their position, and ForegroundColor,
|
||||
StopIfTrue and Priority can all be shortend.
|
||||
|
||||
#>
|
||||
Param (
|
||||
@@ -84,15 +99,15 @@
|
||||
[Alias("Range")]
|
||||
$Address ,
|
||||
#The worksheet where the format is to be applied
|
||||
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
|
||||
[OfficeOpenX1ml.ExcelWorksheet]$WorkSheet ,
|
||||
#A standard named-rule - Top / Bottom / Less than / Greater than / Contains etc.
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule", Position = 1)]
|
||||
[OfficeOpenXml.ConditionalFormatting.eExcelConditionalFormattingRuleType]$RuleType ,
|
||||
#Text colour for matching objects
|
||||
#Text color for matching objects
|
||||
[Parameter(ParameterSetName = "NamedRule")]
|
||||
[Alias("ForegroundColour")]
|
||||
[System.Drawing.Color]$ForegroundColor,
|
||||
#Colour for databar type charts
|
||||
#Color for databar type charts
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "DataBar")]
|
||||
[Alias("DataBarColour")]
|
||||
[System.Drawing.Color]$DataBarColor,
|
||||
@@ -114,16 +129,16 @@
|
||||
#A value for the condition (for example 2000 if the test is 'lessthan 2000'; Formulas should begin with "=" )
|
||||
[Parameter(ParameterSetName = "NamedRule",Position = 2)]
|
||||
$ConditionValue,
|
||||
#A second value for the conditions like "between x and Y"
|
||||
#A second value for the conditions like "Between X and Y"
|
||||
[Parameter(ParameterSetName = "NamedRule",Position = 3)]
|
||||
$ConditionValue2,
|
||||
#Background colour for matching items
|
||||
#Background color for matching items
|
||||
[Parameter(ParameterSetName = "NamedRule")]
|
||||
[System.Drawing.Color]$BackgroundColor,
|
||||
#Background pattern for matching items
|
||||
[Parameter(ParameterSetName = "NamedRule")]
|
||||
[OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::None ,
|
||||
#Secondary colour when a background pattern requires it
|
||||
#Secondary color when a background pattern requires it
|
||||
[Parameter(ParameterSetName = "NamedRule")]
|
||||
[System.Drawing.Color]$PatternColor,
|
||||
#Sets the numeric format for matching items
|
||||
|
||||
Reference in New Issue
Block a user