summaryrefslogtreecommitdiffhomepage
path: root/examples/surrounding_borders_example.md
diff options
context:
space:
mode:
authorZsolt Kozaroczy <[email protected]>2020-09-11 00:36:29 +0200
committerGitHub <[email protected]>2020-09-11 00:36:29 +0200
commit282eec44ef01746ee25931fa6cd287ad083fd40b (patch)
tree14504bf429ca264812679ca971c1592853d3f762 /examples/surrounding_borders_example.md
parent317e8244e4d17c394c1e181f86df3974623fb865 (diff)
downloadcaxlsx-282eec44ef01746ee25931fa6cd287ad083fd40b.tar.gz
caxlsx-282eec44ef01746ee25931fa6cd287ad083fd40b.zip
Restructure examples folder (#47)
Split examples into separate markdown files, each containing a description, sample code, and a screenshot of the resulting xlsx document. The script `generate.rb` is provided to actually generate the example documents by executing the sample code contained in the markdown files.
Diffstat (limited to 'examples/surrounding_borders_example.md')
-rw-r--r--examples/surrounding_borders_example.md38
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/surrounding_borders_example.md b/examples/surrounding_borders_example.md
new file mode 100644
index 00000000..d3135768
--- /dev/null
+++ b/examples/surrounding_borders_example.md
@@ -0,0 +1,38 @@
+## Description
+
+More programmatic way to set the borders
+
+## Code
+
+```ruby
+require 'axlsx'
+
+p = Axlsx::Package.new
+wb = p.workbook
+s = wb.styles
+
+defaults = { style: :thick, color: '000000' }
+borders = Hash.new do |hash, key|
+ hash[key] = s.add_style border: defaults.merge({ edges: key.to_s.split('_').map(&:to_sym) })
+end
+
+top_row = [0, borders[:top_left], borders[:top], borders[:top], borders[:top_right]]
+middle_row = [0, borders[:left], 0, 0, borders[:right]]
+bottom_row = [0, borders[:bottom_left], borders[:bottom], borders[:bottom], borders[:bottom_right]]
+
+wb.add_worksheet(name: 'Surrounding Border') do |sheet|
+ sheet.add_row []
+ sheet.add_row ['', 1, 2, 3, 4], style: top_row
+ sheet.add_row ['', 5, 6, 7, 8], style: middle_row
+ sheet.add_row ['', 9, 10, 11, 12]
+
+ #This works too!
+ sheet.rows.last.style = bottom_row
+end
+
+p.serialize 'surrounding_borders_example.xlsx'
+```
+
+## Output
+
+![Output](images/surrounding_borders_example.png "Output")