Issue when 'equal to' conditional formatting is used with strings
See original GitHub issueHi,
I am using XlsxWriter to write Excel files with conditional formatting. The problem I am encountering is that an equals sign is always appended to the value which gets inserted into the conditional formatting configuration in my Excel workbook. This causes text-based conditional formatting rules to not evaluate correctly. Numeric-based conditional formatting rules do not appear to be affected.
I am using Python version 3.6, XlsxWriter 0.9.9, and Excel 2016.
Here is some code that demonstrates the problem:
import xlsxwriter
workbook = xlsxwriter.Workbook('XLSX Writer Test.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'X')
format1 = workbook.add_format({'bg_color': '#FFC7CE',
'font_color': '#9C0006'})
worksheet.conditional_format('A1', {'type': 'cell',
'criteria': 'equal to',
'value': 'X',
'format': format1})
workbook.close()
After running the above code:
- Open the Excel file
- Select cell A1
- On the Home ribbon, click on Conditional Formatting
- Double-click on the conditional formatting rule
- Observe that the value (which was passed as ‘X’ in the code above) is recorded as ‘=X’, which causes the rule to not execute correctly
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Highlight cells containing string [Conditional formatting]
How to apply Conditional Formatting · Select cell range. · Go to tab "Home" on the ribbon if you are not already there....
Read more >Video: Conditionally format text - Microsoft Support
Click HOME > Conditional Formatting > Highlight Cells Rules > Text that Contains. In the Text that Contains box, on the left, enter...
Read more >Use conditional formatting to highlight information
On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Highlight Cells Rules. ... Select...
Read more >Excel Conditional Formatting tutorial with examples - Ablebits
End-to-end tutorial will teach you how to use Conditional Formatting in Excel: apply preset rules and create new ones, copy existing ...
Read more >How to Combine Conditional Formatting with an IF Statement
For example, if you want to apply conditional formatting using a condition that “If a cell value is greater than a set value,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi,
Thanks for the detailed report.
XlsxWriter doesn’t prepend a ‘=’. Excel does that in the interface.
The issue is that the sting
X
needs to be quoted as an Excel string"X"
, like this:After that the sample program should work as expected.
I’ll leave this open as an issue (maybe with a changed title) since the module should probably fix this silently in the background.
Thanks for the input.
John
Reverted due to #564