axlsx_styler 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2536d38bb1cb2ea59a3c8c3b4271056e6ed61e4f
4
- data.tar.gz: 49dd2f0a2069ccc497167b2ceef045420236c2c2
3
+ metadata.gz: 741a7a700d2d37228f6002dcc7776f00d3c975ec
4
+ data.tar.gz: 049469dbe509df37e8c21c3702248ab5eabb467e
5
5
  SHA512:
6
- metadata.gz: 9f1ae20c49e60b41217a3c43e398685fa7de9d66b401e309fe5f69a6c938fd2c93df70028ae73949b3a685ea03ce46c80662c84387a227cebc2bf8df4c6f92a0
7
- data.tar.gz: 9f8ce7362c84f93d1c9c747d73cfbe9d5067b2934c39c58d7003bc3fbd3219e21f9ed2e05a0c50cc32fe1f8fcbcf78d0ca750feb972a4322c2591d75b7e43cb2
6
+ metadata.gz: e80a33c66d5f932b502b5ba69fb5a03ed764295a5798a98279acb9c001f66e53cd4b821568fe4dab69c442a3ae6986cad845a6b04841bd2844204da260403677
7
+ data.tar.gz: 4096057d99938214307c0b2a7f217b3a632cd84011dfec1065bdc62a3380568445116b4eebe2e5fcbeba15403e9cd2f95282d633f01f752235df9bdcfbd7b75e
data/.gitignore CHANGED
@@ -21,3 +21,4 @@ tmp
21
21
  *.a
22
22
  mkmf.log
23
23
  *.xlsx
24
+ *.xlsx#
data/README.md CHANGED
@@ -1,6 +1,151 @@
1
1
  # AxlsxStyler
2
2
 
