ttb-spreadsheet 0.6.5.8

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.
Files changed (65) hide show
  1. data/GUIDE.txt +267 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +18 -0
  4. data/History.txt +365 -0
  5. data/LICENSE.txt +619 -0
  6. data/Manifest.txt +62 -0
  7. data/README.txt +107 -0
  8. data/Rakefile +0 -0
  9. data/bin/xlsopcodes +18 -0
  10. data/lib/parseexcel.rb +27 -0
  11. data/lib/parseexcel/parseexcel.rb +75 -0
  12. data/lib/parseexcel/parser.rb +11 -0
  13. data/lib/spreadsheet.rb +79 -0
  14. data/lib/spreadsheet/column.rb +71 -0
  15. data/lib/spreadsheet/compatibility.rb +23 -0
  16. data/lib/spreadsheet/datatypes.rb +106 -0
  17. data/lib/spreadsheet/encodings.rb +57 -0
  18. data/lib/spreadsheet/excel.rb +88 -0
  19. data/lib/spreadsheet/excel/error.rb +26 -0
  20. data/lib/spreadsheet/excel/internals.rb +365 -0
  21. data/lib/spreadsheet/excel/internals/biff5.rb +17 -0
  22. data/lib/spreadsheet/excel/internals/biff8.rb +19 -0
  23. data/lib/spreadsheet/excel/offset.rb +41 -0
  24. data/lib/spreadsheet/excel/reader.rb +1173 -0
  25. data/lib/spreadsheet/excel/reader/biff5.rb +22 -0
  26. data/lib/spreadsheet/excel/reader/biff8.rb +199 -0
  27. data/lib/spreadsheet/excel/row.rb +92 -0
  28. data/lib/spreadsheet/excel/sst_entry.rb +46 -0
  29. data/lib/spreadsheet/excel/workbook.rb +80 -0
  30. data/lib/spreadsheet/excel/worksheet.rb +100 -0
  31. data/lib/spreadsheet/excel/writer.rb +1 -0
  32. data/lib/spreadsheet/excel/writer/biff8.rb +75 -0
  33. data/lib/spreadsheet/excel/writer/format.rb +253 -0
  34. data/lib/spreadsheet/excel/writer/workbook.rb +690 -0
  35. data/lib/spreadsheet/excel/writer/worksheet.rb +891 -0
  36. data/lib/spreadsheet/font.rb +92 -0
  37. data/lib/spreadsheet/format.rb +177 -0
  38. data/lib/spreadsheet/formula.rb +9 -0
  39. data/lib/spreadsheet/helpers.rb +11 -0
  40. data/lib/spreadsheet/link.rb +43 -0
  41. data/lib/spreadsheet/row.rb +132 -0
  42. data/lib/spreadsheet/workbook.rb +126 -0
  43. data/lib/spreadsheet/worksheet.rb +287 -0
  44. data/lib/spreadsheet/writer.rb +30 -0
  45. data/spreadsheet.gemspec +20 -0
  46. data/test/data/test_changes.xls +0 -0
  47. data/test/data/test_copy.xls +0 -0
  48. data/test/data/test_datetime.xls +0 -0
  49. data/test/data/test_empty.xls +0 -0
  50. data/test/data/test_formula.xls +0 -0
  51. data/test/data/test_long_sst_record.xls +0 -0
  52. data/test/data/test_missing_row.xls +0 -0
  53. data/test/data/test_version_excel5.xls +0 -0
  54. data/test/data/test_version_excel95.xls +0 -0
  55. data/test/data/test_version_excel97.xls +0 -0
  56. data/test/excel/row.rb +35 -0
  57. data/test/excel/writer/workbook.rb +23 -0
  58. data/test/excel/writer/worksheet.rb +24 -0
  59. data/test/font.rb +163 -0
  60. data/test/integration.rb +1311 -0
  61. data/test/row.rb +33 -0
  62. data/test/suite.rb +17 -0
  63. data/test/workbook.rb +29 -0
  64. data/test/worksheet.rb +80 -0
  65. metadata +151 -0
