workbook 0.4.14 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f6ea32e52658ea5e81c6b5f813819cb26e93feb
4
- data.tar.gz: 98eb9d696796975874734c0b2d11cb606e7e4412
3
+ metadata.gz: bc0e6be07c59fd70553ab1c6e7be1b47259d44fc
4
+ data.tar.gz: 2c38be86478a4e7af84cdcd2b44b9df3353d6fa1
5
5
  SHA512:
6
- metadata.gz: ff1c86015a4122be0a32981efe4a2857021173d8cb54c6691e4bbfb4e3bc1f8e515c8c7c1ef382aa098209cadb113b0b1d80a88704c52fd19168d6d4e4eef148
7
- data.tar.gz: e84103eb4921c7e2f41059fb232b5d5ba1c86a9fb4a84274a747f33af5331425cbe74aeca287d7d38a557882fc23b02d9520c2a5a2143ad9e5592e077db2e809
6
+ metadata.gz: 122ccd6febc910869615018a44e2e34323c5d870e417013b0a33777005c78e94afc0b174bea6c88b1ab9a5d53dc2e01ac6edf9927f4d2f2da673577bbc949a20
7
+ data.tar.gz: 58ab99448e24d2207c5412c67370dc10232d55a5a97eaf78f090c150db5d09eb39297d2c80e4daf95fad33412e54f2f1fe8b02f6e5a5a994164b5be749e8aa5f
data/.yardoc/checksums CHANGED
@@ -1,22 +1,38 @@
1
- lib/workbook.rb 32bc69df4e3b8ce2c9268de044456cac6a0bee40
2
- lib/workbook/row.rb 2ebac27abd51f4858c99c20eaaa51c146820edaf
3
- lib/workbook/cell.rb e9e8375f8ca39b2d48087d362a894ab41768ea77
4
- lib/workbook/book.rb 4975414f7982cf0cc30494e209886057c9d4c750
5
- lib/workbook/sheet.rb 6e4dd25a20aa38932a202bc108de9c4fe99a1d2b
6
- lib/workbook/table.rb f09a6978e9aeb990b66117906de83fc1c10d1f0c
7
- lib/workbook/format.rb 2c851e82a2c6b3b7c165d005824d9c0b6eadfa7c
8
- lib/workbook/version.rb 96df0e31463de68e584e54d3a568988045c08e32
9
- lib/workbook/template.rb 17d4443a02dab1e7373e0d4ee5d5bb598afbb2f2
10
- lib/workbook/nil_value.rb 6dd69760293023adf43fb0a8b6cef65f48b0662f
11
- lib/workbook/readers/csv_reader.rb b04c6dc423a30a87ae957a01229778543840654f
12
- lib/workbook/readers/xls_reader.rb a42b30bc31731c01c23367450306f849b7b36791
13
- lib/workbook/readers/ods_reader.rb 8094776c94e46dfb0fb1f293f3e8618692b61e59
14
- lib/workbook/writers/xls_writer.rb ca52cf9c5c11d1768a96ec33ca48b1f68a59b559
15
- lib/workbook/readers/txt_reader.rb d954decd6be2b2c7ab7ad60fe68398c428d077cd
16
- lib/workbook/readers/xls_shared.rb 67da0f89a3b387b6d575df42a3e49f8a53fae49d
17
- lib/workbook/readers/xlsx_reader.rb 562e664987a4936d9abf89ecb8098744fbb81cf3
1
+ lib/workbook.rb 6438570227f4d8db697a8f875c80e4c1334e99c7
2
+ lib/workbook/row.rb f10c777f11bcf7a03f76615f794ee5730991b097
3
+ lib/workbook/book.rb 0ce5e14b5fabe87cf92a2e09a30779edd5dc2248
4
+ lib/workbook/cell.rb cac1d4b1e42b44059b938ca8b0e521d8fdd002be
5
+ lib/workbook/sheet.rb 5e43246f9fec4db953d6053af8e5b8b16af8ca50
6
+ lib/workbook/table.rb 41cd6aded7748689e9de425e2afd5bc8635c0a5a
7
+ lib/workbook/format.rb 8e8f8c5bd0c9a44d03dd6f4bd787aeb19759688c
8
+ lib/workbook/column.rb 78a5da45e87afea1c489a4fb666e8d923179570b
9
+ lib/workbook/version.rb 020f173233dcaadd7a6f90753bcbc6ab5b8b25cc
10
+ lib/workbook/template.rb 714cf57b0ac43fc020f9bf123d11b5d870851deb
11
+ lib/workbook/types/nil.rb da39a3ee5e6b4b0d3255bfef95601890afd80709
12
+ lib/workbook/nil_value.rb e773e3b95466dc0ef907ea187e692a82f9752764
13
+ lib/workbook/types/date.rb 1f6cd471a88c6a03b02dda54bfa86e70c914d612
14
+ lib/workbook/types/time.rb b7a4c25a9236ff9bfea79334c8c7b126ad98177a
15
+ lib/workbook/types/true.rb da39a3ee5e6b4b0d3255bfef95601890afd80709
16
+ lib/workbook/types/false.rb da39a3ee5e6b4b0d3255bfef95601890afd80709
17
+ lib/workbook/types/string.rb 7d9138192f5b597027a1e6039d0e4d24732b32c5
18
+ lib/workbook/modules/cell.rb 336687a768edc50e5dcf056c775cd052b7257220
19
+ lib/workbook/generatetypes.rb ed30aeac0037757d9fd170962440b4c31ea35ba5
20
+ lib/workbook/types/numeric.rb cc3b3c332d3fd714aac2f61cd1b297461a177121
21
+ lib/workbook/modules/cache.rb 4f493b5da9725b1dba8b0d4c5e50f260cbe71846
22
+ lib/workbook/types/nil_class.rb bde80579120dda2ea26006ebd213a9f5806b34fe
23
+ lib/workbook/types/true_class.rb 58426c452b1146f9c7f466817c5a34c5d87bf8bf
24
+ lib/workbook/types/false_class.rb b462a69a094c0ad7a694de1c3ca8868486a10f24
25
+ lib/workbook/modules/diff_sort.rb 2d634c089d2dd98cca57a90e62fa6d8b5adf876d
26
+ lib/workbook/readers/xls_reader.rb 9993723162e63a372f44fbdffeadf779a7c99ec5
27
+ lib/workbook/readers/ods_reader.rb 15d6203b19c86dd735d46f7f2e98e3d1cbaaacfc
28
+ lib/workbook/readers/csv_reader.rb faa57ea04511f22d2e111f358aac9291dbe17acd
29
+ lib/workbook/writers/xls_writer.rb cca4a524506e04dfe23d60fb364e7878a8f5120f
30
+ lib/workbook/readers/txt_reader.rb 65a16f46aac4debcfe4aab45494de87d785f5ae2
31
+ lib/workbook/readers/xls_shared.rb 4cb1a5cc897a2578bb5ba02eaceccda01627dc34
18
32
  lib/workbook/modules/type_parser.rb a933dd8ba9566c13cd61999ada9ffb431c402444
