summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKoza <[email protected]>2021-02-17 17:20:34 +0100
committerStefan Daschek <[email protected]>2021-03-19 00:51:28 +0100
commit0146438f571c9c36f77b525164d4b190a81b4981 (patch)
tree2515f038b3486a1949cbe003f6501f61c88a8f99
parent482421e72c3ec92e02628ccf70742e6bbb2dbed2 (diff)
downloadcaxlsx-0146438f571c9c36f77b525164d4b190a81b4981.tar.gz
caxlsx-0146438f571c9c36f77b525164d4b190a81b4981.zip
Add conditional formatting example for text equality
-rw-r--r--examples/README.md1
-rw-r--r--examples/conditional_formatting_text_equal_example.md37
-rw-r--r--examples/images/conditional_formatting_text_equal_example.pngbin0 -> 24727 bytes
3 files changed, 38 insertions, 0 deletions
diff --git a/examples/README.md b/examples/README.md
index 5b1abdc2..f1ab1d5b 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -34,6 +34,7 @@ Usage:
* [Color scale](conditional_formatting_color_scale_example.md)
* [Data bar](conditional_formatting_data_bar_example.md)
* [Icon set](conditional_formatting_icon_set_example.md)
+* [Text equal](conditional_formatting_text_equal_example.md)
### Charts
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
+
+![Output](images/conditional_formatting_text_equal_example.png "Output")
diff --git a/examples/images/conditional_formatting_text_equal_example.png b/examples/images/conditional_formatting_text_equal_example.png
new file mode 100644
index 00000000..60cfaf92
--- /dev/null
+++ b/examples/images/conditional_formatting_text_equal_example.png
Binary files differ