spreadsheet 0.8.9 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Last Update: 31.05.2013 - Zeno R.R. Davatz
2
2
 
3
- = Spreadsheet
3
+ # Spreadsheet
4
4
 
5
5
  https://github.com/zdavatz/spreadsheet
6
6
 
@@ -24,7 +24,7 @@ For Non-GPLv3 commercial licencing, please see:
24
24
 
25
25
  http://www.spreadsheet.ch
26
26
 
27
- == Description
27
+ ## Description
28
28
 
29
29
  The Spreadsheet Library is designed to read and write Spreadsheet Documents.
30
30
  As of version 0.6.0, only Microsoft Excel compatible spreadsheets are
@@ -32,13 +32,13 @@ supported. Spreadsheet is a combination/complete rewrite of the
32
32
  Spreadsheet::Excel Library by Daniel J. Berger and the ParseExcel Library by
33
33
  Hannes Wyss. Spreadsheet can read, write and modify Spreadsheet Documents.
34
34
 
35
- == Notes from Users
35
+ ## Notes from Users
36
36
 
37
37
  Alfred: a@boxbot.org: I think it should be noted in the README file that the library doesn't
38
38
  recognize cell formats in Excel created documents, which results in
39
39
  Floats returned for any number.
40
40
 
41
- == What's new?
41
+ ## What's new?
42
42
 
43
43
  * Supported outline (grouping) functions
44
44
  * Significantly improved memory-efficiency when reading large Excel Files
@@ -46,7 +46,7 @@ Floats returned for any number.
46
46
  * Improved handling of String Encodings
47
47
 
48
48
 
49
- == On the Roadmap
49
+ ## On the Roadmap
50
50
 
51
51
  * Improved Format support/Styles
52
52
  * Document Modification: Formats/Styles
@@ -61,22 +61,22 @@ Note: Spreadsheet supports Ruby 1.8.6, 1.8.7, 1.9.2, 1.9.3
61
61
  You will get a deprecated warning about iconv when using spreadsheet with Ruby
62
62
  1.9.3. So replacing iconv is on the Roadmap as well ;).
63
63
 
64
- == Dependencies
64
+ ## Dependencies
65
65
 
66
66
  * ruby 1.8
