xmlss 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +1 -2
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +12 -11
  4. data/README.rdoc +141 -107
  5. data/Rakefile +24 -1
  6. data/bench/profiler.rb +6 -0
  7. data/bench/profiler_runner.rb +43 -0
  8. data/examples/example_workbook.rb +8 -12
  9. data/examples/layout.rb +34 -60
  10. data/examples/layout.xml +66 -0
  11. data/examples/simple.rb +16 -21
  12. data/examples/simple.xml +32 -0
  13. data/examples/styles.rb +52 -56
  14. data/examples/styles.xml +50 -0
  15. data/examples/text.rb +18 -28
  16. data/examples/text.xml +20 -0
  17. data/lib/xmlss/{cell.rb → element/cell.rb} +4 -14
  18. data/lib/xmlss/{column.rb → element/column.rb} +2 -7
  19. data/lib/xmlss/{data.rb → element/data.rb} +7 -12
  20. data/lib/xmlss/{row.rb → element/row.rb} +2 -13
  21. data/lib/xmlss/{worksheet.rb → element/worksheet.rb} +7 -18
  22. data/lib/xmlss/style/alignment.rb +3 -10
  23. data/lib/xmlss/style/base.rb +6 -45
  24. data/lib/xmlss/style/border.rb +5 -5
  25. data/lib/xmlss/style/font.rb +2 -9
  26. data/lib/xmlss/style/interior.rb +2 -5
  27. data/lib/xmlss/style/number_format.rb +4 -7
  28. data/lib/xmlss/style/protection.rb +4 -7
  29. data/lib/xmlss/undies_writer.rb +172 -0
  30. data/lib/xmlss/version.rb +1 -1
  31. data/lib/xmlss/workbook.rb +97 -31
  32. data/lib/xmlss.rb +1 -28
  33. data/test/{cell_test.rb → element/cell_test.rb} +11 -35
  34. data/test/{column_test.rb → element/column_test.rb} +6 -12
  35. data/test/{data_test.rb → element/data_test.rb} +15 -10
  36. data/test/{row_test.rb → element/row_test.rb} +5 -35
  37. data/test/{worksheet_test.rb → element/worksheet_test.rb} +4 -30
  38. data/test/helper.rb +13 -30
  39. data/test/style/alignment_test.rb +13 -45
  40. data/test/style/base_test.rb +1 -106
  41. data/test/style/border_test.rb +12 -32
  42. data/test/style/font_test.rb +11 -43
  43. data/test/style/interior_test.rb +7 -27
  44. data/test/style/number_format_test.rb +5 -21
  45. data/test/style/protection_test.rb +2 -12
  46. data/test/undies_writer_test.rb +333 -0
  47. data/test/workbook_test.rb +89 -44
  48. data/xmlss.gemspec +2 -2
  49. metadata +37 -39
  50. data/lib/xmlss/item_set.rb +0 -17
  51. data/lib/xmlss/table.rb +0 -22
  52. data/lib/xmlss/xml.rb +0 -60
  53. data/test/item_set_test.rb +0 -27
  54. data/test/table_test.rb +0 -56
  55. data/test/xml_test.rb +0 -81
  56. data/test/xmlss_test.rb +0 -31
