spreadsheet 0.6.1.8 → 0.6.1.9

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.
@@ -1,3 +1,17 @@
1
+ === 0.6.1.9 / 2008-11-07
2
+
3
+ * 1 Bugfix
4
+
5
+ * Fixes a precision-issue in Excel::Row#datetime: Excel records Time-Values
6
+ with more significant bits (but not necessarily more precise) than
7
+ DateTime can handle.
8
+ (Thanks to Bjørn Hjelle for the Bugreport)
9
+
10
+ * 1 minor enhancement
11
+
12
+ * Added support for appending Worksheets to a Workbook
13
+ (Thanks to Mohammed Rabbani for the report)
14
+
1
15
  === 0.6.1.8 / 2008-10-31
2
16
 
3
17
  * 1 Bugfix
@@ -42,7 +42,7 @@ module Spreadsheet
42
42
 
43
43
  ##
44
44
  # The version of Spreadsheet you are using.
45
- VERSION = '0.6.1.8'
45
+ VERSION = '0.6.1.9'
46
46
 
47
47
  ##
48
48
  # Default client Encoding. Change this value if your application uses a
@@ -112,6 +112,7 @@ class Reader
112
112
  extend_internals biff
113
113
  read_workbook
114
114
  @workbook.default_format = @workbook.format 0
115
+ @workbook.changes.clear
115
116
  @workbook
116
117
  end
117
118
  def read_blank worksheet, addr, work
@@ -20,6 +20,11 @@ class Row < Spreadsheet::Row
20
20
  def datetime idx
21
21
  _datetime at(idx)
22
22
  end
23
+ def each &block
24
+ size.times do |idx|
25
+ block.call self[idx]
26
+ end
27
+ end
23
28
  ##
24
29
  # Access data in this Row like you would in an Array. If a cell is formatted
25
30
  # as a Date or DateTime, the decoded Date or DateTime value is returned.
@@ -49,7 +54,11 @@ class Row < Spreadsheet::Row
49
54
  def _datetime data # :nodoc:
50
55
  return data if data.is_a?(DateTime)
51
56
  date = _date data
52
- DateTime.new(date.year, date.month, date.day) + (data.to_f % 1)
57
+ hour = (data % 1) * 24
58
+ min = (hour % 1) * 60
59
+ sec = (min % 1) * 60
60
+ DateTime.new(date.year, date.month, date.day,
61
+ hour.to_i, min.to_i, sec.round)
53
62
  end
54
63
  def enriched_data idx, data # :nodoc:
55
64
  res = nil
@@ -44,6 +44,10 @@ class Workbook < Spreadsheet::Workbook
44
44
  def add_shared_string str
45
45
  @sst.push str
46
46
  end
47
+ def add_worksheet worksheet
48
+ @changes.store :boundsheets, true
49
+ super
50
+ end
47
51
  def biff_version
48
52
  case @bof
49
53
  when 0x009
@@ -154,11 +154,17 @@ class Workbook < Spreadsheet::Writer
154
154
  sst_strings.each_with_index do |str, idx| sst.store str, idx end
155
155
  sheets = worksheets(workbook)
156
156
  positions = []
157
+ newsheets = []
157
158
  sheets.each do |sheet|
158
159
  @sst[sheet] = sst
159
160
  pos, len = workbook.offsets[sheet.worksheet]
160
- positions.push pos
161
- sheet.write_changes reader, pos + len, sst_status
161
+ if pos
162
+ positions.push pos
163
+ sheet.write_changes reader, pos + len, sst_status
164
+ else
165
+ newsheets.push sheet
166
+ sheet.write_from_scratch
167
+ end
162
168
  sheet_data[sheet.worksheet] = sheet.data
163
169
  end
164
170
  Ole::Storage.open io do |ole|
@@ -202,6 +208,9 @@ class Workbook < Spreadsheet::Writer
202
208
  reader.seek lastpos
203
209
  end
204
210
  writer.write reader.read
211
+ newsheets.each do |sheet|
212
+ writer.write sheet.data
213
+ end
205
214
  end
206
215
  end
207
216
  end
@@ -160,7 +160,7 @@ module Spreadsheet
160
160
  ##
161
161
  # Is the cell formatted as a DateTime?
162
162
  def datetime?
163
- !!/([YMD].*[hms])|([hms].*[YMD])/.match(@number_format.to_s)
163
+ !!/([YMD].*[HS])|([HS].*[YMD])/.match(@number_format.to_s)
164
164
  end
165
165
  ##
166
166
  # Is the cell formatted as a Time?
@@ -502,6 +502,20 @@ module Spreadsheet
502
502
  assert_instance_of Excel::Worksheet, sheet
503
503
  assert_equal sheet, book.worksheet("S\000h\000e\000e\000t\0001\000")
504
504
  end
505
+ def test_datetime
506
+ path = File.join @data, 'test_datetime.xls'
507
+ book = Spreadsheet.open path
508
+ assert_instance_of Excel::Workbook, book
509
+ sheet = book.worksheet 0
510
+ time = sheet[0,0]
511
+ assert_equal 22, time.hour
512
+ assert_equal 00, time.min
513
+ assert_equal 00, time.sec
514
+ time = sheet[1,0]
515
+ assert_equal 22, time.hour
516
+ assert_equal 30, time.min
517
+ assert_equal 45, time.sec
518
+ end
505
519
  def test_change_encoding
506
520
  path = File.join @data, 'test_version_excel95.xls'
507
521
  book = Spreadsheet.open path
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.8
4
+ version: 0.6.1.9
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-31 00:00:00 +01:00
12
+ date: 2008-11-07 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency