Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To utilize Powershell's export-excel Add-ConditionalFormatting function with RuleType ThreeColorScale, follow the steps below:

  1. Open Powershell and import the module "Import-Module ImportExcel".

  2. Create an object of the Excel Worksheet using the "New-ExcelWorksheet" cmdlet.

  3. Populate the worksheet with data by creating an array or importing data from a file.

  4. Use the "Add-ConditionalFormatting" function to apply conditional formatting to the worksheet.

  5. Set the "Type" parameter of the function to "ThreeColorScale".

  6. Set the "Minimum", "Middle", and "Maximum" parameters of the function to configure the color scale.

  7. Set the "Range" parameter of the function to specify the range of cells to apply the formatting to.

  8. Save the worksheet as an Excel file using the "Export-Excel" cmdlet.

Example:

$data = @(1,2,3,4,5,6,7,8,9) $worksheet = New-ExcelWorksheet -Name "Data" $worksheet.Cells["A1"].LoadFromCollection($data,$true) Add-ConditionalFormatting -Range ($worksheet.Cells["A1:A9"]) -Type ThreeColorScale -Minimum 1 -Middle 5 -Maximum 9 Export-Excel -Path "C:\Users\Example\Documents\Data.xlsx" -Worksheet $worksheet