19
- lib/workbook/writers/html_writer.rb 0671601948122a46e9ea7cd0888378256560f6f9
20
- lib/workbook/modules/table_diff_sort.rb cffe0ffc3cd71d79ea8fcd67fad363b63292c005
21
- lib/workbook/writers/csv_table_writer.rb 9ea2161c399c37a172b6a4a95dcaefc95ab47ece
22
- lib/workbook/modules/raw_objects_storage.rb 3b9a499c170f1e82a2750dbfa247b4a1c2eb0e20
33
+ lib/workbook/writers/html_writer.rb 44adc88d7faa0e09d3684d005473069149503d0e
34
+ lib/workbook/readers/xlsx_reader.rb 632564692d893df9968828380bcab15a0a90ea47
35
+ lib/workbook/writers/xlsx_writer.rb ea165031771b18e48c34863a48de05a667546d3a
36
+ lib/workbook/writers/csv_table_writer.rb 76018a0d9ed6140ee2a639edbc821c9754a8accc
37
+ lib/workbook/writers/json_table_writer.rb 5b3f503afd1a1a5dd410ba12f66ad66711621cb2
38
+ lib/workbook/modules/raw_objects_storage.rb edc0d117f776f1d05c81bdd0fe7c22bdee247596
data/.yardoc/object_types CHANGED
Binary file
Binary file
@@ -3,14 +3,26 @@ require 'workbook/modules/raw_objects_storage'
3
3
 
