xmlss 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +12 -11
- data/README.rdoc +141 -107
- data/Rakefile +24 -1
- data/bench/profiler.rb +6 -0
- data/bench/profiler_runner.rb +43 -0
- data/examples/example_workbook.rb +8 -12
- data/examples/layout.rb +34 -60
- data/examples/layout.xml +66 -0
- data/examples/simple.rb +16 -21
- data/examples/simple.xml +32 -0
- data/examples/styles.rb +52 -56
- data/examples/styles.xml +50 -0
- data/examples/text.rb +18 -28
- data/examples/text.xml +20 -0
- data/lib/xmlss/{cell.rb → element/cell.rb} +4 -14
- data/lib/xmlss/{column.rb → element/column.rb} +2 -7
- data/lib/xmlss/{data.rb → element/data.rb} +7 -12
- data/lib/xmlss/{row.rb → element/row.rb} +2 -13
- data/lib/xmlss/{worksheet.rb → element/worksheet.rb} +7 -18
- data/lib/xmlss/style/alignment.rb +3 -10
- data/lib/xmlss/style/base.rb +6 -45
- data/lib/xmlss/style/border.rb +5 -5
- data/lib/xmlss/style/font.rb +2 -9
- data/lib/xmlss/style/interior.rb +2 -5
- data/lib/xmlss/style/number_format.rb +4 -7
- data/lib/xmlss/style/protection.rb +4 -7
- data/lib/xmlss/undies_writer.rb +172 -0
- data/lib/xmlss/version.rb +1 -1
- data/lib/xmlss/workbook.rb +97 -31
- data/lib/xmlss.rb +1 -28
- data/test/{cell_test.rb → element/cell_test.rb} +11 -35
- data/test/{column_test.rb → element/column_test.rb} +6 -12
- data/test/{data_test.rb → element/data_test.rb} +15 -10
- data/test/{row_test.rb → element/row_test.rb} +5 -35
- data/test/{worksheet_test.rb → element/worksheet_test.rb} +4 -30
- data/test/helper.rb +13 -30
- data/test/style/alignment_test.rb +13 -45
- data/test/style/base_test.rb +1 -106
- data/test/style/border_test.rb +12 -32
- data/test/style/font_test.rb +11 -43
- data/test/style/interior_test.rb +7 -27
- data/test/style/number_format_test.rb +5 -21
- data/test/style/protection_test.rb +2 -12
- data/test/undies_writer_test.rb +333 -0
- data/test/workbook_test.rb +89 -44
- data/xmlss.gemspec +2 -2
- metadata +37 -39
- data/lib/xmlss/item_set.rb +0 -17
- data/lib/xmlss/table.rb +0 -22
- data/lib/xmlss/xml.rb +0 -60
- data/test/item_set_test.rb +0 -27
- data/test/table_test.rb +0 -56
- data/test/xml_test.rb +0 -81
- data/test/xmlss_test.rb +0 -31
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
xmlss (0.
|
5
|
-
enumeration (~> 1.
|
6
|
-
|
4
|
+
xmlss (0.4.0)
|
5
|
+
enumeration (~> 1.3)
|
6
|
+
undies (~> 2.1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
ansi (1.
|
12
|
-
assert (0.
|
13
|
-
assert-view (~> 0.
|
14
|
-
assert-view (0.
|
11
|
+
ansi (1.4.1)
|
12
|
+
assert (0.7.3)
|
13
|
+
assert-view (~> 0.5)
|
14
|
+
assert-view (0.5.0)
|
15
15
|
ansi (~> 1.3)
|
16
|
-
undies (~>
|
17
|
-
enumeration (1.
|
18
|
-
nokogiri (1.5.0)
|
16
|
+
undies (~> 2.0)
|
17
|
+
enumeration (1.3.1)
|
19
18
|
rake (0.9.2)
|
20
|
-
|
19
|
+
ruby-prof (0.10.8)
|
20
|
+
undies (2.1.0)
|
21
21
|
|
22
22
|
PLATFORMS
|
23
23
|
ruby
|
@@ -26,4 +26,5 @@ DEPENDENCIES
|
|
26
26
|
assert (~> 0.6)
|
27
27
|
bundler (~> 1.0)
|
28
28
|
rake (~> 0.9.2)
|
29
|
+
ruby-prof
|
29
30
|
xmlss!
|
data/README.rdoc
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
= Xmlss
|
2
|
+
A ruby DSL for generating spreadsheets in the XML Spreadsheet format. It provides an api for constructing spreadsheet data and then uses that data to generate xml that can be interpreted by MS Excel.
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
This gem allows you to generate spreadsheets in the XML Spreadsheet format. It provides an api for constructing spreadsheet data and then uses that data to generate xml that can be interpreted by MS Excel.
|
6
|
-
|
7
|
-
** Note: this gem only generates XML according to a subset of the August 2001 XML Spreadsheet spec (http://msdn.microsoft.com/en-us/library/aa140066(office.10).aspx). It does not generate the more modern open office spreadsheet spec (xlsx).
|
4
|
+
** Note: this gem only generates XML according to a subset of the August 2001 XML Spreadsheet spec (http://msdn.microsoft.com/en-us/library/aa140066(office.10).aspx). It does not generate the more modern open office spreadsheet spec (xlsx) and may have limited support in modern spreadsheet applications.
|
8
5
|
|
9
6
|
== Installation
|
10
7
|
|
@@ -14,122 +11,159 @@ This gem allows you to generate spreadsheets in the XML Spreadsheet format. It
|
|
14
11
|
|
15
12
|
require 'xmlss'
|
16
13
|
|
17
|
-
workbook = Xmlss::
|
18
|
-
|
14
|
+
workbook = Xmlss::Worksheet.new do
|
15
|
+
|
16
|
+
worksheet("5 columns, 1 row") {
|
17
|
+
5.times do
|
18
|
+
column
|
19
|
+
end
|
20
|
+
|
21
|
+
row {
|
22
|
+
# put data into the row (infer type)
|
23
|
+
[1, "text", 123.45, "0001267", "$45.23"].each do |data_value|
|
24
|
+
cell { data data_value }
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
}
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
workbook.to_s # => "..." (XML Spreadsheet xml string)
|
33
|
+
|
34
|
+
== DSL / API
|
35
|
+
|
36
|
+
Use these directives to create workbook markup elements.
|
37
|
+
|
38
|
+
worksheet(name):
|
39
|
+
* name: string
|
40
|
+
|
41
|
+
column(apts={}):
|
42
|
+
* opts[:style_id]: string
|
43
|
+
* opts[:width]: numeric
|
44
|
+
* opts[:auto_fit_width]: bool, default: false
|
45
|
+
* opts[:hidden]: bool, default: false
|
46
|
+
|
47
|
+
row(opts={}):
|
48
|
+
* opts[:style_id]: string
|
49
|
+
* opts[:height]: numeric
|
50
|
+
* opts[:auto_fit_height]: bool, default: false
|
51
|
+
* opts[:hidden]: bool, default: false
|
52
|
+
|
53
|
+
cell(opts={}):
|
54
|
+
* opts[:style_id]: string
|
55
|
+
* opts[:href]: string
|
56
|
+
* opts[:formula]: string
|
57
|
+
* opts[:merge_across]: fixnum, default: 0
|
58
|
+
* opts[:merge_down]: fixnum, default: 0
|
59
|
+
|
60
|
+
data(value, opts={}):
|
61
|
+
* value: whatever
|
62
|
+
* opts[:type]: enum: :number, :date_time, :boolean, :string, :error
|
63
|
+
* the :type option is defaulted appropriately based on the value - use the option to override as necessary
|
64
|
+
|
65
|
+
Use these directives to define markup element styles. Bind to markup using the element's :style_id option. See 'examples/styles.rb' for more details.
|
66
|
+
|
67
|
+
style(id):
|
68
|
+
* id: string, must be unique to the workbook
|
69
|
+
|
70
|
+
alignment(opts={}):
|
71
|
+
* opts[:wrap_text]: bool, default: false
|
72
|
+
* opts[:rotate]: fixnum (-90 to 90)
|
73
|
+
* opts[:horizontal]: enum: :automatic, :left, :center, :right, :default
|
74
|
+
* opts[:vertical]: enum: :automatic, :top, :center, :bottom, :default
|
75
|
+
|
76
|
+
borders:
|
77
|
+
* use this to build a set of border directives (see examples/styles.rb for details)
|
78
|
+
|
79
|
+
border(opts={}):
|
80
|
+
* opts[:color]: string, hex value ('#00FF00')
|
81
|
+
* opts[:position]: enum: :left, :top, :right, :bottom
|
82
|
+
* opts[:style]: enum: :none, :continuous (default), :dash, :dot, :dash_dot, :dash_dot_dot
|
83
|
+
* opts[:weight]: enum: :hairline, :thin (default), :medium, :thick
|
84
|
+
|
85
|
+
font(opts={}):
|
86
|
+
* opts[:bold]: bool, default: false
|
87
|
+
* opts[:color]: string, hex value ('#00FF00')
|
88
|
+
* opts[:name]: string
|
89
|
+
* opts[:italic]: bool, default: false
|
90
|
+
* opts[:size]: fixnum
|
91
|
+
* opts[:strike_through]: bool, default: false
|
92
|
+
* opts[:shadow]: bool, default: false
|
93
|
+
* opts[:underline]: enum: :single, :double, :single_accounting, :double_accounting
|
94
|
+
* opts[:alignment]: enum: :subscript, :superscript
|
95
|
+
|
96
|
+
interior(opts={}):
|
97
|
+
* opts[:color]: string, hex value ('#00FF00')
|
98
|
+
* opts[:pattern]: enum (see code for options), default: :default
|
99
|
+
* opts[:pattern_color]: string, hex value ('#00FF00')
|
100
|
+
|
101
|
+
number_format(value):
|
102
|
+
* value: there are MANY different options for this, I suggest saving a spreadsheet in the XML format and seeing what Excel uses
|
103
|
+
|
104
|
+
protection(value):
|
105
|
+
* value: bool, default: false
|
19
106
|
|
20
|
-
|
21
|
-
:name => 'Sheet 1'
|
22
|
-
})
|
23
|
-
sheet1.table = Xmlss::Table.new
|
24
|
-
sheet1.table.rows # => []
|
107
|
+
== Usage
|
25
108
|
|
26
|
-
|
27
|
-
|
28
|
-
|
109
|
+
To generate a spreadsheet, create an Xmlss::Workbook instance and build the workbook using the above DSL. Workbook takes two optional parameters:
|
110
|
+
* opts: hash: :data, :output
|
111
|
+
* &build: proc containing DSL directives
|
29
112
|
|
30
|
-
|
31
|
-
workbook.worksheets << sheet1
|
113
|
+
=== Data option
|
32
114
|
|
33
|
-
|
115
|
+
Xmlss evals the build proc in the scope of the workbook instance. This means that the build has access to only the data it is given or the DSL itself. Data is given in the form of a Hash. The string form of the hash keys are exposed as local workbook methods that return their corresponding values.
|
34
116
|
|
35
|
-
|
36
|
-
|
117
|
+
Xmlss::Workbook.new(:data => {:sheet_name => 'A cool sheet'}) do
|
118
|
+
worksheet(sheet_name) {
|
119
|
+
...
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
=== Output option (Undies)
|
124
|
+
|
125
|
+
Xmlss uses Undies (https://github.com/kelredd/undies) to render the XML output. The :output Workbook option is used to create Undies::Ouput objects. See their docs for usage details (https://github.com/kelredd/undies/blob/master/README.rdoc).
|
126
|
+
|
127
|
+
Xmlss::Workbook.new(:output => {:pp => 2}) do
|
128
|
+
worksheet(sheet_name) {
|
129
|
+
...
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
=== Builder approach
|
134
|
+
|
135
|
+
The above examples all pass in a build proc that is eval'd in the scope of the workbook instance. This works great when you know your build at the same time you create your Workbook object. However, in some cases, the build may not be known upfront or you may want to use a more declarative style to specify your spreadsheet content. Workbook builds can be specified programmatically using the "builder" approach.
|
136
|
+
|
137
|
+
To render using this approach, create a Workbook instance passing it data and output info as above. However, don't pass any build proc and save off the created workbook:
|
138
|
+
|
139
|
+
# choosing not to use any local data or output options
|
140
|
+
workbook = Xmlss::Workbook.new
|
141
|
+
|
142
|
+
Now just interact with the Workbook API directly.
|
143
|
+
|
144
|
+
# notice that it becomes less important to bind any local data to the Workbook using this approach
|
145
|
+
something = "Some Thing!"
|
146
|
+
workbook.worksheet(something) {
|
147
|
+
workbook.column
|
148
|
+
|
149
|
+
workbook.row {
|
150
|
+
workbook.cell {
|
151
|
+
workbook.data "hi hi something hi"
|
152
|
+
}
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
== Disclaimer
|
37
157
|
|
38
158
|
Be aware this library only provides the basic, raw API for constructing spreadsheets using this spec and utilities to convert those objects to string xml data representing them. It does not provide any macro logic to aid in constructing the sheets. If you want a more convenient API for your use case, I suggest subclassing the objects and tailoring them to your needs.
|
39
159
|
|
40
160
|
The XML Spreadsheet spec and format are legacy and may have limited support depending on your version of MS Excel. For a more modern spreadsheet generation method, I suggest looking into Office Open XML Workbook format (http://en.wikipedia.org/wiki/Office_Open_XML).
|
41
161
|
|
42
|
-
== API
|
43
|
-
|
44
|
-
These classes define how a spreadsheet is constructed.
|
45
|
-
=== Xmlss::Workbook
|
46
|
-
* *styles*: array, Xmlss:Style objects, default: []
|
47
|
-
* *worksheets*: array, Xmlss::Worksheet objects, default: []
|
48
|
-
|
49
|
-
=== Xmlss::Worksheet
|
50
|
-
* *name*: string
|
51
|
-
* *table*: Xmlss::Table object
|
52
|
-
|
53
|
-
=== Xmlss::Table
|
54
|
-
* *columns*: array, Xmlss::Column objects, default: []
|
55
|
-
* *rows*: array, Xmlss::Row objects, default: []
|
56
|
-
|
57
|
-
=== Xmlss::Column
|
58
|
-
* *style_id*: string
|
59
|
-
* *width*: numeric
|
60
|
-
* *auto_fit_width*: bool, default: false
|
61
|
-
* *hidden*: bool, default: false
|
62
|
-
|
63
|
-
=== Xmlss::Row
|
64
|
-
* *style_id*: string
|
65
|
-
* *height*: numeric
|
66
|
-
* *auto_fit_height*: bool, default: false
|
67
|
-
* *hidden*: bool, default: false
|
68
|
-
* *cells*: array, Xmlss::Cell objects, default: []
|
69
|
-
|
70
|
-
=== Xmlss::Cell
|
71
|
-
* *style_id*: string
|
72
|
-
* *data*: Xmlss::Data object
|
73
|
-
* *href*: string
|
74
|
-
* *merge_across*: int, default: 0
|
75
|
-
* *merge_down*: int, default: 0
|
76
|
-
|
77
|
-
=== Xmlss::Data
|
78
|
-
* *type*: :number, :date_time, :boolean, :string, :error, required
|
79
|
-
* *value*: needs to respond to 'to_s'
|
80
|
-
|
81
|
-
|
82
|
-
These classes define how a spreadsheet cells are styled.
|
83
|
-
=== Xmlss::Style
|
84
|
-
* *id*: string, unique identifier for the style
|
85
|
-
* *alignment*: Xmlss::Style::Alignment object
|
86
|
-
* *borders*: array, Xmlss::Style::Border objects, default: []
|
87
|
-
* *font*: Xmlss::Style::Font object
|
88
|
-
* *interior*: Xmlss::Style::Interior object
|
89
|
-
* *number_format*: Xmlss::Style::NumberFormat object
|
90
|
-
* *protection*: Xmlss::Protection object
|
91
|
-
|
92
|
-
=== Xmlss::Style::Alignment
|
93
|
-
* *horizontal*: :automatic, :left, :center, :right, :default, default: :default
|
94
|
-
* *vertical*: :automatic, :top, :center, :bottom, :default, default: :default
|
95
|
-
* *wrap_text*: bool, default: false
|
96
|
-
* *rotate*: int (-90 to 90)
|
97
|
-
|
98
|
-
=== Xmlss::Style::Border
|
99
|
-
* *position*: :left, :top, :right, :bottom
|
100
|
-
* *color*: hex string
|
101
|
-
* *style*: :none, :continuous, :dash, :dot, :dash_dot, :dash_dot_dot, default: :continuous
|
102
|
-
* *weight*: :hairline, :thin, :medium, :thick, default: :thin
|
103
|
-
|
104
|
-
=== Xmlss::Style::Font
|
105
|
-
* *bold*: bool, default: false
|
106
|
-
* *color*: hex string
|
107
|
-
* *name*: string
|
108
|
-
* *italic*: bool, default: false
|
109
|
-
* *size*: int
|
110
|
-
* *strike_through*: bool, default: false
|
111
|
-
* *shadow*: bool, default: false
|
112
|
-
* *underline*: :single, :double, :single_accounting, :double_accounting
|
113
|
-
* *alignment*: :subscript, :superscript
|
114
|
-
|
115
|
-
=== Xmlss::Style::Interior
|
116
|
-
* *color*: hex string
|
117
|
-
* *pattern*: symbol (see code for options), default: :default
|
118
|
-
* *pattern_color*: hex string
|
119
|
-
|
120
|
-
=== Xmlss::Style::NumberFormat
|
121
|
-
* *format*: :symbol (there are MANY different options for this, I suggest saving a spreadsheet in the XML format and seeing what Excel uses)
|
122
|
-
|
123
|
-
=== Xmlss::Style::Protection
|
124
|
-
* *protected*: bool, default: false
|
125
|
-
|
126
|
-
|
127
|
-
== For More Info
|
128
162
|
* Full XML Spreadsheet spec: http://msdn.microsoft.com/en-us/library/aa140066(office.10).aspx
|
129
163
|
|
130
164
|
== License
|
131
165
|
|
132
|
-
Copyright (c) 2011 Kelly D. Redding
|
166
|
+
Copyright (c) 2011-Present, Kelly D. Redding
|
133
167
|
|
134
168
|
Permission is hereby granted, free of charge, to any person
|
135
169
|
obtaining a copy of this software and associated documentation
|
data/Rakefile
CHANGED
@@ -4,4 +4,27 @@ include Assert::RakeTasks
|
|
4
4
|
require 'bundler'
|
5
5
|
Bundler::GemHelper.install_tasks
|
6
6
|
|
7
|
-
task :default => :
|
7
|
+
task :default => :run_all
|
8
|
+
|
9
|
+
desc "Run the example workbook builds."
|
10
|
+
task :run_examples do
|
11
|
+
require 'examples/simple'
|
12
|
+
require 'examples/layout'
|
13
|
+
require 'examples/text'
|
14
|
+
require 'examples/styles'
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the profiler on 1000 rows."
|
18
|
+
task :run_profiler do
|
19
|
+
require 'bench/profiler_runner'
|
20
|
+
|
21
|
+
runner = XmlssProfilerRunner.new(1000)
|
22
|
+
runner.print_flat(STDOUT, :min_percent => 3)
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Run all the tests, then the example builds, then the profiler."
|
26
|
+
task :run_all do
|
27
|
+
Rake::Task['test'].invoke
|
28
|
+
Rake::Task['run_examples'].invoke
|
29
|
+
Rake::Task['run_profiler'].invoke
|
30
|
+
end
|
data/bench/profiler.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'ruby-prof'
|
2
|
+
require 'xmlss'
|
3
|
+
|
4
|
+
class XmlssProfilerRunner
|
5
|
+
|
6
|
+
attr_reader :result
|
7
|
+
|
8
|
+
def initialize(n)
|
9
|
+
build = Proc.new do
|
10
|
+
worksheet("5 columns, #{n} rows") {
|
11
|
+
column
|
12
|
+
column
|
13
|
+
column
|
14
|
+
column
|
15
|
+
column
|
16
|
+
|
17
|
+
n.times do |i|
|
18
|
+
row {
|
19
|
+
# put data into the row (infer type)
|
20
|
+
[1, "text", 123.45, "0001267", "$45.23"].each do |data_value|
|
21
|
+
cell { data data_value }
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
@result = RubyProf.profile do
|
29
|
+
Xmlss::Workbook.new(:output => {:pp => 2}, &build).to_file("./bench/profiler_#{n}.xml")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def print_flat(outstream, opts={})
|
35
|
+
RubyProf::FlatPrinter.new(@result).print(outstream, opts)
|
36
|
+
#RubyProf::GraphPrinter.new(@result).print(outstream, opts)
|
37
|
+
end
|
38
|
+
|
39
|
+
def print_graph(outstream, opts={})
|
40
|
+
RubyProf::GraphPrinter.new(@result).print(outstream, opts)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -1,19 +1,15 @@
|
|
1
|
-
require '
|
2
|
-
require 'test/env'
|
1
|
+
require 'xmlss'
|
3
2
|
|
4
3
|
class ExampleWorkbook < Xmlss::Workbook
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
puts "Building #{self.name}.xml..."
|
8
|
-
build
|
9
|
-
end
|
10
4
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
def initialize(name, &build)
|
6
|
+
puts "Building #{name} workbook xml..."
|
7
|
+
|
8
|
+
super(:output => {:pp => 2}, &build)
|
9
|
+
self.to_file("./examples/#{name}.xml")
|
10
|
+
|
16
11
|
puts "... ready - open in Excel or whatever..."
|
17
12
|
end
|
13
|
+
|
18
14
|
end
|
19
15
|
|
data/examples/layout.rb
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
require 'examples/example_workbook'
|
2
2
|
|
3
|
-
|
4
|
-
def name; "layout"; end
|
5
|
-
def build
|
6
|
-
wksht = Xmlss::Worksheet.new('first')
|
7
|
-
4.times do
|
8
|
-
wksht.table.columns << Xmlss::Column.new
|
9
|
-
end
|
3
|
+
# $ bundle exec ruby examples/layout.rb
|
10
4
|
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
ExampleWorkbook.new("layout") do
|
6
|
+
|
7
|
+
worksheet('first') {
|
14
8
|
|
15
9
|
# | A | B | C | D |
|
16
10
|
# 1| x | x | x | x |
|
@@ -19,63 +13,43 @@ class Layout < ExampleWorkbook
|
|
19
13
|
# 4| x | x | x |
|
20
14
|
# 5| x | | x |
|
21
15
|
|
16
|
+
4.times { column }
|
17
|
+
|
22
18
|
# row 1: one cell per column
|
23
|
-
|
24
|
-
|
25
|
-
:index => i+1
|
26
|
-
|
27
|
-
|
28
|
-
end
|
19
|
+
row {
|
20
|
+
4.times do |i|
|
21
|
+
cell(:index => i+1) { data "x" }
|
22
|
+
end
|
23
|
+
}
|
29
24
|
|
30
25
|
# row 2: first cell colspan=2
|
31
|
-
|
32
|
-
:index => 1,
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
wksht.table.rows[1].cells << Xmlss::Cell.new({
|
38
|
-
:index => i+3,
|
39
|
-
:data => Xmlss::Data.new("x")
|
40
|
-
})
|
41
|
-
end
|
26
|
+
row {
|
27
|
+
cell(:index => 1, :merge_across => 1) { data "x" }
|
28
|
+
2.times do |i|
|
29
|
+
cell(:index => i+3) { data "x" }
|
30
|
+
end
|
31
|
+
}
|
42
32
|
|
43
33
|
# row 3,4,5: more complex merging
|
44
34
|
# => row 3
|
45
|
-
|
46
|
-
:
|
47
|
-
:index => 1
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
:merge_across => 1,
|
52
|
-
:merge_down => 2,
|
53
|
-
:index => 2
|
54
|
-
})
|
55
|
-
wksht.table.rows[2].cells << Xmlss::Cell.new({
|
56
|
-
:data => Xmlss::Data.new("x"),
|
57
|
-
:index => 4
|
58
|
-
})
|
35
|
+
row {
|
36
|
+
cell(:index => 1) { data "x" }
|
37
|
+
cell(:index => 2, :merge_across => 1, :merge_down => 2) { data "x" }
|
38
|
+
cell(:index => 4) { data "x" }
|
39
|
+
}
|
40
|
+
|
59
41
|
# => row 4
|
60
|
-
|
61
|
-
:
|
62
|
-
:index =>
|
63
|
-
}
|
64
|
-
|
65
|
-
:data => Xmlss::Data.new("x"),
|
66
|
-
:index => 4
|
67
|
-
})
|
42
|
+
row {
|
43
|
+
cell(:index => 1) { data "x" }
|
44
|
+
cell(:index => 4) { data "x" }
|
45
|
+
}
|
46
|
+
|
68
47
|
# => row 5
|
69
|
-
|
70
|
-
:
|
71
|
-
:index =>
|
72
|
-
}
|
73
|
-
|
74
|
-
|
75
|
-
:index => 4
|
76
|
-
})
|
48
|
+
row {
|
49
|
+
cell(:index => 1) { data "x" }
|
50
|
+
cell(:index => 4) { data "x" }
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|
77
54
|
|
78
|
-
self.worksheets << wksht
|
79
|
-
end
|
80
55
|
end
|
81
|
-
Layout.new.to_file
|
data/examples/layout.xml
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
|
3
|
+
<Styles>
|
4
|
+
</Styles>
|
5
|
+
|
6
|
+
<Worksheet ss:Name="first">
|
7
|
+
<Table>
|
8
|
+
<Column />
|
9
|
+
<Column />
|
10
|
+
<Column />
|
11
|
+
<Column />
|
12
|
+
<Row>
|
13
|
+
<Cell ss:Index="1">
|
14
|
+
<Data ss:Type="String">x</Data>
|
15
|
+
</Cell>
|
16
|
+
<Cell ss:Index="2">
|
17
|
+
<Data ss:Type="String">x</Data>
|
18
|
+
</Cell>
|
19
|
+
<Cell ss:Index="3">
|
20
|
+
<Data ss:Type="String">x</Data>
|
21
|
+
</Cell>
|
22
|
+
<Cell ss:Index="4">
|
23
|
+
<Data ss:Type="String">x</Data>
|
24
|
+
</Cell>
|
25
|
+
</Row>
|
26
|
+
<Row>
|
27
|
+
<Cell ss:Index="1" ss:MergeAcross="1">
|
28
|
+
<Data ss:Type="String">x</Data>
|
29
|
+
</Cell>
|
30
|
+
<Cell ss:Index="3">
|
31
|
+
<Data ss:Type="String">x</Data>
|
32
|
+
</Cell>
|
33
|
+
<Cell ss:Index="4">
|
34
|
+
<Data ss:Type="String">x</Data>
|
35
|
+
</Cell>
|
36
|
+
</Row>
|
37
|
+
<Row>
|
38
|
+
<Cell ss:Index="1">
|
39
|
+
<Data ss:Type="String">x</Data>
|
40
|
+
</Cell>
|
41
|
+
<Cell ss:Index="2" ss:MergeAcross="1" ss:MergeDown="2">
|
42
|
+
<Data ss:Type="String">x</Data>
|
43
|
+
</Cell>
|
44
|
+
<Cell ss:Index="4">
|
45
|
+
<Data ss:Type="String">x</Data>
|
46
|
+
</Cell>
|
47
|
+
</Row>
|
48
|
+
<Row>
|
49
|
+
<Cell ss:Index="1">
|
50
|
+
<Data ss:Type="String">x</Data>
|
51
|
+
</Cell>
|
52
|
+
<Cell ss:Index="4">
|
53
|
+
<Data ss:Type="String">x</Data>
|
54
|
+
</Cell>
|
55
|
+
</Row>
|
56
|
+
<Row>
|
57
|
+
<Cell ss:Index="1">
|
58
|
+
<Data ss:Type="String">x</Data>
|
59
|
+
</Cell>
|
60
|
+
<Cell ss:Index="4">
|
61
|
+
<Data ss:Type="String">x</Data>
|
62
|
+
</Cell>
|
63
|
+
</Row>
|
64
|
+
</Table>
|
65
|
+
</Worksheet>
|
66
|
+
</Workbook>
|
data/examples/simple.rb
CHANGED
@@ -1,30 +1,25 @@
|
|
1
1
|
require 'examples/example_workbook'
|
2
2
|
|
3
|
-
|
4
|
-
def name; "simple"; end
|
5
|
-
def build
|
3
|
+
# $ bundle exec ruby examples/simple.rb
|
6
4
|
|
7
|
-
|
8
|
-
|
5
|
+
# create a workbook with 1 row and 5 columns
|
6
|
+
ExampleWorkbook.new("simple") do
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
worksheet('1 row, 5 columns') {
|
9
|
+
column
|
10
|
+
column
|
11
|
+
column
|
12
|
+
column
|
13
|
+
column
|
15
14
|
|
16
|
-
|
15
|
+
row {
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
})
|
23
|
-
end
|
17
|
+
# put data into the row (infer type)
|
18
|
+
[1, "text", 123.45, "0001267", "$45.23"].each do |data_value|
|
19
|
+
cell { data data_value }
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
22
|
+
}
|
23
|
+
}
|
27
24
|
|
28
|
-
end
|
29
25
|
end
|
30
|
-
Simple.new.to_file(:format)
|