spreadsheet 0.6.1.5 → 0.6.1.6
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.
- data/History.txt +16 -1
- data/lib/spreadsheet.rb +1 -1
- data/lib/spreadsheet/column.rb +17 -0
- data/lib/spreadsheet/excel/reader.rb +6 -11
- data/lib/spreadsheet/excel/row.rb +1 -1
- data/lib/spreadsheet/excel/writer/worksheet.rb +10 -7
- data/lib/spreadsheet/worksheet.rb +3 -0
- data/test/integration.rb +19 -0
- data/test/worksheet.rb +12 -2
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,4 +1,19 @@
|
|
1
|
-
=== 0.6.1.
|
1
|
+
=== 0.6.1.6 / 2008-10-28
|
2
|
+
|
3
|
+
* 2 Bugfixes
|
4
|
+
|
5
|
+
* Fixed encoding and decoding of BigNums, negative and other large Numbers
|
6
|
+
http://rubyforge.org/tracker/index.php?func=detail&aid=22581&group_id=678&atid=2677
|
7
|
+
* Fix a bug where modifications to default columns weren't stored
|
8
|
+
http://rubyforge.org/forum/message.php?msg_id=61567
|
9
|
+
|
10
|
+
* 1 minor enhancement
|
11
|
+
|
12
|
+
* Row#enriched_data won't return a Bogus-Date if the data isn't a Numeric
|
13
|
+
value
|
14
|
+
(Thanks to Bjørn Hjelle for the report)
|
15
|
+
|
16
|
+
=== 0.6.1.5 / 2008-10-24
|
2
17
|
|
3
18
|
* 2 Bugfixes
|
4
19
|
|
data/lib/spreadsheet.rb
CHANGED
data/lib/spreadsheet/column.rb
CHANGED
@@ -17,12 +17,27 @@ module Spreadsheet
|
|
17
17
|
# #collapsed:: The Column is collapsed.
|
18
18
|
# #outline_level:: Outline level of the column.
|
19
19
|
class Column
|
20
|
+
class << self
|
21
|
+
def updater *keys
|
22
|
+
keys.each do |key|
|
23
|
+
unless instance_methods.include? "unupdated_#{key}="
|
24
|
+
alias_method :"unupdated_#{key}=", :"#{key}="
|
25
|
+
define_method "#{key}=" do |value|
|
26
|
+
send "unupdated_#{key}=", value
|
27
|
+
@worksheet.column_updated @idx, self if @worksheet
|
28
|
+
value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
20
34
|
include Datatypes
|
21
35
|
include Enumerable
|
22
36
|
attr_accessor :width, :worksheet
|
23
37
|
attr_reader :default_format, :idx
|
24
38
|
boolean :hidden, :collapsed
|
25
39
|
enum :outline_level, 0, Integer
|
40
|
+
updater :width, :hidden, :outline_level
|
26
41
|
def initialize idx, format, opts={}
|
27
42
|
@idx = idx
|
28
43
|
opts[:width] ||= 10
|
@@ -36,6 +51,8 @@ module Spreadsheet
|
|
36
51
|
def default_format= format
|
37
52
|
@worksheet.add_format format if @worksheet
|
38
53
|
@default_format = format
|
54
|
+
@worksheet.column_updated @idx, self if @worksheet
|
55
|
+
format
|
39
56
|
end
|
40
57
|
##
|
41
58
|
# Iterate over all cells in this column.
|
@@ -54,13 +54,12 @@ class Reader
|
|
54
54
|
integer &= 0xfffffffc
|
55
55
|
value, = ("\0\0\0\0" << [integer].pack('V')).unpack EIGHT_BYTE_DOUBLE
|
56
56
|
else
|
57
|
+
## I can't find a format for unpacking a little endian signed integer.
|
58
|
+
# 'V' works for packing, but not for unpacking. But the following works
|
59
|
+
# fine afaics:
|
60
|
+
unsigned, = (@bigendian ? work.reverse : work).unpack 'l'
|
57
61
|
## remove two bits
|
58
|
-
|
59
|
-
unsigned = unsigned >> 2
|
60
|
-
shifted = [unsigned].pack 'V'
|
61
|
-
## I can't find a format for unpacking a little endian signed integer
|
62
|
-
shifted.reverse! if @bigendian
|
63
|
-
value, = shifted.unpack 'l'
|
62
|
+
value = unsigned >> 2
|
64
63
|
end
|
65
64
|
if cent == 1
|
66
65
|
value /= 100.0
|
@@ -621,11 +620,7 @@ class Reader
|
|
621
620
|
# 2 2 Index to column
|
622
621
|
# 4 2 Index to XF record (➜ 6.115)
|
623
622
|
# 6 8 IEEE 754 floating-point value (64-bit double precision)
|
624
|
-
row, column, xf, value = work.unpack
|
625
|
-
unless value
|
626
|
-
# on architectures where sizeof(double) > 8
|
627
|
-
value, = work.unpack 'x6e'
|
628
|
-
end
|
623
|
+
row, column, xf, value = work.unpack binfmt(:number)
|
629
624
|
set_cell worksheet, row, column, xf, value
|
630
625
|
end
|
631
626
|
def read_rk worksheet, addr, work
|
@@ -66,10 +66,8 @@ class Worksheet
|
|
66
66
|
cent = 1
|
67
67
|
end
|
68
68
|
if value.is_a?(Integer)
|
69
|
-
|
70
|
-
|
71
|
-
shifted.reverse! if @bigendian
|
72
|
-
value, = shifted.unpack 'V'
|
69
|
+
## although not documented as signed, 'V' appears to correctly pack
|
70
|
+
# negative numbers.
|
73
71
|
value <<= 2
|
74
72
|
else
|
75
73
|
# FIXME: precision of small numbers
|
@@ -172,8 +170,13 @@ class Worksheet
|
|
172
170
|
multiples, first_idx = nil
|
173
171
|
row.each_with_index do |cell, idx|
|
174
172
|
cell = nil if cell == ''
|
175
|
-
|
176
|
-
|
173
|
+
## it appears that there are limitations to RK precision, both for
|
174
|
+
# Integers and Floats, that lie well below 2^30 significant bits, or
|
175
|
+
# Ruby's Bignum threshold. In that case we'll just write a Number
|
176
|
+
# record
|
177
|
+
need_number = (cell.is_a?(Float) && cell.to_s.length > 5) \
|
178
|
+
|| (cell.is_a?(Numeric) && cell.abs > 0x500000)
|
179
|
+
if multiples && (!multiples.last.is_a?(cell.class) || need_number)
|
177
180
|
write_multiples row, first_idx, multiples
|
178
181
|
multiples, first_idx = nil
|
179
182
|
end
|
@@ -197,7 +200,7 @@ class Worksheet
|
|
197
200
|
# 10^9. Not sure what is a good rule of thumb here, but it seems that
|
198
201
|
# Decimal Numbers with more than 4 significant digits are not represented
|
199
202
|
# with sufficient precision by RK
|
200
|
-
if
|
203
|
+
if need_number
|
201
204
|
write_number row, idx
|
202
205
|
elsif multiples
|
203
206
|
multiples.push cell
|
data/test/integration.rb
CHANGED
@@ -1062,5 +1062,24 @@ module Spreadsheet
|
|
1062
1062
|
sheet.name
|
1063
1063
|
assert_not_nil sheet.offset
|
1064
1064
|
end
|
1065
|
+
def test_bignum
|
1066
|
+
smallnum = 0x500000
|
1067
|
+
bignum = smallnum + 1
|
1068
|
+
book = Spreadsheet::Workbook.new
|
1069
|
+
sheet = book.create_worksheet
|
1070
|
+
sheet[0,0] = bignum
|
1071
|
+
sheet[1,0] = -bignum
|
1072
|
+
sheet[0,1] = smallnum
|
1073
|
+
sheet[1,1] = -smallnum
|
1074
|
+
path = File.join @var, 'test_big-number.xls'
|
1075
|
+
book.write path
|
1076
|
+
assert_nothing_raised do
|
1077
|
+
book = Spreadsheet.open path
|
1078
|
+
end
|
1079
|
+
assert_equal bignum, book.worksheet(0)[0,0]
|
1080
|
+
assert_equal -bignum, book.worksheet(0)[1,0]
|
1081
|
+
assert_equal smallnum, book.worksheet(0)[0,1]
|
1082
|
+
assert_equal -smallnum, book.worksheet(0)[1,1]
|
1083
|
+
end
|
1065
1084
|
end
|
1066
1085
|
end
|
data/test/worksheet.rb
CHANGED
@@ -4,12 +4,13 @@
|
|
4
4
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
5
|
|
6
6
|
require 'test/unit'
|
7
|
-
require 'spreadsheet
|
7
|
+
require 'spreadsheet'
|
8
8
|
|
9
9
|
module Spreadsheet
|
10
10
|
class TestWorksheet < Test::Unit::TestCase
|
11
11
|
def setup
|
12
|
-
@
|
12
|
+
@book = Workbook.new
|
13
|
+
@sheet = @book.create_worksheet
|
13
14
|
end
|
14
15
|
def test_cell_writer
|
15
16
|
assert_nil @sheet[0,0]
|
@@ -58,5 +59,14 @@ module Spreadsheet
|
|
58
59
|
@sheet.replace_row 3
|
59
60
|
assert_equal 4, @sheet.row_count
|
60
61
|
end
|
62
|
+
def test_modify_column
|
63
|
+
assert_equal 10, @sheet.column(0).width
|
64
|
+
@sheet.column(1).width = 20
|
65
|
+
assert_equal 10, @sheet.column(0).width
|
66
|
+
assert_equal 20, @sheet.column(1).width
|
67
|
+
@sheet.column(0).width = 30
|
68
|
+
assert_equal 30, @sheet.column(0).width
|
69
|
+
assert_equal 20, @sheet.column(1).width
|
70
|
+
end
|
61
71
|
end
|
62
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spreadsheet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.1.
|
4
|
+
version: 0.6.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hannes Wyss
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-10-
|
12
|
+
date: 2008-10-28 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|