4
4
  module Workbook
5
5
  # Format is an object used for maintinaing a cell's formatting. It can belong to many cells. It maintains a relation to the raw template's equivalent, to preserve attributes Workbook cannot modify/access.
6
+ # The keys in the Hash are intended to closely mimick the CSS-style options:
7
+ #
8
+ # {
9
+ # background_color: '#ff000',
10
+ # color: '#ffff00',
11
+ # font_weight: :bold,
12
+ # text_decoration: :underline,
13
+ # }
14
+ #
15
+ # Note that as we speak, not all exporters support all properties properly. Consider it WIP.
6
16
  class Format < Hash
7
17
  include Workbook::Modules::RawObjectsStorage
8
18
  alias_method :merge_hash, :merge
9
19
  alias_method :merge_hash!, :merge!
10
20
  attr_accessor :name, :parent
11
21
 
12
- # Initialize
13
- # @param [Workbook::Format, Hash] options (e.g. :background, :color
22
+ # Initializes Workbook::Format with a hash. The keys in the Hash are intended to closely mimick the CSS-style options (see above)
23
+ #
24
+ # @param [Workbook::Format, Hash] options (e.g. :background, :color, :background_color, :font_weight (integer or css-type labels)
25
+ # @return [String] the name of the format, default: nil
14
26
  def initialize options={}, name=nil
15
27
  options.each {|k,v| self[k]=v}
16
28
  self.name = name
@@ -102,7 +102,7 @@ module Workbook
102
102
 
103
103
  # Change the current format
104
104
  #
105
- # @param [Workbook::Format, Hash] f set the formatting properties of this Cell
105
+ # @param [Workbook::Format, Hash] f set the formatting properties of this Cell, see Workbook::Format#initialize
106
106
  def format= f
107
107
  if f.is_a? Workbook::Format
108
108
  @workbook_format = f
@@ -115,7 +115,7 @@ module Workbook
115
115
 
116
116
  # Returns current format
117
117
  #
118
- # @returns [Workbook::Format] the current format
118
+ # @return [Workbook::Format] the current format
119
119
  def format
120
120
  # return @workbook_format if @workbook_format
121
121
  if row and template and row.header? and !@workbook_format
@@ -211,8 +211,9 @@ module Workbook
211
211
  end
212
212
 
213
213
  # Compare
214
+ #
214
215
  # @param [Workbook::Cell] other cell to compare against (based on value), can compare different value-types using #compare_on_class
215
- # @returns [Fixnum] -1, 0, 1
216
+ # @return [Fixnum] -1, 0, 1
216
217
  def <=> other
217
218
  rv = nil
218
219
  begin
@@ -224,7 +225,6 @@ module Workbook
224
225
  rv = compare_on_class other
225
226
  end
226
227
  return rv
227
-
228
228
  end
229
229
 
230
230
  # Compare on class level
@@ -248,22 +248,32 @@ module Workbook
248
248
  return nil
249
249
  end
250
250
 
