spreadsheet 0.6.1 → 0.6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +1 -0
- data/lib/spreadsheet.rb +1 -1
- data/lib/spreadsheet/column.rb +53 -0
- data/lib/spreadsheet/excel/internals.rb +2 -0
- data/lib/spreadsheet/excel/reader.rb +3 -3
- data/lib/spreadsheet/excel/row.rb +1 -1
- data/lib/spreadsheet/excel/sst_entry.rb +1 -1
- data/lib/spreadsheet/excel/workbook.rb +2 -2
- data/lib/spreadsheet/excel/worksheet.rb +1 -1
- data/lib/spreadsheet/excel/writer/biff8.rb +1 -1
- data/lib/spreadsheet/excel/writer/format.rb +2 -2
- data/lib/spreadsheet/excel/writer/workbook.rb +2 -2
- data/lib/spreadsheet/excel/writer/worksheet.rb +3 -3
- data/lib/spreadsheet/font.rb +2 -2
- data/lib/spreadsheet/format.rb +2 -2
- data/lib/spreadsheet/workbook.rb +1 -1
- data/lib/spreadsheet/worksheet.rb +1 -1
- data/test/integration.rb +14 -0
- metadata +3 -2
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/lib/spreadsheet.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
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
|
+
include Datatypes
|
21
|
+
include Enumerable
|
22
|
+
attr_accessor :width, :worksheet
|
23
|
+
attr_reader :default_format, :idx
|
24
|
+
boolean :hidden, :collapsed
|
25
|
+
enum :outline_level, 0, Integer
|
26
|
+
def initialize idx, format, opts={}
|
27
|
+
@idx = idx
|
28
|
+
opts[:width] ||= 10
|
29
|
+
opts.each do |key, value|
|
30
|
+
self.send "#{key}=", value
|
31
|
+
end
|
32
|
+
self.default_format = format
|
33
|
+
end
|
34
|
+
##
|
35
|
+
# Set the default Format for Cells in this Column.
|
36
|
+
def default_format= format
|
37
|
+
@worksheet.add_format format if @worksheet
|
38
|
+
@default_format = format
|
39
|
+
end
|
40
|
+
##
|
41
|
+
# Iterate over all cells in this column.
|
42
|
+
def each
|
43
|
+
@worksheet.each do |row|
|
44
|
+
yield row[idx]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
def == other # :nodoc:
|
48
|
+
other.is_a?(Column) && default_format == other.default_format \
|
49
|
+
&& width == other.width && hidden == other.hidden \
|
50
|
+
&& collapsed == other.collapsed && outline_level == other.outline_level
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -197,6 +197,8 @@ module Internals
|
|
197
197
|
}
|
198
198
|
LEAP_ERROR = Date.new 1900, 2, 28
|
199
199
|
OPCODES = {
|
200
|
+
:annotation => 0x01b6, # Details unknown
|
201
|
+
:note => 0x001c, # Details unknown
|
200
202
|
:blank => 0x0201, # BLANK ➜ 6.7
|
201
203
|
:boolerr => 0x0205, # BOOLERR ➜ 6.10
|
202
204
|
:boundsheet => 0x0085, # ●● BOUNDSHEET ➜ 6.12
|
@@ -13,8 +13,8 @@ module Spreadsheet
|
|
13
13
|
# Excel-Record/Opcode. You should not need to call any of its methods
|
14
14
|
# directly. If you think you do, look at #read
|
15
15
|
class Reader
|
16
|
-
include Encodings
|
17
|
-
include Internals
|
16
|
+
include Spreadsheet::Encodings
|
17
|
+
include Spreadsheet::Excel::Internals
|
18
18
|
OPCODE_SIZE = 4
|
19
19
|
ROW_BLOCK_OPS = [
|
20
20
|
:blank, :boolerr, :dbcell, :formula, :label, :labelsst, :mulblank, :mulrk,
|
@@ -853,7 +853,7 @@ class Reader
|
|
853
853
|
@pos += len
|
854
854
|
code = SEDOCPO.fetch(op, op)
|
855
855
|
#puts "0x%04x/%-16s (0x%08x) %5i: %s" % [op, code.inspect, pos, len, work[0,16].inspect]
|
856
|
-
|
856
|
+
puts "0x%04x/%-16s %5i: %s" % [op, code.inspect, len, work[0,32].inspect]
|
857
857
|
[ pos, code, len + OPCODE_SIZE, work]
|
858
858
|
end
|
859
859
|
end
|
@@ -9,8 +9,8 @@ module Spreadsheet
|
|
9
9
|
# Excel-specific Workbook methods. These are mostly pertinent to the Excel
|
10
10
|
# reader. You should have no reason to use any of these.
|
11
11
|
class Workbook < Spreadsheet::Workbook
|
12
|
-
include Encodings
|
13
|
-
include Offset
|
12
|
+
include Spreadsheet::Encodings
|
13
|
+
include Spreadsheet::Excel::Offset
|
14
14
|
BIFF_VERSIONS = {
|
15
15
|
0x000 => 2,
|
16
16
|
0x007 => 2,
|
@@ -9,7 +9,7 @@ module Spreadsheet
|
|
9
9
|
# reader, and to recording changes to the Worksheet. You should have no reason
|
10
10
|
# to use any of these.
|
11
11
|
class Worksheet < Spreadsheet::Worksheet
|
12
|
-
include Offset
|
12
|
+
include Spreadsheet::Excel::Offset
|
13
13
|
offset :dimensions
|
14
14
|
attr_reader :offset, :ole
|
15
15
|
def initialize opts = {}
|
@@ -8,7 +8,7 @@ module Spreadsheet
|
|
8
8
|
# to Biff8. This Module is likely to be expanded as Support for older Versions
|
9
9
|
# of Excel grows and methods get moved here for disambiguation.
|
10
10
|
module Biff8
|
11
|
-
include Encodings
|
11
|
+
include Spreadsheet::Encodings
|
12
12
|
##
|
13
13
|
# Check whether the string _data_ can be compressed (i.e. every second byte
|
14
14
|
# is a Null-byte) and perform compression.
|
@@ -7,8 +7,8 @@ module Spreadsheet
|
|
7
7
|
module Writer
|
8
8
|
##
|
9
9
|
# This class encapsulates everything that is needed to write an XF record.
|
10
|
-
class Format < DelegateClass
|
11
|
-
include Internals
|
10
|
+
class Format < DelegateClass Spreadsheet::Format
|
11
|
+
include Spreadsheet::Excel::Internals
|
12
12
|
def Format.boolean *args
|
13
13
|
args.each do |key|
|
14
14
|
define_method key do
|
@@ -15,8 +15,8 @@ module Spreadsheet
|
|
15
15
|
# doesn't mean it shouldn't be possible ;). You should not need to call any of
|
16
16
|
# its methods directly. If you think you do, look at #write_workbook
|
17
17
|
class Workbook < Spreadsheet::Writer
|
18
|
-
include Biff8
|
19
|
-
include Internals
|
18
|
+
include Spreadsheet::Excel::Writer::Biff8
|
19
|
+
include Spreadsheet::Excel::Internals
|
20
20
|
attr_reader :fonts
|
21
21
|
def initialize *args
|
22
22
|
super
|
@@ -10,9 +10,9 @@ module Spreadsheet
|
|
10
10
|
# Excel-Record/Opcode. You should not need to call any of its methods directly.
|
11
11
|
# If you think you do, look at #write_worksheet
|
12
12
|
class Worksheet
|
13
|
-
include Biff8
|
14
|
-
include Internals
|
15
|
-
include Internals::Biff8
|
13
|
+
include Spreadsheet::Excel::Writer::Biff8
|
14
|
+
include Spreadsheet::Excel::Internals
|
15
|
+
include Spreadsheet::Excel::Internals::Biff8
|
16
16
|
attr_reader :worksheet
|
17
17
|
def initialize workbook, worksheet
|
18
18
|
@workbook = workbook
|
data/lib/spreadsheet/font.rb
CHANGED
data/lib/spreadsheet/format.rb
CHANGED
@@ -6,8 +6,8 @@ module Spreadsheet
|
|
6
6
|
##
|
7
7
|
# Formatting data
|
8
8
|
class Format
|
9
|
-
include
|
10
|
-
include
|
9
|
+
include Spreadsheet::Datatypes
|
10
|
+
include Spreadsheet::Encodings
|
11
11
|
##
|
12
12
|
# You can set the following boolean attributes:
|
13
13
|
# #cross_down:: Draws a Line from the top-left to the bottom-right
|
data/lib/spreadsheet/workbook.rb
CHANGED
@@ -11,7 +11,7 @@ module Spreadsheet
|
|
11
11
|
# that have no format set explicitly or in
|
12
12
|
# Row#default_format or Worksheet#default_format.
|
13
13
|
class Workbook
|
14
|
-
include Encodings
|
14
|
+
include Spreadsheet::Encodings
|
15
15
|
attr_reader :io, :worksheets, :formats, :fonts
|
16
16
|
attr_accessor :encoding, :version, :default_format
|
17
17
|
def initialize io = nil, opts={:default_format => Format.new}
|
@@ -20,7 +20,7 @@ module Spreadsheet
|
|
20
20
|
# If you modify a Column directly, your changes will be
|
21
21
|
# reflected in all those positions.
|
22
22
|
class Worksheet
|
23
|
-
include Encodings
|
23
|
+
include Spreadsheet::Encodings
|
24
24
|
include Enumerable
|
25
25
|
attr_accessor :name, :workbook
|
26
26
|
attr_reader :rows, :columns
|
data/test/integration.rb
CHANGED
@@ -1030,5 +1030,19 @@ module Spreadsheet
|
|
1030
1030
|
sheet.name
|
1031
1031
|
assert_not_nil sheet.offset
|
1032
1032
|
end
|
1033
|
+
def test_file_comment
|
1034
|
+
source = File.expand_path 'data/test_comment.xls', File.dirname(__FILE__)
|
1035
|
+
book = Spreadsheet.open source
|
1036
|
+
sheet = book.worksheet 0
|
1037
|
+
row = sheet.row 0
|
1038
|
+
ann = row.annotation 0
|
1039
|
+
assert_equal 'cellcontent', row.cell(0)
|
1040
|
+
assert_equal 'cellcomment', ann
|
1041
|
+
assert_equal 'HW', ann.author
|
1042
|
+
row = sheet.row 1
|
1043
|
+
ann = row.annotation 1
|
1044
|
+
assert_equal 'cellcontent', row.cell(1)
|
1045
|
+
assert_equal 'annotation', ann
|
1046
|
+
end
|
1033
1047
|
end
|
1034
1048
|
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.1
|
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-20 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/parseexcel/parseexcel.rb
|
57
57
|
- lib/parseexcel/parser.rb
|
58
58
|
- lib/spreadsheet.rb
|
59
|
+
- lib/spreadsheet/column.rb
|
59
60
|
- lib/spreadsheet/datatypes.rb
|
60
61
|
- lib/spreadsheet/encodings.rb
|
61
62
|
- lib/spreadsheet/excel.rb
|