spreadsheet_architect 3.3.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +71 -13
- data/README.md +64 -75
- data/lib/spreadsheet_architect/axlsx_string_width_patch.rb +23 -0
- data/lib/spreadsheet_architect/class_methods/csv.rb +2 -0
- data/lib/spreadsheet_architect/class_methods/ods.rb +1 -0
- data/lib/spreadsheet_architect/class_methods/xlsx.rb +56 -8
- data/lib/spreadsheet_architect/utils.rb +84 -25
- data/lib/spreadsheet_architect/utils/xlsx.rb +34 -37
- data/lib/spreadsheet_architect/version.rb +1 -1
- data/test/dummy_app/app/controllers/spreadsheets_controller.rb +5 -2
- data/test/dummy_app/config/application.rb +2 -5
- data/test/dummy_app/config/environments/test.rb +1 -1
- data/test/dummy_app/db/migrate/20170103234524_add_posts.rb +1 -1
- data/test/dummy_app/log/test.log +86427 -0
- data/test/test_helper.rb +15 -7
- data/test/unit/exceptions_test.rb +9 -1
- data/test/unit/kitchen_sink_test.rb +6 -5
- data/test/unit/options_test.rb +9 -0
- data/test/unit/utils_test.rb +43 -2
- data/test/unit/xlsx_freeze_test.rb +44 -0
- data/test/unit/xlsx_utils_test.rb +0 -21
- metadata +30 -15
- data/lib/spreadsheet_architect/monkey_patches/axlsx_column_width.rb +0 -56
- data/test/custom_assertions.rb +0 -21
- data/test/unit/regressions_test.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f453f3bd541db38744f93c7803a473dea7f8dee0c9c45ab86523992c78bd6317
|
4
|
+
data.tar.gz: 5c92d3ac4e35db0c17bd4da1e4325d08700decf476546fde20a66aa6057dacdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e89d0f1f1968275084495fdd420af039b61d7033606be0d9b63428fc3aab944baf82377103057fbf1ec43c91c02a7c48210bd81617ba55893ef998c3848265c0
|
7
|
+
data.tar.gz: ddfdcd2c578a1aa10dd2839368cdf99b897a49abf1a888bae40dbd08ad310f4ee26a5bc93ce9fdd484092b5f32ee4d5195c7cb5bdb466fcdf5dec6250e79603e
|
data/CHANGELOG.md
CHANGED
@@ -1,29 +1,59 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
---------
|
3
3
|
|
4
|
-
- **Unreleased**
|
5
|
-
- Nothing
|
6
|
-
|
4
|
+
- **Unreleased** - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v4.2.0...master)
|
5
|
+
- Nothing yet
|
6
|
+
|
7
|
+
- **4.2.0** - May 27, 2021 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v4.1.0...v4.2.0)
|
8
|
+
- Add option `:skip_defaults` which removes the defaults and default styles. Particularily useful for heavily customized spreadsheets where the default styles get in the way.
|
9
|
+
- Fix bug where styles werent being un-applied when using the `false` value.
|
10
|
+
- Add style aliases for `:valign` and `:wrap_text`
|
11
|
+
- Fix error with `headers: false`, previously had to use `headers: []`
|
12
|
+
|
13
|
+
- **4.1.0** - Nov 20, 2020 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v4.0.1...v4.1.0)
|
14
|
+
- Raise ArgumentError when invalid option names are given
|
15
|
+
|
16
|
+
- **4.0.1** - Nov 20, 2020 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v4.0.0...v4.0.1)
|
17
|
+
- Fix bug with `headers: false` where a blank header row is still added
|
18
|
+
- Fix Bug for older version of `caxlsx` v2.0.2
|
19
|
+
|
20
|
+
- **4.0.0** - Mar 3, 2020 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v3.3.1...v4.0.0)
|
21
|
+
- Switch to the `caxlsx` gem (Community Axlsx) from the legacy unmaintained `axlsx` gem. Axlsx has had a long history of being poorly maintained so this community gem improves the situation.
|
22
|
+
- Require Ruby 2.3+
|
23
|
+
- Ensure all options using Hash are automatically converted to symbol only hashes
|
24
|
+
- Add XLSX option `:freeze` to freeze custom sections of your spreadsheet
|
25
|
+
- Add XLSX option `:freeze_headers` to freeze the headers of your spreadsheet
|
26
|
+
- Remove old Axlsx patch for column width
|
27
|
+
- Backport new code for `string_width` calculations to Axlsx 3.0.1 and below.
|
28
|
+
|
29
|
+
- **3.3.1** - Dec 2, 2019 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v3.3.0...v3.3.1)
|
30
|
+
- [Issue #30](https://github.com/westonganger/spreadsheet_architect/issues/30) - Fix duplicate constant warning for XLSX_COLUMN_TYPES
|
31
|
+
|
32
|
+
- **3.3.0** - Nov 28, 2019 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v3.2.1...v3.3.0)
|
7
33
|
- Fix `:borders` option, was broken in v3.2.1
|
8
34
|
- Fix bug when passing `false` to `:headers` option
|
9
35
|
- Raise error when unsupported column type is passed
|
10
36
|
- Remove claimed support for `:currency` and `:percent` for ODS spreadsheets as they were not working. PR Wanted.
|
11
|
-
|
37
|
+
|
38
|
+
- **3.2.1** - April 10, 2019 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v3.2.0...v3.2.1)
|
12
39
|
- Fix bug when using `column_style` option with `include_header: true` & letter based column numbering
|
13
|
-
|
40
|
+
|
41
|
+
- **3.2.0** - September 14, 2018 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v3.1.0...v3.2.0)
|
14
42
|
- Change implementation of `:column_styles` option to utilize `axlsx_styler` instead of the built-in axlsx `col_style` method. The reason for the switch is that `col_style` would overwrite all previously set styles. `axlsx_styler` already has the ability to add onto existing styles and is what is currently utilized by `range_styles`.
|
15
43
|
- Date / Time formatting is now set per cell instead of on the entire column.
|
16
44
|
- Default Date formatting for `xlsx` changed from `m/d/yyyy` to `yyyy-mm-dd`
|
17
45
|
- Default Time/DateTime formatting for `xlsx` changed from `yyyy/m/d h:mm AM/PM` to `yyyy-mm-dd h:mm AM/PM`
|
18
46
|
- Fix bug where the ActionController::Renderer `:filename` option was ignored when an AR::Relation passed directly to the renderer without first calling `to_#{format}`
|
19
|
-
|
47
|
+
|
48
|
+
- **3.1.0** - August 19, 2018 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v3.0.0...v3.1.0)
|
20
49
|
- Add new option `:conditional_row_styles` to `to_xlsx`.
|
21
50
|
- Add ability to pass an alternative method name as a Symbol/String to the `:spreadsheet_columns` option.
|
22
51
|
- Replace all usage of the legacy method `instance_eval` with the proper method `send`.
|
23
52
|
- [#23](https://github.com/westonganger/spreadsheet_architect/issues/23#issuecomment-412803761) - Fix bug where custom `columns_widths` in xlsx spreadsheets might not get set correctly.
|
24
53
|
- All exceptions now inherit from the appropriate ruby core exception classes
|
25
54
|
- `SpreadsheetArchitect::Exceptions::InvalidOptionError` renamed to `SpreadsheetArchitect::Exceptions::OptionTypeError`
|
26
|
-
|
55
|
+
|
56
|
+
- **3.0.0** - July 6, 2018 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v2.1.2...v3.0.0)
|
27
57
|
- [#16](https://github.com/westonganger/spreadsheet_architect/issues/16) - Add ability to pass :instances option to SpreadsheetArchitect class methods
|
28
58
|
- [#16](https://github.com/westonganger/spreadsheet_architect/issues/16) - Remove Plain Ruby syntax `Post.to_xlsx(instances: posts_array)` in favor of `SpreadsheetArchitect.to_xlsx(instance: posts_array)`. However, it may still work at this time if configured correctly.
|
29
59
|
- Fix project-wide and model-level defaults before only `header_style`, `row_style`, & `sheet_name` were being utilized.
|
@@ -38,12 +68,15 @@ CHANGELOG
|
|
38
68
|
- Remove all Rails generators `spreadsheet_architect:add_default_options`. No need since its just as easy to copy from the README
|
39
69
|
- Major overhaul of test suite, add a ton more tests, for DRYness use resursion for tests when appropriate
|
40
70
|
- Use appraisal to test various `axlsx` versions
|
41
|
-
|
71
|
+
|
72
|
+
- **2.1.2** - July 6, 2018 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v2.1.1...v2.1.2)
|
42
73
|
- Fix bug where everything was underlined by default in Excel (LibreOffice was working correctly). For some reason, `false` in `:u` or `:underline` was incorrectly being treated as `true` but only within Excel. Now anytime `false` is encountered for either `:u` or `:underline` it is now converted to `nil`
|
43
74
|
- Fix bug where empty xlsx spreadsheets were corrupt when trying to open with Excel (LibreOffice was working correctly). This only occured when containing no headers and empty `:data` option which resulted in a package with no sheets.
|
44
|
-
|
75
|
+
|
76
|
+
- **2.1.1** - July 4, 2018 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v2.1.0...v2.1.1)
|
45
77
|
- [#18](https://github.com/westonganger/spreadsheet_architect/pull/18) - Fix controller bug when using an non-ActiveRecord ORM only within Rails
|
46
|
-
|
78
|
+
|
79
|
+
- **2.1.0** - June 20, 2018 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v2.0.2...v2.1.0)
|
47
80
|
- [#15](https://github.com/westonganger/spreadsheet_architect/pull/15) - Improved the method symbolize_keys. This method did not work properly for nested objects.
|
48
81
|
- [PR #15](https://github.com/westonganger/spreadsheet_architect/pull/15) - Added the ability to pass `:text_wrap` option within the `:alignment` style
|
49
82
|
- Make axlsx styles higher precendence over Spreadsheet Architect style aliases
|
@@ -51,14 +84,17 @@ CHANGELOG
|
|
51
84
|
- Due to [RODF bug](https://github.com/thiagoarrais/rodf/issues/19) convert all Date and Time cells to String in ODS spreadsheets
|
52
85
|
- Improve test suite
|
53
86
|
- Dont test against Ruby versions that Rails no longer supports. Gem code should remain compatible with Ruby 1.9.3.
|
54
|
-
|
87
|
+
|
88
|
+
- **2.0.2** - July 14 2017 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v2.0.1...v2.0.2)
|
55
89
|
- Fix bug with range styles rows option not counting headers
|
56
90
|
- Fix bug with range styles rows :all option
|
57
|
-
|
91
|
+
|
92
|
+
- **2.0.1** - February 16 2017 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v2.0.0...v2.0.1)
|
58
93
|
- Fix bug where `SpreadsheetArchitect.default_options` and `SPREADSHEET_OPTIONS` were being overwritten
|
59
94
|
- Fix bug where col_styles ignored previous styles on header when using `include_header` option
|
60
95
|
- Errors now try to provide which value is the cause
|
61
|
-
|
96
|
+
|
97
|
+
- **2.0.0** - January 28 2017 - [View Diff](https://github.com/westonganger/spreadsheet_architect/compare/v1.4.8...v2.0.0)
|
62
98
|
- Add to xlsx: `merges`, `column_styles`, `range_styles`, `borders`, `column_widths` multi-row headers, date/time default format_code
|
63
99
|
- Add `column_types` option for xlsx and ods
|
64
100
|
- Add ability to make multi-sheet spreadsheets in XLSX & ODS
|
@@ -66,52 +102,74 @@ CHANGELOG
|
|
66
102
|
- Add Examples
|
67
103
|
- Add Axlsx Style Reference
|
68
104
|
- Refractor into smaller files
|
105
|
+
|
69
106
|
- **1.4.8** - December 6 2016
|
70
107
|
- Lock `rodf` gem to v0.3.7 for last v1 version of this gem
|
108
|
+
|
71
109
|
- **1.4.7** - November 7 2016
|
72
110
|
- Fix method arguments for `to_rodf_spreadsheet` method
|
111
|
+
|
73
112
|
- **1.4.6** - May 16 2016
|
74
113
|
- Fix hash syntax for support of ruby v2.1 and below
|
114
|
+
|
75
115
|
- **1.4.5** - May 4 2016
|
76
116
|
- Bug fixes
|
117
|
+
|
77
118
|
- **1.4.4** - May 3 2016
|
78
119
|
- Add Ability to add format_code to all numbers body rows
|
120
|
+
|
79
121
|
- **1.4.3** - May 3 2016
|
80
122
|
- Bug fixes
|
123
|
+
|
81
124
|
- **1.4.2** - May 3 2016
|
82
125
|
- Add to_axlsx_package, to_rodf_spreadsheet methods for the item to be further manipulated. Ex. axlsx_styler
|
126
|
+
|
83
127
|
- **1.4.1** - May 2 2016
|
84
128
|
- Add rails generator for project defaults initializer
|
129
|
+
|
85
130
|
- **1.4.0** - April 29 2016
|
86
131
|
- Add to_xlsx, to_ods, & to_csv to SpreadsheetArchitect model for direct calling by passing in cell data
|
132
|
+
|
87
133
|
- **1.3.0** - April 21 2016
|
88
134
|
- Add ability to create class/model and project option defaults
|
135
|
+
|
89
136
|
- **1.2.5** - March 25 2016
|
90
137
|
- Fix each_with_index bug
|
138
|
+
|
91
139
|
- **1.2.4** - March 24 2016
|
92
140
|
- Fix cell type logic for symbol methods
|
141
|
+
|
93
142
|
- **1.2.3** - March 20 2016
|
94
143
|
- Fix cell type logic
|
144
|
+
|
95
145
|
- **1.2.2** - March 19 2016
|
96
146
|
- Make cell type numeric if value is numeric
|
147
|
+
|
97
148
|
- **1.2.1** - March 13 2016
|
98
149
|
- Better error reporting
|
99
150
|
- Fix for Plain ruby models
|
151
|
+
|
100
152
|
- **1.2.0** - March 10 2016
|
101
153
|
- Fix Bug: first row data repeated for all records on custom values
|
154
|
+
|
102
155
|
- **1.1.0** - March 3 2016
|
103
156
|
- Breaking Change - Move spreadsheet_columns method from the class to the instance
|
104
157
|
- Fix Bug: remove default underline on cells
|
158
|
+
|
105
159
|
- **1.0.4** - March 1 2016
|
106
160
|
- Extract helper methods to seperate module
|
107
161
|
- Improve readme
|
162
|
+
|
108
163
|
- **1.0.3** - March 1 2016
|
109
164
|
- Fix/Improve renderers
|
110
165
|
- Fix header default background color
|
111
166
|
- Fix default columns
|
167
|
+
|
112
168
|
- **1.0.2** - February 26 2016
|
113
169
|
- Enhance Style options
|
170
|
+
|
114
171
|
- **1.0.1** - February 26 2016
|
115
172
|
- Fix bug in renderers
|
173
|
+
|
116
174
|
- **1.0.0** - February 26 2016
|
117
175
|
- Gem Initial Release
|
data/README.md
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
# Spreadsheet Architect
|
2
2
|
|
3
3
|
<a href="https://badge.fury.io/rb/spreadsheet_architect" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/spreadsheet_architect.svg" alt="Gem Version"></a>
|
4
|
-
<a href='https://
|
4
|
+
<a href='https://github.com/westonganger/spreadsheet_architect/actions' target='_blank'><img src="https://github.com/westonganger/spreadsheet_architect/workflows/Tests/badge.svg" style="max-width:100%;" height='21' style='border:0px;height:21px;' border='0' alt="CI Status"></a>
|
5
5
|
<a href='https://rubygems.org/gems/spreadsheet_architect' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://ruby-gem-downloads-badge.herokuapp.com/spreadsheet_architect?label=rubygems&type=total&total_label=downloads&color=brightgreen' border='0' alt='RubyGems Downloads' /></a>
|
6
|
-
<a href='https://ko-fi.com/A5071NK' target='_blank'><img height='22' style='border:0px;height:22px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /></a>
|
7
6
|
|
8
7
|
Spreadsheet Architect is a library that allows you to create XLSX, ODS, or CSV spreadsheets super easily from ActiveRecord relations, plain Ruby objects, or tabular data.
|
9
8
|
|
10
9
|
Key Features:
|
11
10
|
|
12
11
|
- Dead simple custom spreadsheets with custom data
|
13
|
-
- Data Sources: ActiveRecord relations, array of plain Ruby object instances
|
12
|
+
- Data Sources: Tabular Data from an Array, ActiveRecord relations, or array of plain Ruby object instances
|
14
13
|
- Easily style and customize spreadsheets
|
15
14
|
- Create multi sheet spreadsheets
|
16
15
|
- Setting Class/Model or Project specific defaults
|
@@ -22,10 +21,12 @@ Key Features:
|
|
22
21
|
gem 'spreadsheet_architect'
|
23
22
|
```
|
24
23
|
|
25
|
-
# General Usage
|
24
|
+
# General Usage
|
26
25
|
|
27
26
|
### Tabular (Array) Data
|
28
27
|
|
28
|
+
The simplest and preffered usage is to simply create the data array yourself.
|
29
|
+
|
29
30
|
```ruby
|
30
31
|
headers = ['Col 1','Col 2','Col 3']
|
31
32
|
data = [[1,2,3], [4,5,6], [7,8,9]]
|
@@ -34,50 +35,25 @@ SpreadsheetArchitect.to_ods(headers: headers, data: data)
|
|
34
35
|
SpreadsheetArchitect.to_csv(headers: headers, data: data)
|
35
36
|
```
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
posts = Post.order(name: :asc).where(published: true)
|
41
|
-
# OR
|
42
|
-
posts = 10.times.map{|i| Post.new(number: i)}
|
38
|
+
Using this style will allow you to utilize any custom performance optimizations during your data generation process. This will come in handy when the spreadsheets get large and things start to get slow. One of my favourites for Rails is [light_record](https://github.com/Paxa/light_record)
|
43
39
|
|
44
|
-
|
45
|
-
SpreadsheetArchitect.to_ods(instances: posts)
|
46
|
-
SpreadsheetArchitect.to_csv(instances: posts)
|
47
|
-
```
|
40
|
+
### Rails Relations or an Array of plain Ruby object instances
|
48
41
|
|
49
|
-
|
42
|
+
If you would like to add the methods `to_xlsx`, `to_ods`, `to_csv`, `to_axlsx_package`, `to_rodf_spreadsheet` to some class, you can simply include the SpreadsheetArchitect module to whichever classes you choose. For example:
|
50
43
|
|
51
44
|
```ruby
|
52
|
-
class
|
45
|
+
class Post < ApplicationRecord
|
53
46
|
include SpreadsheetArchitect
|
54
47
|
end
|
55
48
|
```
|
56
49
|
|
57
|
-
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
posts = Post.order(name: :asc).where(published: true)
|
61
|
-
posts.to_xlsx
|
62
|
-
posts.to_ods
|
63
|
-
posts.to_csv
|
64
|
-
|
65
|
-
# Plain Ruby Objects
|
66
|
-
posts_array = 10.times.map{|i| Post.new(number: i)}
|
67
|
-
Post.to_xlsx(instances: posts_array)
|
68
|
-
Post.to_ods(instances: posts_array)
|
69
|
-
Post.to_csv(instances: posts_array)
|
70
|
-
```
|
71
|
-
|
72
|
-
# Usage with Instances / ActiveRecord Relations
|
73
|
-
|
74
|
-
When NOT using the `:data` option, ie. on an AR Relation or using the `:instances` option, Spreadsheet Architect requires an instance method defined on the class to generate the data. It looks for the `spreadsheet_columns` method on the class. If you are using on an ActiveRecord model and that method is not defined, it would fallback to the models `column_names` method (not recommended). If using the `:data` option this is ignored.
|
50
|
+
When using on an AR Relation or using the `:instances` option, SpreadsheetArchitect requires an instance method to be defined on the class to generate the data. By default it looks for the `spreadsheet_columns` method on the class. If you are using on an ActiveRecord model and that method is not defined, it would fallback to the models `column_names` method. If using the `:data` option this is completely ignored.
|
75
51
|
|
76
52
|
```ruby
|
77
53
|
class Post
|
54
|
+
include SpreadsheetArchitect
|
78
55
|
|
79
56
|
def spreadsheet_columns
|
80
|
-
|
81
57
|
### Column format is: [Header, Cell Data / Method (if symbol) to Call on each Instance, (optional) Cell Type]
|
82
58
|
[
|
83
59
|
['Title', :title],
|
@@ -89,15 +65,30 @@ class Post
|
|
89
65
|
['Rating', :rating],
|
90
66
|
['Category/Tags', "#{category.name} - #{tags.collect(&:name).join(', ')}"]
|
91
67
|
]
|
68
|
+
end
|
69
|
+
|
92
70
|
end
|
71
|
+
```
|
72
|
+
|
73
|
+
Then use it on the class or ActiveRecord relations of the class
|
93
74
|
|
94
|
-
|
75
|
+
```ruby
|
76
|
+
posts = Post.order(name: :asc).where(published: true)
|
77
|
+
posts.to_xlsx
|
78
|
+
posts.to_ods
|
79
|
+
posts.to_csv
|
80
|
+
|
81
|
+
# Plain Ruby Objects
|
82
|
+
posts_array = 10.times.map{|i| Post.new(number: i)}
|
83
|
+
Post.to_xlsx(instances: posts_array)
|
84
|
+
Post.to_ods(instances: posts_array)
|
85
|
+
Post.to_csv(instances: posts_array)
|
95
86
|
```
|
96
87
|
|
97
|
-
If you want to use a different method name then `spreadsheet_columns` you can pass a method name
|
88
|
+
If you want to use a different method name then `spreadsheet_columns` you can pass a method name to the `:spreadsheet_columns` option.
|
98
89
|
|
99
90
|
```ruby
|
100
|
-
Post.to_xlsx(instances: posts, spreadsheet_columns: :
|
91
|
+
Post.to_xlsx(instances: posts, spreadsheet_columns: :my_special_method)
|
101
92
|
```
|
102
93
|
|
103
94
|
Alternatively, you can pass a Proc/lambda to the `spreadsheet_columns` option. For those purists that really dont want to define any extra `spreadsheet_columns` instance method on your model, this option can help you work with that methodology.
|
@@ -119,10 +110,19 @@ Post.to_xlsx(instances: posts, spreadsheet_columns: Proc.new{|instance|
|
|
119
110
|
|
120
111
|
# Sending & Saving Spreadsheets
|
121
112
|
|
122
|
-
### Method 1:
|
113
|
+
### Method 1: Save to a file manually
|
123
114
|
|
124
115
|
```ruby
|
116
|
+
file_data = SpreadsheetArchitect.to_xlsx(headers: headers, data: data)
|
125
117
|
|
118
|
+
File.open('path/to/file.xlsx', 'w+b') do |f|
|
119
|
+
f.write file_data
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
### Method 2: Send Data via Rails Controller
|
124
|
+
|
125
|
+
```ruby
|
126
126
|
class PostsController < ActionController::Base
|
127
127
|
respond_to :html, :xlsx, :ods, :csv
|
128
128
|
|
@@ -176,49 +176,32 @@ class PostsController < ActionController::Base
|
|
176
176
|
end
|
177
177
|
```
|
178
178
|
|
179
|
-
|
179
|
+
# Multi Sheet Spreadsheets
|
180
180
|
|
181
|
-
|
182
|
-
### Ex. with ActiveRecord relation
|
183
|
-
file_data = Post.order(published_at: :asc).to_xlsx
|
184
|
-
File.open('path/to/file.xlsx', 'w+b') do |f|
|
185
|
-
f.write file_data
|
186
|
-
end
|
181
|
+
### XLSX
|
187
182
|
|
188
|
-
file_data = Post.order(published_at: :asc).to_ods
|
189
|
-
File.open('path/to/file.ods', 'w+b') do |f|
|
190
|
-
f.write file_data
|
191
|
-
end
|
192
|
-
|
193
|
-
file_data = Post.order(published_at: :asc).to_csv
|
194
|
-
File.open('path/to/file.csv', 'w+b') do |f|
|
195
|
-
f.write file_data
|
196
|
-
end
|
197
|
-
```
|
198
|
-
|
199
|
-
# Multi Sheet XLSX Spreadsheets
|
200
183
|
```ruby
|
201
184
|
axlsx_package = SpreadsheetArchitect.to_axlsx_package({headers: headers, data: data})
|
202
|
-
axlsx_package = SpreadsheetArchitect.to_axlsx_package({headers: headers, data: data},
|
185
|
+
axlsx_package = SpreadsheetArchitect.to_axlsx_package({headers: headers, data: data}, axlsx_package)
|
203
186
|
|
204
|
-
File.open('path/to/
|
187
|
+
File.open('path/to/multi_sheet_file.xlsx', 'w+b') do |f|
|
205
188
|
f.write axlsx_package.to_stream.read
|
206
189
|
end
|
207
190
|
```
|
208
191
|
|
209
|
-
See this file for more details:
|
192
|
+
See this file for more details: [test/unit/multi_sheet_test.rb](./test/unit/multi_sheet_test.rb)
|
210
193
|
|
211
|
-
###
|
194
|
+
### ODS
|
212
195
|
```ruby
|
213
196
|
ods_spreadsheet = SpreadsheetArchitect.to_rodf_spreadsheet({headers: headers, data: data})
|
214
|
-
ods_spreadsheet = SpreadsheetArchitect.to_rodf_spreadsheet({headers: headers, data: data},
|
197
|
+
ods_spreadsheet = SpreadsheetArchitect.to_rodf_spreadsheet({headers: headers, data: data}, ods_spreadsheet)
|
215
198
|
|
216
|
-
File.open('path/to/
|
199
|
+
File.open('path/to/multi_sheet_file.ods', 'w+b') do |f|
|
217
200
|
f.write ods_spreadsheet
|
218
201
|
end
|
219
202
|
```
|
220
203
|
|
221
|
-
See this file for more details:
|
204
|
+
See this file for more details: [test/unit/multi_sheet_test.rb](./test/unit/multi_sheet_test.rb)
|
222
205
|
|
223
206
|
# Methods
|
224
207
|
|
@@ -231,15 +214,18 @@ See this file for more details: https://github.com/westonganger/spreadsheet_arch
|
|
231
214
|
|**spreadsheet_columns**<br>*Proc/Symbol/String*| Use this option to override or define the spreadsheet columns. Normally, if this option is not specified and are using the instances option/ActiveRecord relation, it uses the classes custom `spreadsheet_columns` method or any custom defaults defined.<br>If neither of those and is an ActiveRecord model, then it will falls back to the models `self.column_names` | Cannot be used with the `:data` option.<br><br>If a Proc value is passed it will be evaluated on the instance object.<br><br>If a Symbol or String value is passed then it will search the instance for a method name that matches and call it. |
|
232
215
|
|**headers**<br>*Array / 2D Array*| |Data for the header row cells. If using on a class/relation, this defaults to the ones provided via `spreadsheet_columns`. Pass `false` to skip the header row. |
|
233
216
|
|**sheet_name**<br>*String*|`Sheet1`||
|
234
|
-
|**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`|See all available style options [here](
|
235
|
-
|**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false, format_code: nil}`|Styles for non-header rows. See all available style options [here](
|
236
|
-
|**column_styles**<br>*Array*||[See this example for usage](
|
237
|
-
|**range_styles**<br>*Array*||[See this example for usage](
|
238
|
-
|**conditional_row_styles**<br>*Array*||[See this example for usage](
|
239
|
-
|**merges**<br>*Array*||Merge cells. [See this example for usage](
|
240
|
-
|**borders**<br>*Array*||[See this example for usage](
|
217
|
+
|**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`|See all available style options [here](./docs/axlsx_style_reference.md)|
|
218
|
+
|**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false, format_code: nil}`|Styles for non-header rows. See all available style options [here](./docs/axlsx_style_reference.md)|
|
219
|
+
|**column_styles**<br>*Array*||[See this example for usage](./test/unit/kitchen_sink_test.rb)|
|
220
|
+
|**range_styles**<br>*Array*||[See this example for usage](./test/unit/kitchen_sink_test.rb)|
|
221
|
+
|**conditional_row_styles**<br>*Array*||[See this example for usage](./test/unit/kitchen_sink_test.rb). The if/unless proc will called with the following args: `row_index`, `row_data`|
|
222
|
+
|**merges**<br>*Array*||Merge cells. [See this example for usage](./test/unit/kitchen_sink_test.rb). Warning merges cannot overlap eachother, if you attempt to do so Excel will claim your spreadsheet is corrupt and refuse to open your spreadsheet.|
|
223
|
+
|**borders**<br>*Array*||[See this example for usage](./test/unit/kitchen_sink_test.rb)|
|
241
224
|
|**column_types**<br>*Array*||Valid types for XLSX are :string, :integer, :float, :date, :time, :boolean, nil = auto determine.|
|
242
225
|
|**column_widths**<br>*Array*||Sometimes you may want explicit column widths. Use nil if you want a column to autofit again.|
|
226
|
+
|**freeze_headers**<br>*Boolean*||Make all header rows frozen/fixed so they do not scroll.|
|
227
|
+
|**freeze**<br>*Hash*|`{rows: (1..4), columns: :all}`|Make all specified rows and columns frozen/fixed so they do not scroll.|
|
228
|
+
|**skip_defaults**<br>*Boolean*|`false`|Removes defaults and default styles. Particularily useful for heavily customized spreadsheets where the default styles get in the way.|
|
243
229
|
|
244
230
|
## `to_axlsx_spreadsheet(options={}, axlsx_package_to_join=nil)`
|
245
231
|
Same options as `to_xlsx`
|
@@ -256,6 +242,7 @@ Same options as `to_xlsx`
|
|
256
242
|
|**header_style**<br>*Hash*|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_size: 10, bold: true}`|Note: Currently ODS only supports these options|
|
257
243
|
|**row_style**<br>*Hash*|`{background_color: nil, color: "000000", align: :left, font_size: 10, bold: false}`|Styles for non-header rows. Currently ODS only supports these options|
|
258
244
|
|**column_types**<br>*Array*||Valid types for ODS are :string, :float, :date, :time, :boolean, nil = auto determine. Due to [RODF Issue #19](https://github.com/thiagoarrais/rodf/issues/19), :date/:time will be converted to :string |
|
245
|
+
|**skip_defaults**<br>*Boolean*|`false`|Skip defaults and default styles. Particularily useful for heavily customized spreadsheets where the default styles get in the way.|
|
259
246
|
|
260
247
|
## `to_rodf_spreadsheet(options={}, spreadsheet_to_join=nil)`
|
261
248
|
Same options as `to_ods`
|
@@ -273,7 +260,9 @@ Same options as `to_ods`
|
|
273
260
|
# Change class-wide default method options
|
274
261
|
|
275
262
|
```ruby
|
276
|
-
class Post
|
263
|
+
class Post < ApplicationRecord
|
264
|
+
include SpreadsheetArchitect
|
265
|
+
|
277
266
|
def spreadsheet_columns
|
278
267
|
[:name, :content]
|
279
268
|
end
|
@@ -318,11 +307,11 @@ SpreadsheetArchitect.default_options = {
|
|
318
307
|
```
|
319
308
|
|
320
309
|
# Kitchen Sink Examples with Styling for XLSX and ODS
|
321
|
-
See this example:
|
310
|
+
See this example: [test/unit/kitchen_sink_test.rb](./test/unit/kitchen_sink_test.rb)
|
322
311
|
|
323
312
|
# Axlsx Style Reference
|
324
313
|
|
325
|
-
I have compiled a list of all available style options for axlsx here:
|
314
|
+
I have compiled a list of all available style options for axlsx here: [docs/axlsx_style_reference.md](./docs/axlsx_style_reference.md)
|
326
315
|
|
327
316
|
# Testing / Validating your Spreadsheets
|
328
317
|
|