spreadshoot 0.0.3 → 0.0.4

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.
data/examples/basic.rb CHANGED
@@ -9,7 +9,7 @@ spreadsheet = Spreadshoot.new do |s|
9
9
  @foo = r.cell 2
10
10
  end
11
11
  w.row do |r|
12
- r.cell Date.today + 1
12
+ r.cell Time.now
13
13
  r.cell 'bar', :font => 'Times New Roman'
14
14
  @bar = r.cell 3
15
15
  end
@@ -80,6 +80,45 @@ spreadsheet = Spreadshoot.new do |s|
80
80
  end
81
81
  end
82
82
  end
83
+
84
+ s.worksheet('Relative positioned tables') do |w|
85
+ t1 = w.table do |t|
86
+ 3.times do
87
+ t.row do |r|
88
+ 4.times do
89
+ r.cell(1)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ w.table(:next_to => t1) do |t|
95
+ 5.times do
96
+ t.row do |r|
97
+ 2.times do
98
+ r.cell(2)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ t3 = w.table do |t|
104
+ 4.times do
105
+ t.row do |r|
106
+ 5.times do
107
+ r.cell(3)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ w.table(:next_to => t3) do |t|
113
+ 2.times do
114
+ t.row do |r|
115
+ 2.times do
116
+ r.cell(4)
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
83
122
  end
84
123
 
85
124
  spreadsheet.dump
@@ -1,3 +1,3 @@
1
- module Spreadshoot
2
- VERSION = "0.0.3"
1
+ class Spreadshoot
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/spreadshoot.rb CHANGED
@@ -248,6 +248,7 @@ class Spreadshoot
248
248
  end
249
249
  end
250
250
 
251
+ # Outputs XML describing spreadsheet styles.
251
252
  def styles
252
253
  Builder::XmlMarkup.new.styleSheet(:xmlns => "http://schemas.openxmlformats.org/spreadsheetml/2006/main") do |xs|
253
254
  xs.fonts do |xf|
@@ -320,6 +321,7 @@ class Spreadshoot
320
321
  end
321
322
  end
322
323
 
324
+ # Single worksheet containing one or more tables.
323
325
  class Worksheet
324
326
  # <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" >
325
327
  # <sheetData>
@@ -332,7 +334,9 @@ class Spreadshoot
332
334
  # </worksheet>
333
335
 
334
336
  attr_reader :title, :xml, :spreadsheet, :row_index, :col_index, :cells
335
- def initialize spreadsheet, title, options = {}, &block
337
+
338
+ # Not intended to be called directly. Use Spreadshoot#worksheet to create a worksheet.
339
+ def initialize spreadsheet, title, options = {}
336
340
  @cells = {}
337
341
  @spreadsheet = spreadsheet
338
342
  @title = title
@@ -346,7 +350,7 @@ class Spreadshoot
346
350
  yield self
347
351
  end
348
352
 
349
- # outputs the worksheet as OOXML
353
+ # Outputs the worksheet as OOXML
350
354
  def to_s
351
355
  @xml ||= Builder::XmlMarkup.new.worksheet(:xmlns => "http://schemas.openxmlformats.org/spreadsheetml/2006/main") do |ws|
352
356
  unless @column_widths.empty?
@@ -373,21 +377,34 @@ class Spreadshoot
373
377
  end
374
378
  end
375
379
 
380
+ # Creates a row within a worksheet.
381
+ #
382
+ # @param [Hash] options options to create a row with.
383
+ # @return created row
376
384
  def row options = {}, &block
377
385
  row = @current_table.row options, &block
378
386
  @row_index += 1
379
387
  row
380
388
  end
381
389
 
390
+ # Creates a table within a worksheet.
391
+ #
392
+ # @param [Hash] options Options to initialize table with.
393
+ # @option options [Symbol] :direction (:vertical) Orientation of the table (could be :horizontal or :vertical)
394
+ # @option options [Table] :next_to Optionally, place the table to the right of the already existing table
395
+ # @option options [Fixnum] :row_topleft Place the tables top left corner absolutely to a certain row
396
+ # @option options [Fixnum] :col_topleft Place the tables top left corner absolutely to a certain column
397
+ # @return [Table] created table
382
398
  def table options = {}
383
399
  @current_table = table = Table.new(self, options)
384
400
  yield table
385
- @row_index += table.row_max
401
+ @row_index = [@row_index, table.row_topleft + table.row_max].max
386
402
  @col_index = 0
387
403
  @current_table = Table.new(self, @options) # preparing one in case row directly called next
388
404
  table
389
405
  end
390
406
 
407
+ # Not intended to be used directly.
391
408
  def set_col_width col, width
392
409
  @column_widths[col] = width
393
410
  end
@@ -397,7 +414,7 @@ class Spreadshoot
397
414
  # Allows you to group cells to a logical table within a worksheet. Makes putting several tables
398
415
  # to the same worksheet easier.
399
416
  class Table
400
- attr_reader :worksheet, :direction, :col_max, :row_max, :col_index, :row_index
417
+ attr_reader :worksheet, :direction, :col_max, :row_max, :col_index, :row_index, :row_topleft, :col_topleft
401
418
 
402
419
  def initialize worksheet, options = {}
403
420
  @worksheet = worksheet
@@ -409,6 +426,11 @@ class Spreadshoot
409
426
  @col_max = 0
410
427
  @row_topleft = options[:row_topleft] || @worksheet.row_index
411
428
  @col_topleft = options[:col_topleft] || @worksheet.col_index
429
+
430
+ if tbl = options[:next_to]
431
+ @row_topleft = tbl.row_topleft
432
+ @col_topleft = tbl.col_topleft + tbl.col_max
433
+ end
412
434
  end
413
435
 
414
436
  def col_index= val
@@ -511,8 +533,10 @@ class Spreadshoot
511
533
  xn_parent.c(r) do |xc|
512
534
  xc.f(@options[:formula])
513
535
  end
514
- when Date, Time
536
+ when Date
515
537
  xn_parent.c(r){|xc| xc.v((@value - Date.new(1899,12,30)).to_i)}
538
+ when Time
539
+ xn_parent.c(r){|xc| xc.v((@value - Time.new(1899,12,30)) / (24*60*60))}
516
540
  when nil
517
541
  xn_parent.c(r)
518
542
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadshoot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-04 00:00:00.000000000 Z
12
+ date: 2012-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
16
- requirement: &83815620 !ruby/object:Gem::Requirement
16
+ requirement: &80585380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *83815620
24
+ version_requirements: *80585380
25
25
  description: Create XLSX files from scratch using Ruby
26
26
  email:
27
27
  - jablan@radioni.ca
@@ -63,3 +63,4 @@ signing_key:
63
63
  specification_version: 3
64
64
  summary: Ruby DSL for creating Excel xlsx spreadsheets
65
65
  test_files: []
66
+ has_rdoc: