diff options
| author | Oleg Yakovenko <[email protected]> | 2022-02-07 10:35:21 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-07 10:35:21 +0200 |
| commit | f957baf68aae6ec06e94b5b7b4b1d281ab295ab3 (patch) | |
| tree | 00cca6551838ca48dc297dd71338c14d8f8467b0 /examples/conditional_formatting_text_equal_example.md | |
| parent | af8fbd4d095589d31494b6f04ef07ca93de89650 (diff) | |
| parent | 196862524f94c58b1521ef84a6cf0397b411a685 (diff) | |
| download | caxlsx-f957baf68aae6ec06e94b5b7b4b1d281ab295ab3.tar.gz caxlsx-f957baf68aae6ec06e94b5b7b4b1d281ab295ab3.zip | |
Merge branch 'master' into feature/manageable-scatter-markers
Diffstat (limited to 'examples/conditional_formatting_text_equal_example.md')
| -rw-r--r-- | examples/conditional_formatting_text_equal_example.md | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/conditional_formatting_text_equal_example.md b/examples/conditional_formatting_text_equal_example.md new file mode 100644 index 00000000..0d7bd8d7 --- /dev/null +++ b/examples/conditional_formatting_text_equal_example.md @@ -0,0 +1,37 @@ +## Description + +Conditional format example: Text equal + +1. You must specify `:containsText` for both type and operator. +2. You must craft a formula to match what you are looking for. The formula needs to reference the top-left cell of the range (the cell reference will be dynamically adapted when the formula gets evaluated for the other cells in the range). +3. The formula may turn out to be vendor specific. You will want to test extensively if interoperability beyond excel is a concern. + +## Code + +```ruby +require 'axlsx' + +p = Axlsx::Package.new +wb = p.workbook + +s = wb.styles +profit = s.add_style bg_color: 'FF428751', type: :dxf + +wb.add_worksheet(name: 'Text Matching Conditional') do |sheet| + sheet.add_row ["Loss", "Loss", "Profit", "Loss", "Profit", "Loss", "Profit", "Loss", "Profit", "Profit"] + + # Highlight all the cells containing the text "Profit" + sheet.add_conditional_formatting('A1:J1', + type: :containsText, + operator: :containsText, + formula: 'NOT(ISERROR(SEARCH("Profit",A1)))', + dxfId: profit, + priority: 1) +end + +p.serialize 'conditional_formatting_text_equal_example.xlsx' +``` + +## Output + + |
