importexcel conditional formatting: How to apply color to entire row - powershell

I'm trying to color rows depending on the value of a cell.
eg: if A2 = 1, then color the entire row red ; if A3 = 10 then color entire row orange, etc.
So far I've only managed to get the cell containing the value I'm checking the value of, to have the color applied. ie if A2 =1 then A2 is red but not the entire A row.
This what I'm doing:
$Params = #{
WorkSheet = $xl.Workbook.Worksheets[1]
Range = "A2:A500"
BackgroundColor = "Red"
RuleType = 'Equal'
ConditionValue = "1"
}
Add-ConditionalFormatting #Params
I'm using importexcel
Any help & suggestions gratefully received!

Related

How to create pie chart in PowerShell with custom colors?

I have four values from results: Fail, Pass Crash and Progress.
I have two requirements where (1) I want to show fix colors with these four results (Ex: Red for fail, green = pass, yellow = progress and brown = Crash).
(2) The zero values should not show on pie chart. (Ex. if crash count is 0, do not show on chart).
$Cities is a Hashtable where values are fetched from Excel.
Name Value
Progress 0
Crashed 0
Failed 2
Passed 3
Here is my code:
the following is glued together from the article over at solarwinds and the info about palettes from a blog entry. It takes the values from $DataArray and creates a pie chart from it. the section chart colour palette creates a custom colour palette which must match data array order to fulfill the mapping requirement.
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Windows.Forms.DataVisualization
$DataArray = #{Progress=0; Crashed=0; Failed=2; Passed=3}
# create chart object
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart
$Chart.Width = 400
$Chart.Height = 400
$Chart.Left = 20
$Chart.Top = 20
# chart colour palette (must match data array order)
$chart.Palette = [System.Windows.Forms.DataVisualization.Charting.ChartColorPalette]::None
$Chart.PaletteCustomColors = #( [System.Drawing.Color]::Brown, [System.Drawing.Color]::Gold, [System.Drawing.Color]::Red, [System.Drawing.Color]::Green )
# create a chartarea to draw on and add to chart
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
$Chart.ChartAreas.Add($ChartArea)
# add data to chart
[void]$Chart.Series.Add("Data")
$Chart.Series["Data"].Points.DataBindXY($DataArray.Keys, $DataArray.Values)
$chart.Series["Data"].ChartType = "Pie"
$Chart.Series["Data"]["PieLabelStyle"] = "Outside"
$Chart.Series["Data"]["PieLineColor"] = "Black"
($Chart.Series["Data"].Points.FindMaxByValue())["Exploded"] = $true
$Chart.Series["Data"][?PieLabelStyle?] = ?Disabled?
# Legend
$Legend = New-Object System.Windows.Forms.DataVisualization.Charting.Legend
$Legend.IsEquallySpacedItems = $True
$Legend.BorderColor = 'Black'
$Chart.Legends.Add($Legend)
$chart.Series["Data"].LegendText = "#VALX (#VALY)"
# save chart to file
$Chart.SaveImage("c:\Temp\piechart.png", "PNG")

Access VBA to Change an Image in a Continuous Form

I am trying to create a receipt form where people will confirm if they've received the full quantity of an order. As part of this, I want the following to happen:
If they received the full quantity, a green check mark appears
If they received a partial quantity, an orange triangle appears
If they received no items, a red x appears
To accomplish this, I'm using a continuous form with 3 image files for each situation. I'm using the code below to change the image when the quantity is changed. The problem is, when the quantity is change on 1 line, the symbol changes for all lines. I'll post pictures as well.
Any thoughts on how I can fix this?
I'm open to other methods of accomplishing this idea too.
Private Sub FinalQTY_AfterUpdate()
If IsNull(Me.FinalQty) Then
MsgBox "You must enter a quantity for this item"
Me.FinalQty.SetFocus
Exit Sub
Else
LValue = Me.[FinalQty]
If IsNumeric(LValue) = 0 Then
Me.FinalQty = ""
MsgBox "Qty must be a numeric value"
Me.QTY.SetFocus
Exit Sub
End If
End If
Me.FinalTotalPrice = Me.FinalPrice * Me.FinalQty
If Me.FinalQty = 0 Then
Me.Yes.Visible = False
Me.Change.Visible = False
Me.No.Visible = True
End If
If Me.FinalQty < Me.QTY Then
Me.Yes.Visible = False
Me.Change.Visible = True
Me.No.Visible = False
End If
If Me.FinalQty = Me.QTY Then
Me.Yes.Visible = True
Me.Change.Visible = False
Me.No.Visible = False
End If
End Sub
This is before I adjust the quantity:
This is after I adjust the qty of only the second line:
Since the formatting of each record displayed by a continuous form is inherited from the form design template, any changes to the template will be automatically applied to all records displayed by the form, aside from Conditional Formatting rules in effect or the handful of properties which may changed via the OnPaint event of the Detail section.
One possible alternative might be to add a new field to your table with a data type of OLE Object and populate the value on the AfterUpdate event using the AppendChunk method, sourcing image data from a separate table containing three records corresponding to your green tick, orange triangle, and red cross images.

