writeexcel 0.6.19 → 1.0.0

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: 9f08faee160c80efda98d7e3f42d07aa547a92ca
4
- data.tar.gz: d1e75487c065ad0ac74dc978aac6218c21621aa3
3
+ metadata.gz: 702289cea8e425bbac18a6d8f80c4576cbf20161
4
+ data.tar.gz: b1957b4f76a19077b31f11183f0a8bcec2ba4553
5
5
  SHA512:
6
- metadata.gz: c6e152b9677247808da606c2bacb7f403b4c45f3f6f093ce6958a5de510d1bac8c81adb3f2e47591ffa79183f348db3c5f4429264c4d96abc81783eb6e6cb33f
7
- data.tar.gz: 61d1223ff7e8884ec3a92d79b8ec6af8d0f15696d0f1958c4a0a45c813d2aee5deebe0b470d6028423562a518265fd1f224d17b850c451ad506a324f71f937e2
6
+ metadata.gz: d37342053b25ef225bbd72facd93e71058c401d6d002ad579e5b6265f78b2dce090dfd597f9a984e37824f2574997fabc8ec55c849467e0bba88c2443c278dec
7
+ data.tar.gz: 2a4e84a327faee73ffb11784a5cde5dd267bd998a508821509e713e104f87241b04b836472b3ca47f871368858c36a70f7a70c80c67d762066f937828c3d720d
@@ -5,10 +5,7 @@ Write to a cross-platform Excel binary file.
5
5
  == Description
6
6
 
7
7
  This library is converted from Spreadsheet::WriteExcel module of Perl.
8
- http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.37/
9
-
10
- Some examples written in perl was successfully converted to Ruby. But
11
- this library written in Ruby has many bugs, I think.
8
+ http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.38/
12
9
 
13
10
  Original description is below:
14
11
 
@@ -42,8 +39,8 @@ Or install it yourself as:
42
39
 
43
40
  == Usage
44
41
 
45
- See rdoc's WriteExcel class document or Reference http://writeexcel.web.fc2.com/ .
46
- You must save source file in UTF8 and run ruby with -Ku option or set $KCODE='u'.
42
+ See Reference http://writeexcel.web.fc2.com/ .
43
+ You must save source file in UTF8, and run ruby with -Ku option or set $KCODE='u' in Ruby 1.8.
47
44
 
48
45
  Example Code:
49
46
 
@@ -84,12 +81,10 @@ Example Code:
84
81
  * ignore. if write 0001, use string such as write(1,2, '0001')
85
82
  * and ......
86
83
 
87
- == Caution
88
-
89
- You must save source file in UTF8 and run ruby with -Ku option or set $KCODE='u'
90
- when use urf8 string data.
91
-
92
- == Recent Changes
84
+ == Recent Change
85
+ v1.0.0
86
+ * Bug fix in Workbook#set_properties.
87
+ s
93
88
  v0.6.19
94
89
  * Bug fix in Worksheet#write_url_internal
95
90
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby -w
1
+ #!/usr/bin/ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  ##############################################################################
@@ -15,7 +15,7 @@
15
15
 
16
16
  workbook = WriteExcel.new('properties.xls')
17
17
  worksheet = workbook.add_worksheet