data/.gitignore CHANGED
@@ -2,5 +2,4 @@ pkg/*
2
2
  .bundle
3
3
  *.gem
4
4
  *.log
5
- *.xml
6
-
5
+ bench/*.xml
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source "http://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem 'rake', '~>0.9.2'
7
+ gem 'ruby-prof'
data/Gemfile.lock CHANGED
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xmlss (0.3.1)
5
- enumeration (~> 1.2)
6
- nokogiri (~> 1.4)
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.3.0)
12
- assert (0.6.0)
13
- assert-view (~> 0.3)
14
- assert-view (0.3.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 (~> 1.1)
17
- enumeration (1.2.1)
18
- nokogiri (1.5.0)
16
+ undies (~> 2.0)
17
+ enumeration (1.3.1)
19
18
  rake (0.9.2)
20
- undies (1.1.0)
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
- == Description
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::Workbook.new
18
- workbook.worksheets # => []
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
- sheet1 = Xmlss::Worksheet.new({
21
- :name => 'Sheet 1'
22
- })
23
- sheet1.table = Xmlss::Table.new
24
- sheet1.table.rows # => []
107
+ == Usage
25
108
 
26
- row1 = Xmlss::Row.new(1, 'some data', 54.54)
27
- row1.cells.count = 3
28
- row1.cells.first.data # => 1
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
- sheet1.table.rows << row1
31
- workbook.worksheets << sheet1
113
+ === Data option
32
114
 
33
- workbook.to_xml # => "..." (XML Spreadsheet xml string)
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
- == Usage
36
- see the examples folder for some use case examples.
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 => :build
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,6 @@
1
+ # $ bundle exec ruby bench/profiler.rb
2
+
3
+ require 'bench/profiler_runner'
4
+
5
+ runner = XmlssProfilerRunner.new(ARGV[0] ? ARGV[0].to_i : 1000)
6
+ runner.print_flat(STDOUT, :min_percent => 1)
@@ -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 'rubygems'
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 to_file(*options)
12
- # write this workbooks xml data to a file
13
- File.open("examples/#{self.name}.xml", "w") do |file|
14
- file.write self.to_xml(*options)
15
- end
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
- class Layout < ExampleWorkbook
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
- 5.times do
12
- wksht.table.rows << Xmlss::Row.new
13
- end
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
- 4.times do |i|
24
- wksht.table.rows[0].cells << Xmlss::Cell.new({
25
- :index => i+1,
26
- :data => Xmlss::Data.new("x")
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
- wksht.table.rows[1].cells << Xmlss::Cell.new({
32
- :index => 1,
33
- :data => Xmlss::Data.new("x"),
34
- :merge_across => 1
35
- })
36
- 2.times do |i|
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
- wksht.table.rows[2].cells << Xmlss::Cell.new({
46
- :data => Xmlss::Data.new("x"),
47
- :index => 1
48
- })
49
- wksht.table.rows[2].cells << Xmlss::Cell.new({
50
- :data => Xmlss::Data.new("x"),
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
- wksht.table.rows[3].cells << Xmlss::Cell.new({
61
- :data => Xmlss::Data.new("x"),
62
- :index => 1
63
- })
64
- wksht.table.rows[3].cells << Xmlss::Cell.new({
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
- wksht.table.rows[4].cells << Xmlss::Cell.new({
70
- :data => Xmlss::Data.new("x"),
71
- :index => 1
72
- })
73
- wksht.table.rows[4].cells << Xmlss::Cell.new({
74
- :data => Xmlss::Data.new("x"),
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
@@ -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
- class Simple < ExampleWorkbook
4
- def name; "simple"; end
5
- def build
3
+ # $ bundle exec ruby examples/simple.rb
6
4
 
7
- # add 1 row of simple data across 3 columns
8
- wksht = Xmlss::Worksheet.new('1 row, 3 columns')
5
+ # create a workbook with 1 row and 5 columns
6
+ ExampleWorkbook.new("simple") do
9
7
 
10
- wksht.table.columns << Xmlss::Column.new
11
- wksht.table.columns << Xmlss::Column.new
12
- wksht.table.columns << Xmlss::Column.new
13
- wksht.table.columns << Xmlss::Column.new
14
- wksht.table.columns << Xmlss::Column.new
8
+ worksheet('1 row, 5 columns') {
9
+ column
10
+ column
11
+ column
12
+ column
13
+ column
15
14
 
16
- row1 = Xmlss::Row.new
15
+ row {
17
16
 
18
- # put data into the row (infer type)
19
- [1, "text", 123.45, "0001267", "$45.23"].each do |data|
20
- row1.cells << Xmlss::Cell.new({
21
- :data => Xmlss::Data.new(data)
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
- wksht.table.rows << row1
26
- self.worksheets << wksht
22
+ }
23
+ }
27
24
 
28
- end
29
25
  end
30
- Simple.new.to_file(:format)