251
+ # Returns whether special formatting is present on this cell
252
+ #
253
+ # @return [Boolean] index of the cell
254
+ def format?
255
+ format and format.keys.count > 0
256
+ end
257
+
251
258
  # Returns the index of the cell within the row, returns nil if no row is present
252
259
  #
253
- # @returns [Integer, NilClass] index of the cell
260
+ # @return [Integer, NilClass] index of the cell
254
261
  def index
255
262
  row.index self if row
256
263
  end
257
264
 
258
265
  # Returns the key (a Symbol) of the cell, based on its table's header
259
266
  #
260
- # @returns [Symbol, NilClass] key of the cell, returns nil if the cell doesn't belong to a table
267
+ # @return [Symbol, NilClass] key of the cell, returns nil if the cell doesn't belong to a table
261
268
  def key
262
269
  table.header[index].to_sym if table
263
270
  end
264
271
 
265
272
  def inspect
266
- "<Workbook::Cell @value=#{value}>"
273
+ txt = "<Workbook::Cell @value=#{value}"
274
+ txt += " @format=#{format}" if format?
275
+ txt += ">"
276
+ txt
267
277
  end
268
278
 
269
279
  # convert value to string, and in case of a Date or Time value, apply formatting
@@ -28,7 +28,7 @@ module Workbook
28
28
  end
29
29
 
30
30
  # Lists the classes for which raws are available
31
- # @return Array<Object> array with the classes available
31
+ # @return [Array<Object>] array with the classes available
32
32
  def available_raws
33
33
  raws.keys
34
34
  end
@@ -4,7 +4,7 @@ module Workbook
4
4
  class NilValue
5
5
 
6
6
  # initialize this special nilvalue with a reason
7
- # @params [String] reason (currently only :covered, in case this cell is coverd because an adjecant cell spans over it)
7
+ # @param [String] reason (currently only :covered, in case this cell is coverd because an adjecant cell spans over it)
8
8
  def initialize reason
9
9
  self.reason= reason
10
10
  end
@@ -5,7 +5,7 @@ module Workbook
5
5
 
6
6
  # Converts standard (ruby/C++/unix/...) strftime formatting to MS's formatting
7
7
  #
8
- # @param [String, nil] numberformat (nil returns nil)
8
+ # @param [String, nil] ms_nr_format (nil returns nil)
9
9
  # @return [String, nil]
10
10
  def ms_formatting_to_strftime ms_nr_format
11
11
  if ms_nr_format
@@ -36,7 +36,7 @@ module Workbook
36
36
 
37
37
  # Returns the name of this sheet
38
38
  #
39
- # @return [String] the name, defaulting to "Sheet {index}" when none is set
39
+ # @return [String] the name, defaulting to sheet#index when none is set
40
40
  def name
41
41
  @name ||= "Sheet #{book.index(self)+1}"
42
42
  end
@@ -55,7 +55,7 @@ module Workbook
55
55
  # Set the header of this table (typically the first row, but can be a different row).
56
56
  # The header row is also used for finding values in a aribrary row.
57
57
  #
58
- # @param [Workbook::Row, Integer]
58
+ # @param [Workbook::Row, Integer] h should be the row or the index of this table's row
59
59
  # @return [Workbook::Row] The header
60
60
  def header= h
61
61
  if h.is_a? Numeric
@@ -65,8 +65,11 @@ module Workbook
65
65
  end
66
66
  end
67
67
 
68
- def header_row_index(h=nil)
69
- self.index(h ? h : self.header)
68
+ # Returns the index of the header row
69
+ #
70
+ # @return [Integer] The index of the header row (typically 0)
71
+ def header_row_index
72
+ self.index(self.header)
70
73
  end
71
74
 
72
75
  def define_columns_with_row(r)
@@ -76,6 +79,9 @@ module Workbook
76
79
  end
77
80
 
78
81
  # Generates a new row, with optionally predefined cell-values, that is already connected to this table.