Changing value in if statement

I'm trying to iterate through a column in numbers and change the background color of a cell, if the cell has a certain background color.
repeat with i from 11 to the count of cells by 6
if background color of cell i is {17990, 47031, 42919} then
set background color of cell i to {65535, 0, 0}
end if
end repeat
unfortunately, this does not do anything. The script just stops without Error. Help please!
There seems to be a bug in Numbers app where is not reporting the colors correctly. I set the background colors of columns A and B to your chosen value {17990, 47031, 42919}, but when I asked the script to return the colors, it returned the value {17990, 47030, 42919}. Because of this, I had the script check for both values and to act accordingly.
I added a dialog pop-up giving you the option to choose which column to change the cell colors.
tell application "Numbers"
set ifColor to {17990, 47031, 42919}
set ifColor2 to {17990, 47030, 42919}
set changeToColor to {65535, 0, 0}
tell its document 1
set theColumns to name of columns of table "Table 1" of active sheet
set chosenColumn to item 1 of (choose from list theColumns with title "Choose The Column" with prompt "Choose The Column")
set cellCount to count of cells of column chosenColumn of table "Table 1" of active sheet
repeat with i from 11 to cellCount by 6
set thisCell to cell ((chosenColumn & i) as string) of table "Table 1" of active sheet
if background color of thisCell is ifColor or background color of thisCell is ifColor2 then
set background color of thisCell to changeToColor
end if
end repeat
end tell
end tell
Here's the table I started with, having coloured the background of one cell magenta, i.e. {65535,0,65535}.
Then I ran this code:
use NumbersApp : application "Numbers"
property document : a reference to document 1 of NumbersApp
property sheet : a reference to active sheet of my document
property table : a reference to table 1 of my sheet
repeat with c in (a reference to every cell of my table)
if c's background color = missing value then ¬
set c's background color to {65535, 65535, 0}
if c's background color = {65535, 0, 65535} then ¬
set c's background color to {65535, 65535, 65535}
end repeat
I was expecting the majority of cells to turn yellow, and my magenta cell to turn white:
Hm...
My magenta cell is still looking far too magenta. So I decided to check just how magenta it really is:
return the background color of cell "C7" of my table
--> {64587, 609, 65480}
Well, that's not what I set it to, but it's pretty magenta, though I now see why it didn't turn white.
Next I decided to check the background colour of one of the yellow cells, that you have just seen me programmatically turn to a very specific kind of yellow:
return the background color of cell "D10" in my table
--> {65534, 65531, 2689}
Again, it is yellow, but not the yellow I told it to be.
Finally, I used the colour value just returned to try and target those cells and turn them black:
set the background color of every cell in my table ¬
whose background color is {65534, 65531, 2689} ¬
to {0, 0, 0}
Zilch. They are still very sunnily yellow.
Conclusion
Bug in AppleScript. I've submitted a bug report to Apple. I suggest you do the same.
#wch1zpink: {17990, 47031, 42919} --> {17990, 47030, 42919}
Looks like a rounding error introduced when converting integers to floating point numbers and back again. (AppleScript dates from the days of QuickDraw, which represented RGB values as UInt16, whereas Numbers is a Cocoa app, and Cocoa's NSColor uses CGFloat.) That's unavoidable, being a fundamental limitation of how CPUs do math (e.g. 0.7 * 0.7 = 0.49 --> false!).
The solution is to check the numbers are equal within an acceptable margin of error:
on areRealsEqual(n1, n2, toleranceMargin)
return n1 > n2 - toleranceMargin and n1 < n2 + toleranceMargin
end areRealsEqual
on areColorsEqual(c1, c2)
repeat with i from 1 to length of c1
if not areRealsEqual(item i of c1, item i of c2, 5) then return false
end repeat
return true
end areColorsEqual
set expectedColor to {17990, 47031, 42919}
set foundColor to {17990, 47030, 42919}
areColorsEqual(expectedColor, foundColor)
--> true

How to change text color of a field in crystal report

I have a crystal report field with name 'Comp' which will contain the text 'correct' or 'not correct' according to some formula. what i want to achieve is, if text is correct i want to make it green color, otherwise red.
Got it after some search, here is the answer
if{Comp} = "correct" then crGreen else crRed
you can create formula in your program too:
FormulaFieldDefinitions definitions = MyReport.FormulaFields;
string formulaText = "IF " + MyReport.Database.Tables[1].Fields[1].Name
+ " = correct THEN crGreen else crRed";
definitions.Add("Test", formulaText);
MyReport.Sections[1].AddFieldObject(definitions[1], 0, 0);

Understanding a boolean expression

I am trying to set a rule using a boolean expression that when X is within a range (6.0 -8.0) then yellow, anything below is green and above red. Your help is greatly appreciated
You mean like this?
if(X<6) {
color=green;
}
else {
if(x<=8){
color=yellow;
}else{
color=red;
}
}
You can accomplish this with simple if statements (exact syntax will vary by language, of course):
if X < 6.0 then
color = green
else if X <= 8.0 then
color = yellow
else
color = red
end