jruby-poi 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/writing_spec.rb CHANGED
@@ -1,146 +1,144 @@
1
- require 'spec_helper'
2
-
3
- require 'date'
4
- require 'stringio'
5
-
6
- describe "writing Workbooks" do
7
- it "should create a new empty workbook" do
8
- name = 'new-workbook.xlsx'
9
- book = POI::Workbook.create(name)
10
- book.should_not be_nil
11
- end
12
-
13
- it "should create a new workbook and write something to it" do
14
- name = "spec/data/timesheet-#{Time.now.strftime('%Y%m%d%H%M%S%s')}.xlsx"
15
- create_timesheet_spreadsheet(name)
16
- book = POI::Workbook.open(name)
17
- book.worksheets.size.should == 1
18
- book.worksheets[0].name.should == 'Timesheet'
19
- book.filename.should == name
20
- book['Timesheet!A3'].should == 'Yegor Kozlov'
21
- book.cell('Timesheet!J13').formula_value.should == 'SUM(J3:J12)'
22
- FileUtils.rm_f name
23
- end
24
-
25
- def create_timesheet_spreadsheet name='spec/data/timesheet.xlsx'
26
- titles = ["Person", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Total\nHrs", "Overtime\nHrs", "Regular\nHrs"]
27
- sample_data = [
28
- ["Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0],
29
- ["Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, nil, nil, 4.0]
30
- ]
31
-
32
- book = POI::Workbook.create(name)
33
- title_style = book.create_style :font_height_in_points => 18, :boldweight => :boldweight_bold,
34
- :alignment => :align_center, :vertical_alignment => :vertical_center
35
- header_style = book.create_style :font_height_in_points => 11, :color => :white, :fill_foreground_color => :grey_50_percent,
36
- :fill_pattern => :solid_foreground, :alignment => :align_center, :vertical_alignment => :vertical_center
37
- cell_style = book.create_style :alignment => :align_center, :border_bottom => :border_thin, :border_top => :border_thin,
38
- :border_left => :border_thin, :border_right => :border_thin, :bottom_border_color => :black,
39
- :right_border_color => :black, :left_border_color => :black, :top_border_color => :black
40
- form1_style = book.create_style :data_format => '0.00', :fill_pattern => :solid_foreground, :fill_foreground_color => :grey_25_percent,
41
- :alignment => :align_center, :vertical_alignment => :vertical_center
42
- form2_style = book.create_style :data_format => '0.00', :fill_pattern => :solid_foreground, :fill_foreground_color => :grey_40_percent,
43
- :alignment => :align_center, :vertical_alignment => :vertical_center
44
-
45
- sheet = book.create_sheet 'Timesheet'
46
- print_setup = sheet.print_setup
47
- print_setup.landscape = true
48
- sheet.fit_to_page = true
49
- sheet.horizontally_center = true
50
-
51
- title_row = sheet.rows[0]
52
- title_row.height_in_points = 45
53
- title_cell = title_row.cells[0]
54
- title_cell.value = 'Weekly Timesheet'
55
- title_cell.style = title_style
56
- sheet.add_merged_region org.apache.poi.ss.util.CellRangeAddress.valueOf("$A$1:$L$1")
57
-
58
- header_row = sheet[1]
59
- header_row.height_in_points = 40
60
- titles.each_with_index do | title, index |
61
- header_cell = header_row[index]
62
- header_cell.value = title
63
- header_cell.style = header_style
64
- end
65
-
66
- row_num = 2
67
- 10.times do
68
- row = sheet[row_num]
69
- row_num += 1
70
- titles.each_with_index do | title, index |
71
- cell = row[index]
72
- if index == 9
73
- cell.formula = "SUM(C#{row_num}:I#{row_num})"
74
- cell.style = form1_style
75
- elsif index == 11
76
- cell.formula = "J#{row_num} - K#{row_num}"
77
- cell.style = form1_style
78
- else
79
- cell.style = cell_style
80
- end
81
- end
82
- end
83
-
84
- # row with totals below
85
- sum_row = sheet[row_num]
86
- row_num += 1
87
- sum_row.height_in_points = 35
88
- cell = sum_row[0]
89
- cell.style = form1_style
90
- cell = sum_row[1]
91
- cell.style = form1_style
92
- cell.value = 'Total Hrs:'
93
- (2...12).each do | cell_index |
94
- cell = sum_row[cell_index]
95
- column = (?A + cell_index).chr
96
- cell.formula = "SUM(#{column}3:#{column}12)"
97
- if cell_index > 9
98
- cell.style = form2_style
99
- else
100
- cell.style = form1_style
101
- end
102
- end
103
- row_num += 1
104
- sum_row = sheet[row_num]
105
- row_num += 1
106
- sum_row.height_in_points = 25
107
- cell = sum_row[0]
108
- cell.value = 'Total Regular Hours'
109
- cell.style = form1_style
110
- cell = sum_row[1]
111
- cell.formula = 'L13'
112
- cell.style = form2_style
113
- sum_row = sheet[row_num]
114
- row_num += 1
115
- cell = sum_row[0]
116
- cell.value = 'Total Overtime Hours'
117
- cell.style = form1_style
118
- cell = sum_row[1]
119
- cell.formula = 'K13'
120
- cell.style = form2_style
121
-
122
- # set sample data
123
- sample_data.each_with_index do |each, row_index|
124
- row = sheet[2 + row_index]
125
- each.each_with_index do | data, cell_index |
126
- data = sample_data[row_index][cell_index]
127
- next unless data
128
- if data.kind_of? String
129
- row[cell_index].value = data #.to_java(:string)
130
- else
131
- row[cell_index].value = data #.to_java(:double)
132
- end
133
- end
134
- end
135
-
136
- # finally set column widths, the width is measured in units of 1/256th of a character width
137
- sheet.set_column_width 0, 30*256 # 30 characters wide
138
- (2..9).to_a.each do | column |
139
- sheet.set_column_width column, 6*256 # 6 characters wide
140
- end
141
- sheet.set_column_width 10, 10*256 # 10 characters wide
142
-
143
- book.save
144
- File.exist?(name).should == true
145
- end
146
- end
1
+ require 'date'
2
+ require 'stringio'
3
+
4
+ describe "writing Workbooks" do
5
+ it "should create a new empty workbook" do
6
+ name = 'new-workbook.xlsx'
7
+ book = POI::Workbook.create(name)
8
+ book.should_not be_nil
9
+ end
10
+
11
+ it "should create a new workbook and write something to it" do
12
+ name = TestDataFile.expand_path("timesheet-#{Time.now.strftime('%Y%m%d%H%M%S%s')}.xlsx")
13
+ create_timesheet_spreadsheet(name)
14
+ book = POI::Workbook.open(name)
15
+ book.worksheets.size.should == 1
16
+ book.worksheets[0].name.should == 'Timesheet'
17
+ book.filename.should == name
18
+ book['Timesheet!A3'].should == 'Yegor Kozlov'
19
+ book.cell('Timesheet!J13').formula_value.should == 'SUM(J3:J12)'
20
+ FileUtils.rm_f name
21
+ end
22
+
23
+ def create_timesheet_spreadsheet name='spec/data/timesheet.xlsx'
24
+ titles = ["Person", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Total\nHrs", "Overtime\nHrs", "Regular\nHrs"]
25
+ sample_data = [
26
+ ["Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0],
27
+ ["Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, nil, nil, 4.0]
28
+ ]
29
+
30
+ book = POI::Workbook.create(name)
31
+ title_style = book.create_style :font_height_in_points => 18, :boldweight => :boldweight_bold,
32
+ :alignment => :align_center, :vertical_alignment => :vertical_center
33
+ header_style = book.create_style :font_height_in_points => 11, :color => :white, :fill_foreground_color => :grey_50_percent,
34
+ :fill_pattern => :solid_foreground, :alignment => :align_center, :vertical_alignment => :vertical_center
35
+ cell_style = book.create_style :alignment => :align_center, :border_bottom => :border_thin, :border_top => :border_thin,
36
+ :border_left => :border_thin, :border_right => :border_thin, :bottom_border_color => :black,
37
+ :right_border_color => :black, :left_border_color => :black, :top_border_color => :black
38
+ form1_style = book.create_style :data_format => '0.00', :fill_pattern => :solid_foreground, :fill_foreground_color => :grey_25_percent,
39
+ :alignment => :align_center, :vertical_alignment => :vertical_center
40
+ form2_style = book.create_style :data_format => '0.00', :fill_pattern => :solid_foreground, :fill_foreground_color => :grey_40_percent,
41
+ :alignment => :align_center, :vertical_alignment => :vertical_center
42
+
43
+ sheet = book.create_sheet 'Timesheet'
44
+ print_setup = sheet.print_setup
45
+ print_setup.landscape = true
46
+ sheet.fit_to_page = true
47
+ sheet.horizontally_center = true
48
+
49
+ title_row = sheet.rows[0]
50
+ title_row.height_in_points = 45
51
+ title_cell = title_row.cells[0]
52
+ title_cell.value = 'Weekly Timesheet'
53
+ title_cell.style = title_style
54
+ sheet.add_merged_region org.apache.poi.ss.util.CellRangeAddress.valueOf("$A$1:$L$1")
55
+
56
+ header_row = sheet[1]
57
+ header_row.height_in_points = 40
58
+ titles.each_with_index do | title, index |
59
+ header_cell = header_row[index]
60
+ header_cell.value = title
61
+ header_cell.style = header_style
62
+ end
63
+
64
+ row_num = 2
65
+ 10.times do
66
+ row = sheet[row_num]
67
+ row_num += 1
68
+ titles.each_with_index do | title, index |
69
+ cell = row[index]
70
+ if index == 9
71
+ cell.formula = "SUM(C#{row_num}:I#{row_num})"
72
+ cell.style = form1_style
73
+ elsif index == 11
74
+ cell.formula = "J#{row_num} - K#{row_num}"
75
+ cell.style = form1_style
76
+ else
77
+ cell.style = cell_style
78
+ end
79
+ end
80
+ end
81
+
82
+ # row with totals below
83
+ sum_row = sheet[row_num]
84
+ row_num += 1
85
+ sum_row.height_in_points = 35
86
+ cell = sum_row[0]
87
+ cell.style = form1_style
88
+ cell = sum_row[1]
89
+ cell.style = form1_style
90
+ cell.value = 'Total Hrs:'
91
+ (2...12).each do | cell_index |
92
+ cell = sum_row[cell_index]
93
+ column = (?A.ord + cell_index).chr
94
+ cell.formula = "SUM(#{column}3:#{column}12)"
95
+ if cell_index > 9
96
+ cell.style = form2_style
97
+ else
98
+ cell.style = form1_style
99
+ end
100
+ end
101
+ row_num += 1
102
+ sum_row = sheet[row_num]
103
+ row_num += 1
104
+ sum_row.height_in_points = 25
105
+ cell = sum_row[0]
106
+ cell.value = 'Total Regular Hours'
107
+ cell.style = form1_style
108
+ cell = sum_row[1]
109
+ cell.formula = 'L13'
110
+ cell.style = form2_style
111
+ sum_row = sheet[row_num]
112
+ row_num += 1
113
+ cell = sum_row[0]
114
+ cell.value = 'Total Overtime Hours'
115
+ cell.style = form1_style
116
+ cell = sum_row[1]
117
+ cell.formula = 'K13'
118
+ cell.style = form2_style
119
+
120
+ # set sample data
121
+ sample_data.each_with_index do |each, row_index|
122
+ row = sheet[2 + row_index]
123
+ each.each_with_index do | data, cell_index |
124
+ data = sample_data[row_index][cell_index]
125
+ next unless data
126
+ if data.kind_of? String
127
+ row[cell_index].value = data #.to_java(:string)
128
+ else
129
+ row[cell_index].value = data #.to_java(:double)
130
+ end
131
+ end
132
+ end
133
+
134
+ # finally set column widths, the width is measured in units of 1/256th of a character width
135
+ sheet.set_column_width 0, 30*256 # 30 characters wide
136
+ (2..9).to_a.each do | column |
137
+ sheet.set_column_width column, 6*256 # 6 characters wide
138
+ end
139
+ sheet.set_column_width 10, 10*256 # 10 characters wide
140
+
141
+ book.save
142
+ File.exist?(name).should == true
143
+ end
144
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jruby-poi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.8.2
5
+ version: 0.9.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Scott Deming
@@ -11,8 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-22 00:00:00 -04:00
15
- default_executable:
14
+ date: 2012-10-15 00:00:00 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: rspec
@@ -21,7 +20,7 @@ dependencies:
21
20
  requirements:
22
21
  - - ">="
23
22
  - !ruby/object:Gem::Version
24
- version: 2.5.0
23
+ version: 2.11.0
25
24
  requirement: *id001
26
25
  prerelease: false
27
26
  type: :development
@@ -32,12 +31,12 @@ dependencies:
32
31
  requirements:
33
32
  - - ">="
34
33
  - !ruby/object:Gem::Version
35
- version: 1.6.0
34
+ version: 1.8.4
36
35
  requirement: *id002
37
36
  prerelease: false
38
37
  type: :development
39
38
  - !ruby/object:Gem::Dependency
40
- name: rcov
39
+ name: jruby-openssl
41
40
  version_requirements: &id003 !ruby/object:Gem::Requirement
42
41
  none: false
43
42
  requirements:
@@ -51,12 +50,8 @@ description: A rubyesque library for manipulating spreadsheets and other documen
51
50
  email:
52
51
  - sdeming@makefile.com
53
52
  - jacaetevha@gmail.com
54
- executables:
55
- - autospec
56
- - htmldiff
57
- - ldiff
58
- - rdebug
59
- - rspec
53
+ executables: []
54
+
60
55
  extensions: []
61
56
 
62
57
  extra_rdoc_files:
@@ -71,20 +66,16 @@ files:
71
66
  - README.markdown
72
67
  - Rakefile
73
68
  - VERSION
74
- - bin/autospec
75
- - bin/htmldiff
76
- - bin/ldiff
77
- - bin/rdebug
78
- - bin/rspec
79
69
  - jruby-poi.gemspec
80
70
  - lib/ooxml-lib/dom4j-1.6.1.jar
81
- - lib/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar
71
+ - lib/ooxml-lib/stax-api-1.0.1.jar
82
72
  - lib/ooxml-lib/xmlbeans-2.3.0.jar
83
- - lib/poi-3.7-20101029.jar
84
- - lib/poi-examples-3.7-20101029.jar
85
- - lib/poi-ooxml-3.7-20101029.jar
86
- - lib/poi-ooxml-schemas-3.7-20101029.jar
87
- - lib/poi-scratchpad-3.7-20101029.jar
73
+ - lib/poi-3.8-20120326.jar
74
+ - lib/poi-examples-3.8-20120326.jar
75
+ - lib/poi-excelant-3.8-20120326.jar
76
+ - lib/poi-ooxml-3.8-20120326.jar
77
+ - lib/poi-ooxml-schemas-3.8-20120326.jar
78
+ - lib/poi-scratchpad-3.8-20120326.jar
88
79
  - lib/poi.rb
89
80
  - lib/poi/workbook.rb
90
81
  - lib/poi/workbook/area.rb
@@ -107,7 +98,6 @@ files:
107
98
  - spec/workbook_spec.rb
108
99
  - spec/writing_spec.rb
109
100
  - spec_debug.sh
110
- has_rdoc: true
111
101
  homepage: http://github.com/kameeoze/jruby-poi
112
102
  licenses:
113
103
  - Apache
@@ -134,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
124
  requirements: []
135
125
 
136
126
  rubyforge_project:
137
- rubygems_version: 1.5.1
127
+ rubygems_version: 1.8.24
138
128
  signing_key:
139
129
  specification_version: 3
140
130
  summary: Apache POI class library for jruby
data/bin/autospec DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env jruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'autospec' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('rspec-core', 'autospec')
data/bin/htmldiff DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env jruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'htmldiff' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('diff-lcs', 'htmldiff')
data/bin/ldiff DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env jruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'ldiff' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('diff-lcs', 'ldiff')
data/bin/rdebug DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env jruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rdebug' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('ruby-debug', 'rdebug')