spreadsheet_architect 1.4.1 → 1.4.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: b706fe5b3df6da7cfc18655f49969b0192621f17
4
- data.tar.gz: 293780f00057fa57874e20d05508454f14002502
3
+ metadata.gz: 43f9f29b01120f3411da214e7077dda8bb04c3ec
4
+ data.tar.gz: 53d0343559d21e70b02bd16eb7aefdd7bdea3bb4
5
5
  SHA512:
6
- metadata.gz: 47960159b14e086c77dcab8786cebd0e6b19b976aab59c04caef2535755fc5f62cb3cada580481db15ab3dfd70b2677da14186cc76937b47fe4cc2405fda13cf
7
- data.tar.gz: fbb2f328e8f3f47509f4e8e4f80c8da20fb249fe70bc70f33dd8a93dd825d650f619c7b6da58e8abd7d67aed8cccce0f439aa710a6c8aced80fb4566acabc961
6
+ metadata.gz: 2a54100454ba15e3de07052e102ae1847407f811c95c75297f0cd272247798db640f7654f948ff4e89a78d572eb0eaa1b97293f1c43a442cb853e1c4f76f5a95
7
+ data.tar.gz: 46ca8c7ffdb8f899eeba54241fb69d2c0c19f89743fa2861578a1b2f950ddac8fffd4610d61de31f5ec7cee11cc41e7aeac245b895df5275675303d7e3a3d795
@@ -1,6 +1,10 @@
1
1
  CHANGELOG
2
2
  ---------
3
3
 
4
+ - **May.3.2016**: 1.5.0
5
+ - Add to_axlsx_package, to_rodf_spreadsheet methods for the item to be further manipulated. Ex. axlsx_styler
6
+ - **May.2.2016**: 1.4.1
7
+ - Add rails generator for project defaults initializer
4
8
  - **April.29.2016**: 1.4.0
5
9
  - Add to_xlsx, to_ods, & to_csv to SpreadsheetArchitect model for direct calling by passing in cell data
6
10
  - **April.21.2016**: 1.3.0
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Spreadsheet Architect
2
- <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=VKY8YAWAS5XRQ&lc=CA&item_name=Weston%20Ganger&item_number=spreadsheet_architect&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest" target="_blank" title="Donate"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="Donate"/></a>
2
+ <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=VKY8YAWAS5XRQ&lc=CA&item_name=Weston%20Ganger&item_number=spreadsheet_architect&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest" target="_blank" title="Buy Me A Coffee"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="Buy Me A Coffee"/></a>
3
3
 
4
4
  Spreadsheet Architect is a library that allows you to create XLSX, ODS, or CSV spreadsheets easily from ActiveRecord relations, Plain Ruby classes, or predefined data.
5
5
 
@@ -12,7 +12,7 @@ Key Features:
12
12
  - Model/Class or Project specific defaults
13
13
  - Simple to use ActionController renderers
14
14
 
15
- Spreadsheet Architect adds the following methods to your class:
15
+ Spreadsheet Architect adds the following methods:
16
16
  ```ruby
17
17
  # Rails ActiveRecord Model
18
18
  Post.order(name: :asc).where(published: true).to_xlsx
@@ -30,6 +30,12 @@ data = [[1,2,3], [4,5,6], [7,8,9]]
30
30
  SpreadsheetArchitect.to_xlsx(data: data, headers: headers)
31
31
  SpreadsheetArchitect.to_ods(data: data, headers: headers)
32
32
  SpreadsheetArchitect.to_csv(data: data, header: false)
33
+
34
+ # These return a ruby object that can be further manipulated
35
+ # These methods may also be used on models/classes
36
+ SpreadsheetArchitect.to_axlsx('package', {data: data, headers: headers})
37
+ SpreadsheetArchitect.to_axlsx('sheet', {data: data, headers: headers})
38
+ SpreadsheetArchitect.to_rodf_spreadsheet(data: data, headers: headers)
33
39
  ```
34
40
 
35
41
  # Install
@@ -37,7 +43,6 @@ SpreadsheetArchitect.to_csv(data: data, header: false)
37
43
  gem install spreadsheet_architect
38
44
  ```
39
45
 
40
-
41
46
  # Class/Model Setup
42
47
 
43
48
  ### Model
@@ -162,7 +167,7 @@ end
162
167
  |**headers**|Boolean|`true`|Pass false to skip the header row.|
163
168
  |**sheet_name**|String|Class name||
164
169
  |**header_style**|Hash|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`||
165
- |**row_style**|Hash|`{background_color: nil, color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`|Styles for non-header rows.|
170
+ |**row_style**|Hash|`{background_color: nil, color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false, number_format_code: nil}`|Styles for non-header rows.|
166
171
 
167
172
  <br>
168
173
  #### `.to_ods` - (on custom class/model)
@@ -191,7 +196,7 @@ end
191
196
  |**headers**|Array|`false`|2D Array of data for the header rows cells. Pass false to skip the header row.|
192
197
  |**sheet_name**|String|`SpreadsheetArchitect`||