3
- TODO: Write a gem description
3
+ [Axlsx](https://github.com/randym/axlsx) gem is an excellent tool to
4
+ build Excel spreadsheets. The sheets are
5
+ created row-by-row and styles are immediately added to each cell when a
6
+ row is created. This gem allows to follow an alternative route: fill out
7
+ a spreadsheet with data and apply styles later. Styles can be added
8
+ to individual cells as well as to ranges of cells. As a bonus, this gem
9
+ also simplifies drawing borders around groups of cells.
10
+
11
+ ## Usage
12
+
13
+ This gem extend `Array` class in a way that allows you to apply
14
+ styles to ranges of cells, e.g.
15
+
16
+ ```ruby
17
+ sheet["A1:D10"].add_style b: true
18
+ ```
19
+
20
+ The styles can be overlayed, so that later on you can add another style
21
+ to cells that already have styles, e.g.
22
+
23
+ ```ruby
24
+ sheet["A1:D1"].add_style bg_color: 'FF0000'
25
+ ```
26
+
27
+ You can also add borders to ranges of cells:
28
+
29
+ ```ruby
30
+ sheet["B2:D5"].add_border
31
+ sheet["B2:B5"].add_border [:right]
32
+ ```
33
+
34
+ When you are done with styling you just need to run
35
+
36
+ ```ruby
37
+ workbook.apply_styles
38
+ ```
39
+
40
+ Here's an example that compares styling a simple table with and without
41
+ AxlsxStyler. Suppose make our spreadsheet to look as follows:
42
+
43
+ ![alt text](./spreadsheet.png "Sample Spreadsheet")
44
+
45
+ ### With `AxlsxStyler`
46
+
47
+ Just follow the step outlined above:
48
+
49
+ ```ruby
50
+ require 'axlsx_styler'
51
+
52
+ axlsx = Axlsx::Package.new
53
+ workbook = axlsx.workbook
54
+
55
+ workbook.add_worksheet do |sheet|
56
+ sheet.add_row
57
+ sheet.add_row ["", "Product", "Category", "Price"]
58
+ sheet.add_row ["", "Butter", "Dairy", 4.99]
59
+ sheet.add_row ["", "Bread", "Baked Goods", 3.45]
60
+ sheet.add_row ["", "Broccoli", "Produce", 2.99]
61
+ sheet.column_widths 5, 20, 20, 20
62
+
63
+ # using AxlsxStyler DSL
64
+ sheet["B2:D2"].add_style b: true
65
+ sheet["B2:B5"].add_style b: true
66
+ sheet["B2:D2"].add_style bg_color: "95AFBA"
67
+ sheet["B3:D5"].add_style bg_color: "E2F89C"
68
+ sheet["D3:D5"].add_style alignment: { horizontal: :left }
69
+ sheet["B2:D5"].add_border
70
+ sheet["B3:D3"].add_border [:top]
71
+ end
72
+
73
+ workbook.apply_styles
74
+
75
+ axlsx.serialize "grocery.xlsx"
76
+ ```
77
+
78
+ ### With plain `Axlsx` gem
79
+
80
+ This example can be DRYied up, but it gives you a rough idea of what you
81
+ need to go through.
82
+
83
+ ```ruby
84
+ require 'axlsx'
85
+ axlsx = Axlsx::Package.new
86
+ wb = axlsx.workbook
87
+ border_color = '000000'
88
+ wb.add_worksheet do |sheet|
89
+ # top row
90
+ header_hash = { b: true, bg_color: '95AFBA' }
91
+ top_left_corner = wb.styles.add_style header_hash.merge({
92
+ border: { style: :thin, color: border_color, edges: [:top, :left, :bottom] }
93
+ })
94
+ top_edge = wb.styles.add_style header_hash.merge({
95
+ border: { style: :thin, color: border_color, edges: [:top, :bottom] }
96
+ })
97
+ top_right_corner = wb.styles.add_style header_hash.merge({
98
+ border: { style: :thin, color: border_color, edges: [:top, :right, :bottom] }
99
+ })
100
+ sheet.add_row
101
+ sheet.add_row(["", "Product", "Category", "Price"],
102
+ style: [ nil, top_left_corner, top_edge, top_right_corner ]
103
+ )
104
+
105
+ # middle rows
106
+ color_hash = { bg_color: 'E2F89C' }
107
+ left_edge = wb.styles.add_style color_hash.merge(
108
+ b: true,
109
+ border: {
110
+ style: :thin, color: border_color, edges: [:left]
111
+ }
112
+ )
113
+ inner = wb.styles.add_style color_hash
114
+ right_edge = wb.styles.add_style color_hash.merge(
115
+ alignment: { horizontal: :left },
116
+ border: {
117
+ style: :thin, color: border_color, edges: [:right]
118
+ }
119
+ )
120
+ sheet.add_row(
121
+ ["", "Butter", "Dairy", 4.99],
122
+ style: [nil, left_edge, inner, right_edge]
123
+ )
124
+ sheet.add_row(
125
+ ["", "Bread", "Baked Goods", 3.45],
126
+ style: [nil, left_edge, inner, right_edge]
127
+ )
128
+
129
+ # last row
130
+ bottom_left_corner = wb.styles.add_style color_hash.merge({
131
+ b: true,
132
+ border: { style: :thin, color: border_color, edges: [:left, :bottom] }
133
+ })
134
+ bottom_edge = wb.styles.add_style color_hash.merge({
135
+ border: { style: :thin, color: border_color, edges: [:bottom] }
136
+ })
137
+ bottom_right_corner = wb.styles.add_style color_hash.merge({
138
+ alignment: { horizontal: :left },
139
+ border: { style: :thin, color: border_color, edges: [:right, :bottom] }
140
+ })
141
+ sheet.add_row(["", "Broccoli", "Produce", 2.99],
142
+ style: [nil, bottom_left_corner, bottom_edge, bottom_right_corner]
143
+ )
144
+
145
+ sheet.column_widths 5, 20, 20, 20
146
+ end
147
+ axlsx.serialize "grocery.xlsx"
148
+ ```
4
149
 
5
150
  ## Installation
6
151
 
@@ -15,15 +160,3 @@ And then execute:
15
160
  Or install it yourself as:
16
161
 
17
162
  $ gem install axlsx_styler
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it ( https://github.com/[my-github-username]/axlsx_styler/fork )
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create a new Pull Request
@@ -9,13 +9,18 @@ workbook.add_worksheet do |sheet|
9
9
  sheet.add_row ["", "Butter", "Dairy", 4.99]
10
10
  sheet.add_row ["", "Bread", "Baked Goods", 3.45]
11
11
  sheet.add_row ["", "Broccoli", "Produce", 2.99]
12
+ sheet.column_widths 5, 20, 20, 20
12
13
 
13
- sheet["B2:D2"].add_style(b: true)
14
- sheet["B2:D5"].add_style(bg_color: "E2D3EB")
14
+ # using AxlsxStyler DSL
15
+ sheet["B2:D2"].add_style b: true
16
+ sheet["B2:B5"].add_style b: true
17
+ sheet["B2:D2"].add_style bg_color: "95AFBA"
18
+ sheet["B3:D5"].add_style bg_color: "E2F89C"
19
+ sheet["D3:D5"].add_style alignment: { horizontal: :left }
15
20
  sheet["B2:D5"].add_border
16
- sheet["B3:D3"].add_border([:top])
21
+ sheet["B3:D3"].add_border [:top]
17
22
  end
18
23
 
19
24
  workbook.apply_styles
20
25
 
21
- axlsx.serialize "grocery.xlsx"
26
+ axlsx.serialize "../grocery.xlsx"
@@ -4,6 +4,6 @@ require 'axlsx_styler/version'
4
4
  require 'axlsx_styler/array'
5
5
  require 'axlsx_styler/axlsx_extensions'
6
6
 
7
- Array.include AxlsxStyler::Array
8
- Axlsx::Workbook.include AxlsxStyler::Axlsx::Workbook
9
- Axlsx::Cell.include AxlsxStyler::Axlsx::Cell
7
+ Array.send :include, AxlsxStyler::Array
8
+ Axlsx::Workbook.send :include, AxlsxStyler::Axlsx::Workbook
9
+ Axlsx::Cell.send :include, AxlsxStyler::Axlsx::Cell
@@ -1,3 +1,3 @@
1
1
  module AxlsxStyler
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: axlsx_styler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sakovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-16 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: axlsx
@@ -99,11 +99,11 @@ files:
99
99
  - Rakefile
100
100
  - axlsx_styler.gemspec
101
101
  - examples/colors_and_borders.rb
102
- - examples/grocery.xlsx
103
102
  - lib/axlsx_styler.rb
104
103
  - lib/axlsx_styler/array.rb
105
104
  - lib/axlsx_styler/axlsx_extensions.rb
106
105
  - lib/axlsx_styler/version.rb
106
+ - spreadsheet.png
107
107
  - test/array_test.rb
108
108
  - test/cell_test.rb
109
109
  - test/test_helper.rb