67
67
  * ruby-ole [ http://code.google.com/p/ruby-ole/ ]
68
68
 
69
69
 
70
- == Examples
70
+ ## Examples
71
71
 
72
- Have a look at the GUIDE[link://files/GUIDE_txt.html].
73
- Also look at: https://gist.github.com/phollyer/1214475
72
+ * Have a look at the GUIDE: https://github.com/zdavatz/spreadsheet/blob/master/GUIDE.txt
73
+ * Also look at: https://gist.github.com/phollyer/1214475
74
74
 
75
- == Installation
75
+ ## Installation
76
76
 
77
77
  Using RubyGems [ http://www.rubygems.org ]:
78
78
 
79
- * sudo gem install spreadsheet
79
+ * `sudo gem install spreadsheet`
80
80
 
81
81
  If you don't like RubyGems[http://www.rubygems.org], let me know which
82
82
  installation solution you prefer and I'll include it in the future.
@@ -84,22 +84,22 @@ installation solution you prefer and I'll include it in the future.
84
84
  If you can use 'rake' and 'hoe' library is also installed, you can
85
85
  build a gem package as follows:
86
86
 
87
- * rake gem
87
+ * `rake gem`
88
88
 
89
89
  The gem package is built in pkg directory.
90
90
 
91
- == Testing
91
+ ## Testing
92
92
 
93
93
  Bundler support added.
94
94
  Running tests:
95
- * bundle install
95
+ * `bundle install`
96
96
  * ./test/suite.rb
97
97
 
98
- == Code Status
98
+ ## TravisCI
99
99
 
100
- * TravisCI [ https://travis-ci.org/zdavatz/spreadsheet ]
100
+ * https://travis-ci.org/zdavatz/spreadsheet
101
101
 
102
- == Authors
102
+ ## Authors
103
103
 
104
104
  Original Code:
105
105
 
@@ -113,7 +113,7 @@ New Code:
113
113
  Copyright (c) 2010 ywesee GmbH (mhatakeyama@ywesee.com, zdavatz@ywesee.com)
114
114
 
115
115
 
116
- == License
116
+ ## License
117
117
 
118
118
  This library is distributed under the GPLv3.
119
119
  Please see the LICENSE[link://files/LICENSE_txt.html] file.
data/bin/xlsopcodes CHANGED
@@ -1,18 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'xlsopcodes' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
2
8
 
3
- require 'spreadsheet'
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
4
12
 
5
- source, target = ARGV
13
+ require 'rubygems'
14
+ require 'bundler/setup'
6
15
 
7
- if source.nil?
8
- puts "Usage: #{$0} <source> [<target>]"
9
- exit -1
10
- end
11
-
12
- target = target ? File.open(target, 'w') : STDOUT
13
-
14
- reader = Spreadsheet::Excel::Reader.new :print_opcodes => target
15
- reader.setup File.open(source)
16
-
17
- while tuple = reader.get_next_chunk
18
- end
16
+ load Gem.bin_path('spreadsheet', 'xlsopcodes')
data/lib/spreadsheet.rb CHANGED
@@ -43,7 +43,7 @@ module Spreadsheet
43
43
 
44
44
  ##
45
45
  # The version of Spreadsheet you are using.
46
- VERSION = '0.8.9'
46
+ VERSION = '0.9.0'
47
47
 
48
48
  ##
49
49
  # Default client Encoding. Change this value if your application uses a
@@ -162,6 +162,7 @@ module Internals
162
162
  :labelsst => 'v3V',
163
163
  :number => "v3#{EIGHT_BYTE_DOUBLE}",
164
164
  :pagesetup => "v8#{EIGHT_BYTE_DOUBLE}2v",
165
+ :margin => "#{EIGHT_BYTE_DOUBLE}",
165
166
  :rk => 'v3V',
166
167
  :row => 'v4x4V',
167
168
  :window2 => 'v4x2v2x4',
@@ -866,6 +866,16 @@ class Reader
866
866
  read_merged_cells worksheet, work, pos, len
867
867
  when :protect, :password
868
868
  read_sheet_protection worksheet, op, work
869
+ when :pagesetup
870
+ read_pagesetup(worksheet, work, pos, len)
871
+ when :leftmargin
872
+ worksheet.margins[:left] = work.unpack(binfmt(:margin))[0]
873
+ when :rightmargin
874
+ worksheet.margins[:right] = work.unpack(binfmt(:margin))[0]
875
+ when :topmargin
876
+ worksheet.margins[:top] = work.unpack(binfmt(:margin))[0]
877
+ when :bottommargin
878
+ worksheet.margins[:bottom] = work.unpack(binfmt(:margin))[0]
869
879
  else
870
880
  if ROW_BLOCK_OPS.include?(op)
871
881
  set_missing_row_address worksheet, work, pos, len
@@ -874,6 +884,17 @@ class Reader
874
884
  previous = op
875
885
  end
876
886
  end
887
+
888
+ def read_pagesetup(worksheet, work, pos, len)
889
+ worksheet.pagesetup.delete_if { true }
890
+ data = work.unpack(binfmt(:pagesetup))
891
+ worksheet.pagesetup[:orientation] = data[5] == 0 ? :landscape : :portrait
892
+ worksheet.pagesetup[:adjust_to] = data[1]
893
+
894
+ worksheet.pagesetup[:orig_data] = data
895
+ # TODO: add options acording to specification
896
+ end
897
+
877
898
  def read_guts worksheet, work, pos, len
878
899
  # Offset Size Contents
879
900
  # 0 2 Width of the area to display row outlines (left of the sheet), in pixel
@@ -30,6 +30,14 @@ class Worksheet < Spreadsheet::Worksheet
30
30
  def date_base
31
31
  @workbook.date_base
32
32
  end
33
+ def margins
34
+ ensure_rows_read
35
+ super
36
+ end
37
+ def pagesetup
38
+ ensure_rows_read
39
+ super
40
+ end
33
41
  def each *args
34
42
  ensure_rows_read
35
43
  super
@@ -313,6 +313,8 @@ and minimal code that generates this warning. Thanks!
313
313
  # but these below are not necessary to run
314
314
  # if [Row|Column]#hidden? = false and [Row|Column]#outline_level == 0
315
315
  write_merged_cells
316
+ write_pagesetup
317
+ write_margins
316
318
  write_colinfos
317
319
  write_guts
318
320
 
@@ -498,6 +500,8 @@ and minimal code that generates this warning. Thanks!
498
500
  # ○ PHONETIC ➜ 5.77
499
501
  # ○ Conditional Formatting Table ➜ 4.12
500
502
  # ○ Hyperlink Table ➜ 4.13
503
+ write_pagesetup
504
+ write_margins
501
505
  write_hyperlink_table
502
506
  # ○ Data Validity Table ➜ 4.14
503
507
  # ○ SHEETLAYOUT ➜ 5.96 (BIFF8X only)
@@ -860,6 +864,27 @@ and minimal code that generates this warning. Thanks!
860
864
  end
861
865
  end
862
866
 
867
+ def write_pagesetup
868
+ return unless @worksheet.pagesetup
869
+ data = @worksheet.pagesetup[:orig_data].dup
870
+ if @worksheet.pagesetup[:orientation]
871
+ data[5] = @worksheet.pagesetup[:orientation] == :landscape ? 0 : 2
872
+ end
873
+
874
+ if @worksheet.pagesetup[:adjust_to]
875
+ data[1] = @worksheet.pagesetup[:adjust_to]
876
+ end
877
+
878
+ write_op opcode(:pagesetup), data.pack(binfmt(:pagesetup))
879
+ end
880
+
881
+ def write_margins
882
+ @worksheet.margins.each do |key, value|
883
+ next unless [:left, :top, :right, :bottom].include?(key)
884
+ write_op opcode(:"#{key}margin"), [value].pack(binfmt(:margin))
885
+ end
886
+ end
887
+
863
888
  def write_proctection
864
889
  return unless @worksheet.protected?
865
890
  # ○ PROTECT Worksheet contents: 1 = protected (➜ 5.82)
@@ -50,6 +50,11 @@ module Spreadsheet
50
50
  worksheet
51
51
  end
52
52
  ##
53
+ # Delete a Worksheet from Workbook by it's index
54
+ def delete_worksheet worksheet_index
55
+ @worksheets.delete_at worksheet_index
56
+ end
57
+ ##
53
58
  # Change the RGB components of the elements in the colour palette.
54
59
  def set_custom_color idx, red, green, blue
55
60
  raise 'Invalid format' if [red, green, blue].find { |c| ! (0..255).include?(c) }
@@ -28,11 +28,22 @@ module Spreadsheet
28
28
  include Spreadsheet::Encodings
29
29
  include Enumerable
30
30
  attr_accessor :name, :selected, :workbook, :password_hash
31
- attr_reader :rows, :columns, :merged_cells
31
+ attr_reader :rows, :columns, :merged_cells, :margins, :pagesetup
32
32
  def initialize opts={}
33
33
  @default_format = nil
34
34
  @selected = opts[:selected]
35
35
  @dimensions = [0,0,0,0]
36
+ @pagesetup = {
37
+ :orig_data => [9, 100, 1, 1, 1, 0, 300, 300, 0.5, 0.5, 1],
38
+ :orientation => :portrait,
39
+ :adjust_to => 100
40
+ }
41
+ @margins = {
42
+ :top => 1,
43
+ :left => 0.75,
44
+ :right => 0.75,
45
+ :bottom => 1
46
+ }
36
47
  @name = opts[:name] || 'Worksheet'
37
48
  @workbook = opts[:workbook]
38
49
  @rows = []
data/spreadsheet.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = "spreadsheet"
3
- s.version = "0.8.6"
3
+ s.version = "0.8.9"
4
4
  s.summary = "The Spreadsheet Library is designed to read and write Spreadsheet Documents"
5
5
  s.description = "As of version 0.6.0, only Microsoft Excel compatible spreadsheets are supported"
6
6
  s.author = "Masaomi Hatakeyama, Zeno R.R. Davatz"
@@ -14,6 +14,6 @@ spec = Gem::Specification.new do |s|
14
14
  s.add_dependency "ruby-ole"
15
15
  s.add_development_dependency "hoe"
16
16
 
17
- s.homepage = "http://scm.ywesee.com/?p=spreadsheet/.git;a=summary"
17
+ s.homepage = "https://github.com/zdavatz/spreadsheet/"
18
18
  end
19
19
 
Binary file
Binary file
data/test/integration.rb CHANGED
@@ -1280,6 +1280,53 @@ module Spreadsheet
1280
1280
  temp_file.unlink
1281
1281
  end
1282
1282
 
1283
+ def test_read_pagesetup
1284
+ path = File.join @data, 'test_pagesetup.xls'
1285
+ book = Spreadsheet.open path
1286
+ assert_instance_of Excel::Workbook, book
1287
+ sheet = book.worksheet(0)
1288
+ assert_equal(:landscape, sheet.pagesetup[:orientation])
1289
+ assert_equal(130, sheet.pagesetup[:adjust_to])
1290
+ end
1291
+
1292
+ def test_write_pagesetup
1293
+ book = Spreadsheet::Workbook.new
1294
+ path = File.join @var, 'test_write_pagesetup.xls'
1295
+ sheet1 = book.create_worksheet
1296
+ sheet1.pagesetup[:orientation] = :landscape
1297
+ sheet1.pagesetup[:adjust_to] = 93
1298
+ assert_nothing_raised do
1299
+ book.write path
1300
+ end
1301
+ book2 = Spreadsheet.open path
1302
+ assert_instance_of Excel::Workbook, book2
1303
+ sheet2 = book2.worksheet(0)
1304
+ assert_equal(:landscape, sheet2.pagesetup[:orientation])
1305
+ assert_equal(93, sheet2.pagesetup[:adjust_to])
1306
+ end
1307
+
1308
+ def test_read_margins
1309
+ path = File.join @data, 'test_margin.xls'
1310
+ book = Spreadsheet.open path
1311
+ assert_instance_of Excel::Workbook, book
1312
+ sheet = book.worksheet(0)
1313
+ assert_equal(2.0, sheet.margins[:left])
1314
+ end
1315
+
1316
+ def test_write_margins
1317
+ book = Spreadsheet::Workbook.new
1318
+ path = File.join @var, 'test_write_margins.xls'
1319
+ sheet1 = book.create_worksheet
1320
+ sheet1.margins[:left] = 3
1321
+ assert_nothing_raised do
1322
+ book.write path
1323
+ end
1324
+ book2 = Spreadsheet.open path
1325
+ assert_instance_of Excel::Workbook, book2
1326
+ sheet2 = book2.worksheet(0)
1327
+ assert_equal(3.0, sheet2.margins[:left])
1328
+ end
1329
+
1283
1330
  private
1284
1331
 
1285
1332
  # Validates the workbook's SST
data/test/workbook.rb CHANGED
@@ -40,5 +40,16 @@ module Spreadsheet
40
40
  @book.add_format f2
41
41
  assert_equal 3, @book.formats.length # Rejected duplicate insertion
42
42
  end
43
+
44
+ def test_delete_worksheet
45
+ original_count = @book.sheet_count
46
+ @sheet = @book.create_worksheet
47
+ changed_count = @book.sheet_count
48
+ @book.delete_worksheet(@book.sheet_count - 1)
49
+
50
+ assert_equal(changed_count, original_count + 1)
51
+ assert_equal(original_count, @book.sheet_count)
52
+ end
53
+
43
54
  end
44
55
  end
metadata CHANGED
@@ -1,95 +1,95 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet
3
- version: !ruby/object:Gem::Version
4
- version: 0.8.9
3
+ version: !ruby/object:Gem::Version
4
+ hash: 59
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Masaomi Hatakeyama, Zeno R.R. Davatz
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-08-24 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: ruby-ole
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '1.0'
17
+
18
+ date: 2013-09-16 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
22
21
  type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
23
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '1.0'
30
- - !ruby/object:Gem::Dependency
31
- name: rdoc
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: '3.10'
38
- type: :development
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 15
28
+ segments:
29
+ - 1
30
+ - 0
31
+ version: "1.0"
32
+ requirement: *id001
39
33
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '3.10'
46
- - !ruby/object:Gem::Dependency
47
- name: hoe
48
- requirement: !ruby/object:Gem::Requirement
34
+ name: ruby-ole
35
+ - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
49
38
  none: false
50
- requirements:
39
+ requirements:
51
40
  - - ~>
52
- - !ruby/object:Gem::Version
53
- version: '2.13'
54
- type: :development
41
+ - !ruby/object:Gem::Version
42
+ hash: 27
43
+ segments:
44
+ - 4
45
+ - 0
46
+ version: "4.0"
47
+ requirement: *id002
55
48
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
49
+ name: rdoc
50
+ - !ruby/object:Gem::Dependency
51
+ type: :development
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
53
  none: false
58
- requirements:
54
+ requirements:
59
55
  - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '2.13'
62
- description: ! 'The Spreadsheet Library is designed to read and write Spreadsheet
63
- Documents.
64
-
56
+ - !ruby/object:Gem::Version
57
+ hash: 11
58
+ segments:
59
+ - 3
60
+ - 6
61
+ version: "3.6"
62
+ requirement: *id003
63
+ prerelease: false
64
+ name: hoe
65
+ description: |-
66
+ The Spreadsheet Library is designed to read and write Spreadsheet Documents.
65
67
  As of version 0.6.0, only Microsoft Excel compatible spreadsheets are
66
-
67
68
  supported. Spreadsheet is a combination/complete rewrite of the
68
-
69
69
  Spreadsheet::Excel Library by Daniel J. Berger and the ParseExcel Library by
70
-
71
- Hannes Wyss. Spreadsheet can read, write and modify Spreadsheet Documents.'
72
- email:
70
+ Hannes Wyss. Spreadsheet can read, write and modify Spreadsheet Documents.
71
+ email:
73
72
  - mhatakeyama@ywesee.com, zdavatz@ywesee.com
74
- executables:
73
+ executables:
75
74
  - xlsopcodes
76
75
  extensions: []
77
- extra_rdoc_files:
78
- - GUIDE.txt
79
- - History.txt
76
+
77
+ extra_rdoc_files:
78
+ - GUIDE.md
79
+ - History.md
80
80
  - LICENSE.txt
81
81
  - Manifest.txt
82
- - README.txt
83
- files:
82
+ - README.md
83
+ files:
84
84
  - .gitignore
85
85
  - .travis.yml
86
- - GUIDE.txt
86
+ - GUIDE.md
87
87
  - Gemfile
88
88
  - Gemfile.lock
89
- - History.txt
89
+ - History.md
90
90
  - LICENSE.txt
91
91
  - Manifest.txt
92
- - README.txt
92
+ - README.md
93
93
  - Rakefile
94
94
  - bin/xlsopcodes
95
95
  - lib/parseexcel.rb
@@ -139,9 +139,11 @@ files:
139
139
  - test/data/test_empty.xls
140
140
  - test/data/test_formula.xls
141
141
  - test/data/test_long_sst_record.xls
142
+ - test/data/test_margin.xls
142
143
  - test/data/test_merged_and_protected.xls
143
144
  - test/data/test_merged_cells.xls
144
145
  - test/data/test_missing_row.xls
146
+ - test/data/test_pagesetup.xls
145
147
  - test/data/test_version_excel5.xls
146
148
  - test/data/test_version_excel95.xls
147
149
  - test/data/test_version_excel97.xls
@@ -161,28 +163,37 @@ files:
161
163
  - .gemtest
162
164
  homepage: https://github.com/zdavatz/spreadsheet
163
165
  licenses: []
166
+
164
167
  post_install_message:
165
- rdoc_options:
168
+ rdoc_options:
166
169
  - --main
167
- - README.txt
168
- require_paths:
170
+ - README.md
171
+ require_paths:
169
172
  - lib
170
- required_ruby_version: !ruby/object:Gem::Requirement
173
+ required_ruby_version: !ruby/object:Gem::Requirement
171
174
  none: false
172
- requirements:
173
- - - ! '>='
174
- - !ruby/object:Gem::Version
175
- version: '0'
176
- required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ hash: 3
179
+ segments:
180
+ - 0
181
+ version: "0"
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
183
  none: false
178
- requirements:
179
- - - ! '>='
180
- - !ruby/object:Gem::Version
181
- version: '0'
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ hash: 3
188
+ segments:
189
+ - 0
190
+ version: "0"
182
191
  requirements: []
192
+
183
193
  rubyforge_project: spreadsheet
184
194
  rubygems_version: 1.8.25
185
195
  signing_key:
186
196
  specification_version: 3
187
197
  summary: The Spreadsheet Library is designed to read and write Spreadsheet Documents
188
198
  test_files: []
199
+