193
198
  |**header_style**|Hash|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`||
194
- |**row_style**|Hash|`{background_color: nil, color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`|Styles for non-header rows.|
199
+ |**row_style**|Hash|`{background_color: nil, color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false, number_format_code: nil}`|Styles for non-header rows.|
195
200
 
196
201
  <br>
197
202
  #### `SpreadsheetArchitect.to_ods`
@@ -211,7 +216,6 @@ end
211
216
  |**headers**|Array|`false`|2D Array of data for the header rows cells. Pass false to skip the header row.|
212
217
 
213
218
 
214
-
215
219
  # Change model default method options
216
220
  ```ruby
217
221
  class Post
@@ -244,6 +248,23 @@ SpreadsheetArchitect.module_eval do
244
248
  end
245
249
  ```
246
250
 
251
+ # Format all numbers, money, or currency in xlsx only
252
+
253
+ Unfortunately so far I have only been successful in applying the format_code to all numbers in the entire spreadsheet.
254
+
255
+ ```
256
+ # Ex. dollar sign, comma's, and minumum two decimal places
257
+ Product.to_xlsx(headers: headers, data: data, number_format_code: "$#,##0.00")
258
+ ```
259
+
260
+ # TODO
261
+
262
+ Would love for any help with new features for this projects. Some desired features are:
263
+
264
+ - More ODS style options
265
+ - Apply format codes to only certain columns (xlsx)
266
+ - Add Columns styles (xlsx & ods)
267
+ - Create multiple sheets (xlsx & ods)
247
268
 
248
269
  # Credits
249
270
  Created by Weston Ganger - @westonganger
@@ -251,4 +272,4 @@ Created by Weston Ganger - @westonganger
251
272
  Heavily influenced by the dead gem `acts_as_xlsx` by @randym but adapted to work for more spreadsheet types and plain ruby models.
252
273
 
253
274
 
254
- <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=VKY8YAWAS5XRQ&lc=CA&item_name=Weston%20Ganger&item_number=spreadsheet_architect&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest" target="_blank" title="Donate"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="Donate"/></a>
275
+ <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=VKY8YAWAS5XRQ&lc=CA&item_name=Weston%20Ganger&item_number=spreadsheet_architect&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest" target="_blank" title="Buy Me A Coffee"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="Buy Me A Coffee"/></a>
@@ -203,7 +203,7 @@ module SpreadsheetArchitect
203
203
  end
204
204
  end
205
205
 
206
- def to_ods(opts={})
206
+ def to_rodf_spreadsheet
207
207
  opts = SpreadsheetArchitect::Helpers.get_cell_data(opts, self)
208
208
  options = SpreadsheetArchitect::Helpers.get_options(opts, self)
209
209
 
@@ -259,10 +259,14 @@ module SpreadsheetArchitect
259
259
  end
260
260
  end
261
261
 
262
- return spreadsheet.bytes
262
+ return spreadsheet
263
+ end
264
+
265
+ def to_ods(opts={})
266
+ return to_rodf_spreadsheet(opts).bytes
263
267
  end
264
268
 
265
- def to_xlsx(opts={})
269
+ def to_axlsx(which='sheet', opts={})
266
270
  opts = SpreadsheetArchitect::Helpers.get_cell_data(opts, self)
267
271
  options = SpreadsheetArchitect::Helpers.get_options(opts, self)
268
272
 
@@ -304,18 +308,28 @@ module SpreadsheetArchitect
304
308
 
305
309
  return package if options[:data].empty?
306
310
 
307
- package.workbook.add_worksheet(name: options[:sheet_name]) do |sheet|
311
+ the_sheet = package.workbook.add_worksheet(name: options[:sheet_name]) do |sheet|
308
312
  if options[:headers]
309
313
  sheet.add_row options[:headers], style: package.workbook.styles.add_style(header_style)
310
314
  end
311
315
 
312
316
  options[:data].each do |row_data|
317
+ row_style.merge!(number_format_code) if opts[:row_style][:number_format_code]
313
318
  sheet.add_row row_data, style: package.workbook.styles.add_style(row_style), types: options[:types]
314
319
  end
315
320
  end
316
321
 
317
- return package.to_stream.read
322
+ if which.to_sym == :sheet
323
+ return the_sheet
324
+ else
325
+ return package
326
+ end
318
327
  end
328
+
329
+ def to_xlsx(opts={})
330
+ return to_axlsx('package', opts).to_stream.read
331
+ end
332
+
319
333
  end
320
334
 
321
335
  extend SpreadsheetArchitect::ClassMethods
@@ -1,3 +1,3 @@
1
1
  module SpreadsheetArchitect
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet_architect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-02 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: axlsx
@@ -153,6 +153,6 @@ signing_key:
153
153
  specification_version: 4
154
154
  summary: Spreadsheet Generator for ActiveRecord Models and Ruby Classes/Modules
155
155
  test_files:
156
- - test/database.yml
157
156
  - test/helper.rb
157
+ - test/database.yml
158
158
  - test/tc_spreadsheet_architect.rb