82
+ #
83
+ # @param [Array, Workbook::Row] cell_values is an array or row of cell values
84
+ # @return [Workbook::Row] the newly created row
79
85
  def new_row cell_values=[]
80
86
  r = Workbook::Row.new(cell_values,self)
81
87
  return r
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Workbook
3
- VERSION = '0.4.14'
3
+ VERSION = '0.5'
4
4
  end
@@ -6,7 +6,6 @@ module Workbook
6
6
  module CsvTableWriter
7
7
  # Output the current workbook to CSV format
8
8
  #
9
- # @param [String] filename
10
9
  # @param [Hash] options (not used)
11
10
  # @return [String] csv (comma separated values in a string)
12
11
  def to_csv options={}
@@ -23,7 +22,7 @@ module Workbook
23
22
  end
24
23
  csv
25
24
  end
26
-
25
+
27
26
  # Write the current workbook to CSV format
28
27
  #
29
28
  # @param [String] filename
@@ -25,7 +25,10 @@ module Workbook
25
25
  xlsx_row.add_cell(c.value) unless xlsx_row_a[ci]
26
26
  xlsx_cell = xlsx_row_a[ci]
27
27
  xlsx_cell.value = c.value
28
- xlsx_cell.style = c.format.raws[Fixnum] if c.format.raws[Fixnum]
28
+ if c.format?
29
+ format_to_xlsx_format(c.format) unless c.format.raws[Fixnum]
30
+ xlsx_cell.style = c.format.raws[Fixnum]
31
+ end
29
32
  end
30
33
  xlsx_sheet.send(:update_column_info, xlsx_row.cells, [])
31
34
  end
@@ -86,25 +89,26 @@ module Workbook
86
89
  end
87
90
  end
88
91
 
92
+ def make_sure_f_is_a_workbook_format f
93
+ f.is_a?(Workbook::Format) ? f : Workbook::Format.new(f)
94
+ end
95
+
89
96
  def format_to_xlsx_format f
90
- xlsfmt = nil
91
- unless f.is_a? Workbook::Format
92
- f = Workbook::Format.new f
93
- end
97
+ f = make_sure_f_is_a_workbook_format f
94
98
 
95
99
  xlsfmt={}
96
- xlsfmt[:fg_color] = "#{f[:color]}00" if f[:color]
97
- xlsfmt[:b] = true if f[:font_weight] == "bold" or f[:font_weight].to_i >= 600 or f[:"font_style"].to_s.match "oblique"
98
- xlsfmt[:i] = true if f[:font_style] == "italic"
100
+ xlsfmt[:fg_color] = "FF#{f[:color].to_s.upcase}".gsub("#",'') if f[:color]
101
+ xlsfmt[:b] = true if f[:font_weight].to_s == "bold" or f[:font_weight].to_i >= 600 or f[:"font_style"].to_s.match "oblique"
102
+ xlsfmt[:i] = true if f[:font_style].to_s == "italic"
99
103
  xlsfmt[:u] = true if f[:text_decoration].to_s.match("underline")
100
104
  xlsfmt[:bg_color] = f[:background_color] if f[:background_color]
101
105
  xlsfmt[:format_code] = strftime_to_ms_format(f[:number_format]) if f[:number_format]
102
106
  xlsfmt[:font_name] = f[:font_family].split.first if f[:font_family]
103
107
  xlsfmt[:family] = parse_font_family(f) if f[:font_family]
104
- f.add_raw init_xlsx_spreadsheet_template.workbook.styles.add_style(xlsfmt)
105
- # wb.styles{|a| p a.add_style({}).class }
106
108
 
109
+ f.add_raw init_xlsx_spreadsheet_template.workbook.styles.add_style(xlsfmt)
107
110
  f.add_raw xlsfmt
111
+
108
112
  return xlsfmt
109
113
  end
110
114
  end
Binary file
@@ -29,5 +29,10 @@ module Readers
29
29
  assert_equal(nil,w.ms_formatting_to_strftime(nil));
