osheet 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- osheet (0.9.0)
4
+ osheet (0.9.1)
5
5
  enumeration (~> 1.2)
6
6
  xmlss (~> 0.2)
7
7
 
@@ -0,0 +1,39 @@
1
+ # To run:
2
+ # $ bundle install
3
+ # $ bundle exec ruby examples/formula.rb
4
+ # $ open examples/formula.xls
5
+
6
+ require 'rubygems'
7
+ require 'osheet'
8
+
9
+
10
+ # this will dump the above data to a single-sheet workbook w/ no styles
11
+
12
+ Osheet::Workbook.new {
13
+ title "formula example"
14
+ worksheet {
15
+ name "Formula"
16
+ row {
17
+ cell { data 1 }
18
+ cell { data 2 }
19
+ # please note formulas use R1C1 notation
20
+ # check out for example http://www.bettersolutions.com/excel/EED883/YI416010881.htm
21
+ # this is absolute reference, ie. =$A$1+$B$1
22
+ cell { formula "=R1C1+R1C2" }
23
+ }
24
+ }
25
+ worksheet {
26
+ name "Refers to previous sheet"
27
+ row {
28
+ cell { data 3 }
29
+ cell { data 4 }
30
+ cell {
31
+ # you can still refer to cells in other sheets through the name of the sheet and !
32
+ # this is also a relative reference, ie. =Formula!A1+B2
33
+ formula "=Formula!RC[-2]+RC[-1]"
34
+ # 6 will change into 5 when formula gets recalculated
35
+ data 6
36
+ }
37
+ }
38
+ }
39
+ }.to_file('examples/formula.xls')
@@ -18,6 +18,7 @@ module Osheet
18
18
  set_ivar(:colspan, 1)
19
19
  set_ivar(:href, nil)
20
20
  set_ivar(:index, nil)
21
+ set_ivar(:formula, nil)
21
22
  if block_given?
22
23
  set_binding_ivars(block.binding)
23
24
  instance_exec(*args, &block)
@@ -43,6 +44,7 @@ module Osheet
43
44
  def colspan(value); set_ivar(:colspan, value); end
44
45
  def href(value); set_ivar(:href, value); end
45
46
  def index(value); set_ivar(:index, value); end
47
+ def formula(value); set_ivar(:formula, value); end
46
48
 
47
49
  def attributes
48
50
  {
@@ -52,7 +54,8 @@ module Osheet
52
54
  :colspan => get_ivar(:colspan),
53
55
  :rowspan => get_ivar(:rowspan),
54
56
  :href => get_ivar(:href),
55
- :index => get_ivar(:index)
57
+ :index => get_ivar(:index),
58
+ :formula => get_ivar(:formula)
56
59
  }
57
60
  end
58
61
 
@@ -1,3 +1,3 @@
1
1
  module Osheet
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -56,7 +56,8 @@ module Osheet::XmlssWriter::Elements
56
56
  :index => ocell.attributes[:index],
57
57
  :merge_across => cell_merge(ocell.attributes[:colspan]),
58
58
  :merge_down => cell_merge(ocell.attributes[:rowspan]),
59
- :data => data(ocell.attributes[:data])
59
+ :data => data(ocell.attributes[:data]),
60
+ :formula => ocell.attributes[:formula]
60
61
  })
61
62
  end
62
63
  def cell_merge(span)
@@ -21,6 +21,7 @@ module Osheet
21
21
  assert_equal 1, subject.send(:get_ivar, "rowspan")
22
22
  assert_equal nil, subject.send(:get_ivar, "href")
23
23
  assert_equal nil, subject.send(:get_ivar, "index")
24
+ assert_equal nil, subject.send(:get_ivar, "formuala")
24
25
  end
25
26
 
26
27
  should "type cast data strings/symbols" do
@@ -61,6 +62,7 @@ module Osheet
61
62
  colspan 4
62
63
  rowspan 2
63
64
  index 3
65
+ formula "=R1C1"
64
66
  href "http://www.google.com"
65
67
  end
66
68
  end
@@ -68,9 +70,10 @@ module Osheet
68
70
  should "should set them correctly" do
69
71
  assert_equal "Poo", subject.send(:get_ivar, "data")
70
72
  assert_kind_of Format::Number, subject.send(:get_ivar, "format")
71
- assert_equal 4, subject.send(:get_ivar, "colspan")
72
- assert_equal 2, subject.send(:get_ivar, "rowspan")
73
- assert_equal 3, subject.send(:get_ivar, "index")
73
+ assert_equal 4, subject.send(:get_ivar, "colspan")
74
+ assert_equal 2, subject.send(:get_ivar, "rowspan")
75
+ assert_equal 3, subject.send(:get_ivar, "index")
76
+ assert_equal "=R1C1", subject.send(:get_ivar, "formula")
74
77
  assert_equal "http://www.google.com", subject.send(:get_ivar, "href")
75
78
  end
76
79
 
@@ -85,6 +88,7 @@ module Osheet
85
88
  assert_equal 4, subject.attributes[:colspan]
86
89
  assert_equal 2, subject.attributes[:rowspan]
87
90
  assert_equal 3, subject.attributes[:index]
91
+ assert_equal "=R1C1", subject.attributes[:formula]
88
92
  assert_equal "http://www.google.com", subject.attributes[:href]
89
93
  end
90
94
 
@@ -132,6 +132,7 @@ module Osheet
132
132
  rowspan 2
133
133
  colspan 5
134
134
  index 3
135
+ formula "=R1C1"
135
136
  end
136
137
  subject.workbook = Workbook.new {
137
138
  style('.awesome') {
@@ -154,6 +155,7 @@ module Osheet
154
155
  assert_equal ::Xmlss::Data.type(:number), @xmlss_cell.data.type
155
156
  assert_equal 'http://example.com', @xmlss_cell.href
156
157
  assert_equal 3, @xmlss_cell.index
158
+ assert_equal "=R1C1", @xmlss_cell.formula
157
159
  end
158
160
 
159
161
  should "handle rowspan and colspan" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osheet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 0
10
- version: 0.9.0
9
+ - 1
10
+ version: 0.9.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-28 00:00:00 Z
18
+ date: 2011-11-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :development
@@ -95,6 +95,7 @@ files:
95
95
  - examples/basic.rb
96
96
  - examples/basic_with_templates.rb
97
97
  - examples/formats.rb
98
+ - examples/formula.rb
98
99
  - examples/styles.rb
99
100
  - examples/trivial.rb
100
101
  - lib/osheet.rb