@@ -0,0 +1,62 @@
1
+ GUIDE.txt
2
+ History.txt
3
+ LICENSE.txt
4
+ Manifest.txt
5
+ README.txt
6
+ Rakefile
7
+ bin/xlsopcodes
8
+ lib/parseexcel.rb
9
+ lib/parseexcel/parseexcel.rb
10
+ lib/parseexcel/parser.rb
11
+ lib/spreadsheet.rb
12
+ lib/spreadsheet/column.rb
13
+ lib/spreadsheet/compatibility.rb
14
+ lib/spreadsheet/datatypes.rb
15
+ lib/spreadsheet/encodings.rb
16
+ lib/spreadsheet/excel.rb
17
+ lib/spreadsheet/excel/error.rb
18
+ lib/spreadsheet/excel/internals.rb
19
+ lib/spreadsheet/excel/internals/biff5.rb
20
+ lib/spreadsheet/excel/internals/biff8.rb
21
+ lib/spreadsheet/excel/offset.rb
22
+ lib/spreadsheet/excel/reader.rb
23
+ lib/spreadsheet/excel/reader/biff5.rb
24
+ lib/spreadsheet/excel/reader/biff8.rb
25
+ lib/spreadsheet/excel/row.rb
26
+ lib/spreadsheet/excel/sst_entry.rb
27
+ lib/spreadsheet/excel/workbook.rb
28
+ lib/spreadsheet/excel/worksheet.rb
29
+ lib/spreadsheet/excel/writer.rb
30
+ lib/spreadsheet/excel/writer/biff8.rb
31
+ lib/spreadsheet/excel/writer/format.rb
32
+ lib/spreadsheet/excel/writer/workbook.rb
33
+ lib/spreadsheet/excel/writer/worksheet.rb
34
+ lib/spreadsheet/font.rb
35
+ lib/spreadsheet/format.rb
36
+ lib/spreadsheet/formula.rb
37
+ lib/spreadsheet/helpers.rb
38
+ lib/spreadsheet/link.rb
39
+ lib/spreadsheet/row.rb
40
+ lib/spreadsheet/workbook.rb
41
+ lib/spreadsheet/worksheet.rb
42
+ lib/spreadsheet/writer.rb
43
+ spreadsheet-0.6.5.gem
44
+ spreadsheet.gemspec
45
+ test/data/test_changes.xls
46
+ test/data/test_copy.xls
47
+ test/data/test_datetime.xls
48
+ test/data/test_empty.xls
49
+ test/data/test_formula.xls
50
+ test/data/test_long_sst_record.xls
51
+ test/data/test_missing_row.xls
52
+ test/data/test_version_excel5.xls
53
+ test/data/test_version_excel95.xls
54
+ test/data/test_version_excel97.xls
55
+ test/excel/row.rb
56
+ test/excel/writer/worksheet.rb
57
+ test/font.rb
58
+ test/integration.rb
59
+ test/row.rb
60
+ test/suite.rb
61
+ test/workbook.rb
62
+ test/worksheet.rb
@@ -0,0 +1,107 @@
1
+ Last Update: 16.09.2011 - Zeno R.R. Davatz
2
+
3
+ = Spreadsheet
4
+
5
+ http://spreadsheet.rubyforge.org
6
+
7
+ The Mailing List can be found here:
8
+
9
+ http://groups.google.com/group/rubyspreadsheet
10
+
11
+ The code can be found here:
12
+
13
+ http://spreadsheet.rubyforge.org
14
+
15
+ For a viewable directory of all recent changes, please see:
16
+
17
+ http://scm.ywesee.com/?p=spreadsheet/.git;a=summary
18
+
19
+ To get a graphical overview of the Library please see
20
+
21
+ http://spreadsheet.rubyforge.org/spreadsheet.jpeg
22
+
23
+ For Non-GPLv3 commercial licencing, please see:
24
+
25
+ http://www.spreadsheet.ch
26
+
27
+
28
+ == Description
29
+
30
+ The Spreadsheet Library is designed to read and write Spreadsheet Documents.
31
+ As of version 0.6.0, only Microsoft Excel compatible spreadsheets are
32
+ supported. Spreadsheet is a combination/complete rewrite of the
33
+ Spreadsheet::Excel Library by Daniel J. Berger and the ParseExcel Library by
34
+ Hannes Wyss. Spreadsheet can read, write and modify Spreadsheet Documents.
35
+
36
+ == Notes from Users
37
+
38
+ Alfred: a@boxbot.org: I think it should be noted in the README file that the library doesn't
39
+ recognize cell formats in Excel created documents, which results in
40
+ Floats returned for any number.
41
+
42
+ == What's new?
43
+
44
+ * Supported outline (grouping) functions
45
+ * Significantly improved memory-efficiency when reading large Excel Files
46
+ * Limited Spreadsheet modification support
47
+ * Improved handling of String Encodings
48
+
49
+
50
+ == Roadmap
51
+
52
+ 0.7.0:: Improved Format support/Styles
53
+ 0.7.1:: Document Modification: Formats/Styles
54
+ 0.8.0:: Formula Support
55
+ 0.8.1:: Document Modification: Formulas
56
+ 0.9.0:: Write-Support: BIFF5
57
+ 1.0.0:: Ruby 1.9 Support;
58
+ Remove backward compatibility code
59
+
60
+
61
+ == Dependencies
62
+
63
+ * ruby 1.8
64
+ * ruby-ole[http://code.google.com/p/ruby-ole/]
65
+
66
+
67
+ == Examples
68
+
69
+ Have a look at the GUIDE[link://files/GUIDE_txt.html].
70
+
71
+
72
+ == Installation
73
+
74
+ Using RubyGems[http://www.rubygems.org]:
75
+
76
+ * sudo gem install spreadsheet
77
+
78
+ If you don't like RubyGems[http://www.rubygems.org], let me know which
79
+ installation solution you prefer and I'll include it in the future.
80
+
81
+ If you can use 'rake' and 'hoe' library is also installed, you can
82
+ build a gem package as follows:
83
+
84
+ * rake gem
85
+
86
+ The gem package is built in pkg directory.
87
+
88
+
89
+ == Authors
90
+
91
+ Original Code:
92
+
93
+ Spreadsheet::Excel:
94
+ Copyright (c) 2005 by Daniel J. Berger (djberg96@gmail.com)
95
+
96
+ ParseExcel:
97
+ Copyright (c) 2003 by Hannes Wyss (hannes.wyss@gmail.com)
98
+
99
+ New Code:
100
+ Copyright (c) 2010 ywesee GmbH (mhatakeyama@ywesee.com, zdavatz@ywesee.com)
101
+
102
+
103
+ == License
104
+
105
+ This library is distributed under the GPLv3.
106
+ Please see the LICENSE[link://files/LICENSE_txt.html] file.
107
+
File without changes
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spreadsheet'
4
+
5
+ source, target = ARGV
6
+
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
@@ -0,0 +1,27 @@
1
+ ### Spreadsheet - A Library for reading and writing Spreadsheet Documents.
2
+ #
3
+ # Copyright (C) 2008 Hannes Wyss
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # Contact Information:
19
+ #
20
+ # E-Mail: hannes.wyss@gmail.com
21
+ # P-Mail: ywesee GmbH
22
+ # Hannes Wyss
23
+ # Winterthurerstrasse 52
24
+ # 8006 Zürich
25
+ ### Switzerland
26
+
27
+ require 'parseexcel/parseexcel'
@@ -0,0 +1,75 @@
1
+ require 'spreadsheet'
2
+
3
+ warn <<-EOS
4
+ [DEPRECATED] By requiring 'parseexcel', 'parseexcel/parseexcel' and/or
5
+ 'parseexcel/parser' you are loading a Compatibility layer which
6
+ provides a drop-in replacement for the ParseExcel library. This
7
+ code makes the reading of Spreadsheet documents less efficient and
8
+ will be removed in Spreadsheet version 1.0.0
9
+ EOS
10
+
11
+ module Spreadsheet
12
+ ##
13
+ # The ParseExcel module is provided as a drop-in replacement for the
14
+ # ParseExcel library. This code is deprecated and will be removed in
15
+ # Spreadsheet version 1.0.0
16
+ module ParseExcel
17
+ def ParseExcel.parse path
18
+ Spreadsheet.open path
19
+ end
20
+ class Worksheet
21
+ class Cell
22
+ attr_accessor :value, :kind, :numeric, :code, :book,
23
+ :format, :rich, :encoding, :annotation
24
+ def initialize value, format, row, idx
25
+ @format = format
26
+ @idx = idx
27
+ @row = row
28
+ @value = value
29
+ @encoding = Spreadsheet.client_encoding
30
+ end
31
+ def date
32
+ @row.date @idx
33
+ end
34
+ def datetime
35
+ @row.datetime @idx
36
+ end
37
+ def to_i
38
+ @value.to_i
39
+ end
40
+ def to_f
41
+ @value.to_f
42
+ end
43
+ def to_s(target_encoding=nil)
44
+ if(target_encoding)
45
+ begin
46
+ Iconv.new(target_encoding, @encoding).iconv(@value)
47
+ rescue
48
+ Iconv.new(target_encoding, 'ascii').iconv(@value.to_s)
49
+ end
50
+ else
51
+ @value.to_s
52
+ end
53
+ end
54
+ def type
55
+ if @format && (@format.date? || @format.time?)
56
+ :date
57
+ elsif @value.is_a?(Numeric)
58
+ :numeric
59
+ else
60
+ :text
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ module Excel
67
+ class Reader # :nodoc: all
68
+ def set_cell worksheet, row, column, xf, value=nil
69
+ cells = @current_row_block[row] ||= Row.new(nil, row)
70
+ cells.formats[column] = xf = @workbook.format(xf)
71
+ cells[column] = ParseExcel::Worksheet::Cell.new(value, xf, cells, column)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,11 @@
1
+ require 'parseexcel'
2
+
3
+ module Spreadsheet
4
+ module ParseExcel # :nodoc: all
5
+ class Parser
6
+ def parse path
7
+ Spreadsheet.open path
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,79 @@
1
+ ### Spreadsheet - A Library for reading and writing Spreadsheet Documents.
2
+ #
3
+ # Copyright (C) 2008-2010 ywesee GmbH
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # Contact Information:
19
+ #
20
+ # E-Mail: mhatakeyama@ywesee.com, zdavatz@ywesee.com
21
+ # P-Mail: ywesee GmbH
22
+ # Zeno R.R. Davatz
23
+ # Winterthurerstrasse 52
24
+ # 8006 Zürich
25
+ ### Switzerland
26
+
27
+ require 'spreadsheet/excel/workbook'
28
+ require 'spreadsheet/excel/reader'
29
+
30
+ # = Synopsis
31
+ # The Spreadsheet Library is designed to read and write Spreadsheet Documents.
32
+ # As of version 0.6.0, only Microsoft Excel compatible spreadsheets are
33
+ # supported.
34
+ #
35
+ # == Example
36
+ # require 'spreadsheet'
37
+ #
38
+ # book = Spreadsheet.open '/path/to/an/excel-file.xls'
39
+ # sheet = book.worksheet 0
40
+ # sheet.each do |row| puts row[0] end
41
+ module Spreadsheet
42
+
43
+ ##
44
+ # The version of Spreadsheet you are using.
45
+ VERSION = '0.6.5.9'
46
+
47
+ ##
48
+ # Default client Encoding. Change this value if your application uses a
49
+ # different Encoding:
50
+ # Spreadsheet.client_encoding = 'ISO-LATIN-1//TRANSLIT//IGNORE'
51
+ @client_encoding = 'UTF-8'
52
+
53
+ class << self
54
+
55
+ attr_accessor :client_encoding
56
+
57
+ ##
58
+ # Parses a Spreadsheet Document and returns a Workbook object. At present,
59
+ # only Excel-Documents can be read.
60
+ def open io_or_path, mode="rb+", &block
61
+ if io_or_path.respond_to? :seek
62
+ Excel::Workbook.open(io_or_path)
63
+ elsif block
64
+ File.open(io_or_path, mode) do |fh|
65
+ block.call open(fh)
66
+ end
67
+ else
68
+ open File.open(io_or_path, mode)
69
+ end
70
+ end
71
+
72
+ ##
73
+ # Returns a Writer object for the specified path. At present, only the
74
+ # Excel-Writer is available.
75
+ def writer io_or_path, type=Excel
76
+ Excel::Writer::Workbook.new io_or_path
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,71 @@
1
+ require 'spreadsheet/datatypes'
2
+
3
+ module Spreadsheet
4
+ ##
5
+ # The Column class. Encapsulates column-formatting and width, and provides a
6
+ # means to iterate over all cells in a column.
7
+ #
8
+ # Useful Attributes:
9
+ # #width:: The width in characters (in respect to the '0' character
10
+ # of the Worksheet's default Font). Float values are
11
+ # permitted, for Excel the available Precision is at 1/256
12
+ # characters.
13
+ # #default_format:: The default Format for cells in this column (applied if
14
+ # there is no explicit Cell Format and no default Row format
15
+ # for the Cell).
16
+ # #hidden:: The Column is hidden.
17
+ # #collapsed:: The Column is collapsed.
18
+ # #outline_level:: Outline level of the column.
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
34
+ include Datatypes
35
+ include Enumerable
36
+ attr_accessor :width, :worksheet
37
+ attr_reader :default_format, :idx
38
+ boolean :hidden, :collapsed
39
+ enum :outline_level, 0, Integer
40
+ updater :collapsed, :hidden, :outline_level, :width
41
+ def initialize idx, format, opts={}
42
+ @worksheet = nil
43
+ @idx = idx
44
+ opts[:width] ||= 10
45
+ opts.each do |key, value|
46
+ self.send "#{key}=", value
47
+ end
48
+ self.default_format = format
49
+ end
50
+ ##
51
+ # Set the default Format for Cells in this Column.
52
+ def default_format= format
53
+ @worksheet.add_format format if @worksheet
54
+ @default_format = format
55
+ @worksheet.column_updated @idx, self if @worksheet
56
+ format
57
+ end
58
+ ##
59
+ # Iterate over all cells in this column.
60
+ def each
61
+ @worksheet.each do |row|
62
+ yield row[idx]
63
+ end
64
+ end
65
+ def == other # :nodoc:
66
+ other.is_a?(Column) && default_format == other.default_format \
67
+ && width == other.width && hidden == other.hidden \
68
+ && collapsed == other.collapsed && outline_level == other.outline_level
69
+ end
70
+ end
71
+ end