30
30
  assert_equal(nil,w.ms_formatting_to_strftime(""));
31
31
  end
32
+ def test_open_integer_xlsx
33
+ w = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/integer_test.xlsx')
34
+
35
+ assert_equal("2",w.sheet.table[1][1].value.to_s)
36
+ end
32
37
  end
33
38
  end
@@ -94,7 +94,7 @@ module Writers
94
94
  b = Workbook::Book.new
95
95
  xlsx_format = b.format_to_xlsx_format(Workbook::Format.new({font_weight: "bold", color: "#FF0000"}))
96
96
  assert_equal(true,xlsx_format[:b])
97
- assert_equal("#FF000000",xlsx_format[:fg_color])
97
+ assert_equal("FFFF0000",xlsx_format[:fg_color])
98
98
  end
99
99
 
100
100
  def test_formats_to_xlsx_format
@@ -104,5 +104,14 @@ module Writers
104
104
  assert_equal(false,b.template.create_or_find_format_by(:header).raws[Fixnum].nil?)
105
105
  end
106
106
 
107
+ def test_format_to_xlsx_integrated
108
+ b = Workbook::Book.new [[:a,:b],[1,2],[3,4]]
109
+ c2 = b.sheet.table[2][1]
110
+ c2.format = Workbook::Format.new({font_weight: "bold", color: "#CC5500", font_style: :italic, text_decoration: :underline})
111
+ # Can't test this for real yet... :/ but the examples here seem to work b.write_to_xlsx("untitled document.xlsx")
112
+ # c = Workbook::Book.open("untitled document.xlsx")
113
+ # p c.inspect
114
+ end
115
+
107
116
  end
108
117
  end
data/workbook.gemspec CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency("rchardet", "~> 1.3")
22
22
  s.add_dependency("rake", '~> 10.0')
23
23
  s.add_dependency("json", '~> 1.8')
24
- s.add_dependency('roo', '~> 1.13')
25
- s.add_dependency('axlsx', '~> 2.0.1')
24
+ s.add_dependency('roo', '~> 2.3')
25
+ s.add_dependency('axlsx', '~> 2.1.0.pre')
26
26
  if RUBY_VERSION < "1.9"
27
27
  s.add_dependency('nokogiri', "~> 1.5.10")
28
28
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.14
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Brouwers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-09 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-prof
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.13'
103
+ version: '2.3'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.13'
110
+ version: '2.3'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: axlsx
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 2.0.1
117
+ version: 2.1.0.pre
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 2.0.1
124
+ version: 2.1.0.pre
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: nokogiri
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -212,6 +212,7 @@ files:
212
212
  - test/artifacts/excel_different_types.xlsx
213
213
  - test/artifacts/failing_import1.xls
214
214
  - test/artifacts/heavy.xlsx
215
+ - test/artifacts/integer_test.xlsx
215
216
  - test/artifacts/native_xlsx.xlsx
216
217
  - test/artifacts/sheet_with_combined_cells.ods
217
218
  - test/artifacts/sheetduplication.xls
@@ -268,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
269
  version: '0'
269
270
  requirements: []
270
271
  rubyforge_project: workbook
271
- rubygems_version: 2.4.5
272
+ rubygems_version: 2.5.1
272
273
  signing_key:
273
274
  specification_version: 4
274
275
  summary: Workbook is a datastructure to contain books of tables (an anlogy used in
@@ -289,6 +290,7 @@ test_files:
289
290
  - test/artifacts/excel_different_types.xlsx
290
291
  - test/artifacts/failing_import1.xls
291
292
  - test/artifacts/heavy.xlsx
293
+ - test/artifacts/integer_test.xlsx
292
294
  - test/artifacts/native_xlsx.xlsx
293
295
  - test/artifacts/sheet_with_combined_cells.ods
294
296
  - test/artifacts/sheetduplication.xls