18
- bp =1
18
+
19
19
  workbook.set_properties(
20
20
  :title => 'This is an example spreadsheet',
21
21
  :subject => 'With document properties',
@@ -4,8 +4,6 @@ class Worksheet < BIFFWriter
4
4
  require 'writeexcel/helper'
5
5
 
6
6
  class ColInfo
7
- attr_reader :level
8
-
9
7
  #
10
8
  # new(firstcol, lastcol, width, [format, hidden, level, collapsed])
11
9
  #
@@ -226,14 +226,16 @@ def pack_VT_FILETIME(localtime) #:nodoc:
226
226
 
227
227
  epoch = DateTime.new(1601, 1, 1)
228
228
 
229
+ t = localtime.getgm
230
+
229
231
  datetime = DateTime.new(
230
- localtime.year,
231
- localtime.mon,
232
- localtime.mday,
233
- localtime.hour,
234
- localtime.min,
235
- localtime.sec,
236
- localtime.usec
232
+ t.year,
233
+ t.mon,
234
+ t.mday,
235
+ t.hour,
236
+ t.min,
237
+ t.sec,
238
+ t.usec
237
239
  )
238
240
  bignum = (datetime - epoch) * 86400 * 1e7.to_i
239
241
  high, low = bignum.divmod 1 << 32
@@ -669,15 +669,18 @@ def _saveHeader(rh_info, iSBDcnt, iBBcnt, iPPScnt)
669
669
  iAllW = iAll
670
670
  iBdCntW = iAllW / iBlCnt
671
671
  iBdCntW += 1 if iAllW % iBlCnt > 0
672
- iBdCnt = 0
673
- #0.1 Calculate BD count
674
- iBlCnt -= 1 #the BlCnt is reduced in the count of the last sect is used for a pointer the next Bl
675
- iBBleftover = iAll - i1stBdMax
676
- if iAll >i1stBdMax
677
- iBdCnt, iBdExL, iBBleftover = calc_idbcnt_idbexl_ibbleftover(iBBleftover, iBlCnt, iBdCnt, iBdExL)
672
+ iBdCnt = ((iAll + iBdCntW) / iBlCnt).to_i
673
+ iBdCnt += ((iAllW + iBdCntW) % iBlCnt) == 0 ? 0 : 1
674
+ if iBdCnt > i1stBdL
675
+ #0.1 Calculate BD count
676
+ iBlCnt -= 1 #the BlCnt is reduced in the count of the last sect is used for a pointer the next Bl
677
+ iBBleftover = iAll - i1stBdMax
678
+ if iAll >i1stBdMax
679
+ iBdCnt, iBdExL, iBBleftover = calc_idbcnt_idbexl_ibbleftover(iBBleftover, iBlCnt, iBdCnt, iBdExL)
680
+ end
681
+ iBdCnt += i1stBdL
682
+ #print "iBdCnt = iBdCnt \n"
678
683
  end
679
- iBdCnt += i1stBdL
680
- #print "iBdCnt = iBdCnt \n"
681
684
 
682
685
  #1.Save Header
683
686
  data = [
@@ -694,8 +697,8 @@ def _saveHeader(rh_info, iSBDcnt, iBBcnt, iPPScnt)
694
697
  [iBBcnt+iSBDcnt].pack("V"), #ROOT START
695
698
  [0].pack("V"),
696
699
  [0x1000].pack("V"),
697
- [0].pack("V"), #Small Block Depot
698
- [1].pack("V")
700
+ [iSBDcnt == 0 ? -2 : 0].pack("V"), #Small Block Depot
701
+ [iSBDcnt].pack("V")
699
702
  ]
700
703
  file.write(
701
704
  ruby_18 { data.join('') } ||
@@ -805,9 +808,9 @@ def _savePpsSetPnt(pps_array, aList, rh_info)
805
808
  aWk = pps_array.dup
806
809
  #1.3.2 Devide a array into Previous,Next
807
810
  aPrev = aWk[0, iPos]
808
- aWk[0..iPos-1] = nil
811
+ aWk[0..iPos-1] = []
809
812
  aNext = aWk[1, iCnt - iPos - 1]
810
- aWk[1..(1 + iCnt - iPos -1 -1)] = nil
813
+ aWk[1..(1 + iCnt - iPos -1 -1)] = []
811
814
  pps_array[iPos].prev_pps = _savePpsSetPnt(aPrev, aList, rh_info)
812
815
  pps_array[iPos].next_pps = _savePpsSetPnt(aNext, aList, rh_info)
813
816
  pps_array[iPos].dir_pps = _savePpsSetPnt(pps_array[iPos].child, aList, rh_info)
@@ -837,7 +840,7 @@ def _savePpsSetPnt2(pps_array, aList, rh_info)
837
840
 
838
841
  aWk = pps_array.dup
839
842
  aPrev = aWk[1, 1]
840
- aWk[1..1] = nil
843
+ aWk[1..1] = []
841
844
  aNext = aWk[1..aWk.size] #, $iCnt - $iPos -1);
842
845
  pps_array[iPos].prev_pps = _savePpsSetPnt2(pps_array, aList, rh_info)
843
846
  aList.push(pps_array[iPos])
@@ -1,5 +1,5 @@
1
1
  require 'writeexcel'
2
2
 
3
3
  class WriteExcel < Workbook
4
- VERSION = "0.6.19"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -492,14 +492,6 @@ def test_for_store_mso_split_menu_colors
492
492
  assert_equal(target, result, caption)
493
493
  end
494
494
 
495
- ###############################################################################
496
- #
497
- # Unpack the binary data into a format suitable for printing in tests.
498
- #
499
- def unpack_record(data)
500
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
501
- end
502
-
503
495
  def data_for_test
504
496
  return [
505
497
  [ 'DggContainer', # Caption
@@ -739,12 +739,4 @@ def test_3_sheets_1024_and_1024_and_1_times_duplicate
739
739
 
740
740
  end
741
741
  =end
742
- ###############################################################################
743
- #
744
- # Unpack the binary data into a format suitable for printing in tests.
745
- #
746
- def unpack_record(data)
747
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
748
- end
749
-
750
742
  end
@@ -54,13 +54,4 @@ def test_defined_author_name
54
54
  result = unpack_record(comment.store_note_record(obj_id))
55
55
  assert_equal(target, result, caption)
56
56
  end
57
-
58
- ###############################################################################
59
- #
60
- # Unpack the binary data into a format suitable for printing in tests.
61
- #
62
- def unpack_record(data)
63
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
64
- end
65
-
66
57
  end
@@ -71,13 +71,4 @@ def test_second_continue_record_after_txo
71
71
  result = unpack_record(comment.__send__("store_txo_continue_2", formats))
72
72
  assert_equal(target, result, caption)
73
73
  end
74
-
75
- ###############################################################################
76
- #
77
- # Unpack the binary data into a format suitable for printing in tests.
78
- #
79
- def unpack_record(data)
80
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
81
- end
82
-
83
74
  end
@@ -71,13 +71,4 @@ def test_3
71
71
  result = unpack_record(@validations.__send__("dval_record", obj_id, dv_count))
72
72
  assert_equal(target, result, caption)
73
73
  end
74
-
75
- ###############################################################################
76
- #
77
- # Unpack the binary data into a format suitable for printing in tests.
78
- #
79
- def unpack_record(data)
80
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
81
- end
82
-
83
74
  end
@@ -120,13 +120,4 @@ def test_string_longer_than_32_characters_for_dialog_messages
120
120
  result = unpack_record(@data_validation.__send__("pack_dv_string", string, max_length))
121
121
  assert_equal(target, result, caption)
122
122
  end
123
-
124
- ###############################################################################
125
- #
126
- # Unpack the binary data into a format suitable for printing in tests.
127
- #
128
- def unpack_record(data)
129
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
130
- end
131
-
132
123
  end
@@ -207,13 +207,4 @@ def test_pack_dv_formula_should_not_change_formula_string
207
207
 
208
208
  assert_equal('=SUM(A1:D1)', formula)
209
209
  end
210
-
211
- ###############################################################################
212
- #
213
- # Unpack the binary data into a format suitable for printing in tests.
214
- #
215
- def unpack_record(data)
216
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
217
- end
218
-
219
210
  end
@@ -176,13 +176,4 @@ def test_pack_a_VT_FILETIME
176
176
  result = unpack_record( pack_VT_FILETIME(filetime) )
177
177
  assert_equal(target, result, caption)
178
178
  end
179
-
180
- ###############################################################################
181
- #
182
- # Unpack the binary data into a format suitable for printing in tests.
183
- #
184
- def unpack_record(data)
185
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
186
- end
187
-
188
179
  end
@@ -223,13 +223,4 @@ def test_same_as_previous_plus_creation_date
223
223
  result = unpack_record( create_summary_property_set(properties))
224
224
  assert_equal(target, result, caption)
225
225
  end
226
-
227
- ###############################################################################
228
- #
229
- # Unpack the binary data into a format suitable for printing in tests.
230
- #
231
- def unpack_record(data)
232
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
233
- end
234
-
235
226
  end
@@ -431,13 +431,4 @@ def test_same_as_previous_plus_creation_date
431
431
  workbook.close
432
432
 
433
433
  end
434
-
435
- ###############################################################################
436
- #
437
- # Unpack the binary data into a format suitable for printing in tests.
438
- #
439
- def unpack_record(data)
440
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
441
- end
442
-
443
434
  end
@@ -567,8 +567,4 @@ def test_store_serauxtrend
567
567
  got = unpack_record(@chart.__send__("store_serauxtrend", *values))
568
568
  assert_equal(expected, got, caption)
569
569
  end
570
-
571
- def unpack_record(data)
572
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
573
- end
574
570
  end
@@ -638,8 +638,4 @@ def get_plotarea_formats(chart)
638
638
 
639
639
  [line, area]
640
640
  end
641
-
642
- def unpack_record(data)
643
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
644
- end
645
641
  end
@@ -3421,4 +3421,38 @@ def test_compatibility_mode_write_number
3421
3421
  # do assertion
3422
3422
  compare_file("#{PERL_OUTDIR}/compatibility_mode_write_number.xls", @file)
3423
3423
  end
3424
+
3425
+ def test_properties
3426
+ workbook = WriteExcel.new(@file)
3427
+
3428
+ #
3429
+ # adjust @localtime to target xls file.
3430
+ #
3431
+ workbook.instance_variable_set(
3432
+ :@localtime,
3433
+ Time.local(2013, 5, 5, 22, 37, 42)
3434
+ )
3435
+
3436
+ worksheet = workbook.add_worksheet
3437
+
3438
+ workbook.set_properties(
3439
+ :title => 'This is an example spreadsheet',
3440
+ :subject => 'With document properties',
3441
+ :author => 'Hideo NAKAMURA',
3442
+ :manager => 'John McNamara',
3443
+ :company => 'Rubygem',
3444
+ :category => 'Example spreadsheets',
3445
+ :keywords => 'Sample, Example, Properties',
3446
+ :comments => 'Created with Ruby and WriteExcel'
3447
+ )
3448
+
3449
+
3450
+ worksheet.set_column('A:A', 50)
3451
+ worksheet.write('A1', 'Select File->Properties to see the file properties')
3452
+
3453
+ workbook.close
3454
+
3455
+ # do assertion
3456
+ compare_file("#{PERL_OUTDIR}/properties.xls", @file)
3457
+ end
3424
3458
  end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'helper'
4
+ require 'stringio'
5
+
6
+ class TestProperties < Test::Unit::TestCase
7
+ def setup
8
+ @workbook = WriteExcel.new(StringIO.new)
9
+ end
10
+
11
+ def test_pack_VT_FILETIME
12
+ assert_equal(
13
+ '40 00 00 00 00 FD 2D ED CE 48 CE 01',
14
+ unpack_record(pack_VT_FILETIME(Time.local(2013, 5, 4, 22, 54, 42)))
15
+ )
16
+ end
17
+
18
+ def test_create_summary_property_set
19
+ assert_equal(
20
+ 'FE FF 00 00 05 01 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 E0 85 9F F2 F9 4F 68 10 AB 91 08 00 2B 27 B3 D9 30 00 00 00 08 01 00 00 07 00 00 00 01 00 00 00 40 00 00 00 02 00 00 00 48 00 00 00 03 00 00 00 70 00 00 00 04 00 00 00 94 00 00 00 05 00 00 00 AC 00 00 00 06 00 00 00 D0 00 00 00 0C 00 00 00 FC 00 00 00 02 00 00 00 E4 04 00 00 1E 00 00 00 1F 00 00 00 54 68 69 73 20 69 73 20 61 6E 20 65 78 61 6D 70 6C 65 20 73 70 72 65 61 64 73 68 65 65 74 00 00 1E 00 00 00 19 00 00 00 57 69 74 68 20 64 6F 63 75 6D 65 6E 74 20 70 72 6F 70 65 72 74 69 65 73 00 00 00 00 1E 00 00 00 0F 00 00 00 48 69 64 65 6F 20 4E 41 4B 41 4D 55 52 41 00 00 1E 00 00 00 1C 00 00 00 53 61 6D 70 6C 65 2C 20 45 78 61 6D 70 6C 65 2C 20 50 72 6F 70 65 72 74 69 65 73 00 1E 00 00 00 21 00 00 00 43 72 65 61 74 65 64 20 77 69 74 68 20 52 75 62 79 20 61 6E 64 20 57 72 69 74 65 45 78 63 65 6C 00 00 00 00 40 00 00 00 00 62 93 81 C5 48 CE 01',
21
+ unpack_record(create_summary_property_set(
22
+ [
23
+ [1, "VT_I2", 1252],
24
+ [2, "VT_LPSTR", "This is an example spreadsheet"],
25
+ [3, "VT_LPSTR", "With document properties"],
26
+ [4, "VT_LPSTR", "Hideo NAKAMURA"],
27
+ [5, "VT_LPSTR", "Sample, Example, Properties"],
28
+ [6, "VT_LPSTR", "Created with Ruby and WriteExcel"],
29
+ [12, "VT_FILETIME", Time.local(2013, 5, 4, 21, 47, 16)]
30
+ ]
31
+ ))
32
+ )
33
+ end
34
+ end
@@ -43,11 +43,6 @@ def test_ucs2asc
43
43
  assert_equal(str, result)
44
44
  end
45
45
  end
46
-
47
- def unpack_record(data)
48
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
49
- end
50
-
51
46
  end
52
47
 
53
48
  class TC_OLEStorageLitePPSFile < Test::Unit::TestCase
@@ -108,9 +103,4 @@ def test_append_stringio
108
103
  assert_equal(d, pps_file.read)
109
104
  end
110
105
  end
111
-
112
- def unpack_record(data)
113
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
114
- end
115
-
116
106
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: writeexcel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.19
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hideo NAKAMURA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-30 00:00:00.000000000 Z
11
+ date: 2013-05-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Multiple worksheets can be added to a workbook and formatting can be
14
14
  applied to cells. Text, numbers, formulas, hyperlinks and images can be written
@@ -209,6 +209,7 @@ files:
209
209
  - test/perl_output/outline_collapsed.xls
210
210
  - test/perl_output/panes.xls
211
211
  - test/perl_output/password_protection.xls
212
+ - test/perl_output/properties.xls
212
213
  - test/perl_output/protection.xls
213
214
  - test/perl_output/regions.xls
214
215
  - test/perl_output/right_to_left.xls
@@ -269,6 +270,7 @@ files:
269
270
  - test/test_format.rb
270
271
  - test/test_formula.rb
271
272
  - test/test_ole.rb
273
+ - test/test_properties.rb
272
274
  - test/test_storage_lite.rb
273
275
  - test/test_workbook.rb
274
276
  - test/test_worksheet.rb
@@ -364,6 +366,7 @@ test_files:
364
366
  - test/perl_output/outline_collapsed.xls
365
367
  - test/perl_output/panes.xls
366
368
  - test/perl_output/password_protection.xls
369
+ - test/perl_output/properties.xls
367
370
  - test/perl_output/protection.xls
368
371
  - test/perl_output/regions.xls
369
372
  - test/perl_output/right_to_left.xls
@@ -424,6 +427,7 @@ test_files:
424
427
  - test/test_format.rb
425
428
  - test/test_formula.rb
426
429
  - test/test_ole.rb
430
+ - test/test_properties.rb
427
431
  - test/test_storage_lite.rb
428
432
  - test/test_workbook.rb
429
433
  - test/test_worksheet.rb