axlsx 1.0.9 → 1.0.10
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/Gemfile +7 -0
- data/Gemfile.lock +20 -0
- data/README.md +46 -3
- data/axlsx.gemspec +10 -10
- data/doc/Axlsx/App.html +111 -86
- data/doc/Axlsx/Ar/ClassMethods.html +188 -0
- data/doc/Axlsx/Ar/InstanceMethods.html +108 -0
- data/doc/Axlsx/Ar/SingletonMethods.html +312 -0
- data/doc/Axlsx/Ar.html +196 -0
- data/doc/Axlsx/Axis.html +57 -48
- data/doc/Axlsx/Bar3DChart.html +64 -54
- data/doc/Axlsx/BarSeries.html +29 -24
- data/doc/Axlsx/Border.html +45 -38
- data/doc/Axlsx/BorderPr.html +51 -44
- data/doc/Axlsx/CatAxis.html +32 -26
- data/doc/Axlsx/CatAxisData.html +25 -23
- data/doc/Axlsx/Cell.html +486 -65
- data/doc/Axlsx/CellAlignment.html +63 -50
- data/doc/Axlsx/CellProtection.html +20 -16
- data/doc/Axlsx/CellStyle.html +36 -28
- data/doc/Axlsx/Chart.html +102 -86
- data/doc/Axlsx/Color.html +27 -21
- data/doc/Axlsx/ContentType.html +15 -13
- data/doc/Axlsx/Core.html +27 -24
- data/doc/Axlsx/DataTypeValidator.html +13 -12
- data/doc/Axlsx/Default.html +21 -17
- data/doc/Axlsx/Drawing.html +82 -68
- data/doc/Axlsx/Fill.html +14 -11
- data/doc/Axlsx/Font.html +98 -82
- data/doc/Axlsx/GradientFill.html +47 -37
- data/doc/Axlsx/GradientStop.html +17 -13
- data/doc/Axlsx/GraphicFrame.html +39 -34
- data/doc/Axlsx/Line3DChart.html +64 -55
- data/doc/Axlsx/LineSeries.html +24 -20
- data/doc/Axlsx/Marker.html +40 -33
- data/doc/Axlsx/NumFmt.html +52 -47
- data/doc/Axlsx/OneCellAnchor.html +49 -41
- data/doc/Axlsx/Override.html +21 -17
- data/doc/Axlsx/Package.html +186 -77
- data/doc/Axlsx/PatternFill.html +47 -41
- data/doc/Axlsx/Pic.html +99 -83
- data/doc/Axlsx/Pie3DChart.html +17 -15
- data/doc/Axlsx/PieSeries.html +29 -24
- data/doc/Axlsx/RegexValidator.html +6 -5
- data/doc/Axlsx/Relationship.html +21 -17
- data/doc/Axlsx/Relationships.html +15 -13
- data/doc/Axlsx/RestrictionValidator.html +7 -6
- data/doc/Axlsx/Row.html +187 -33
- data/doc/Axlsx/Scaling.html +35 -29
- data/doc/Axlsx/SerAxis.html +23 -19
- data/doc/Axlsx/Series.html +140 -28
- data/doc/Axlsx/SeriesTitle.html +16 -15
- data/doc/Axlsx/Styles.html +179 -164
- data/doc/Axlsx/TableStyle.html +28 -23
- data/doc/Axlsx/TableStyleElement.html +53 -47
- data/doc/Axlsx/TableStyles.html +26 -22
- data/doc/Axlsx/Title.html +32 -28
- data/doc/Axlsx/TwoCellAnchor.html +50 -42
- data/doc/Axlsx/ValAxis.html +18 -15
- data/doc/Axlsx/ValAxisData.html +20 -19
- data/doc/Axlsx/View3D.html +48 -38
- data/doc/Axlsx/Workbook.html +225 -201
- data/doc/Axlsx/Worksheet.html +869 -184
- data/doc/Axlsx/Xf.html +75 -58
- data/doc/Axlsx.html +207 -124
- data/doc/_index.html +2 -2
- data/doc/css/style.css +1 -1
- data/doc/file.LICENSE.html +11 -10
- data/doc/file.README.html +142 -93
- data/doc/index.html +142 -93
- data/doc/js/app.js +4 -4
- data/doc/method_list.html +460 -364
- data/doc/top-level-namespace.html +2 -2
- data/examples/example.rb +71 -14
- data/lib/axlsx/package.rb +8 -1
- data/lib/axlsx/stylesheet/styles.rb +1 -1
- data/lib/axlsx/util/simple_typed_list.rb +5 -0
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/workbook.rb +4 -2
- data/lib/axlsx/workbook/worksheet/cell.rb +8 -13
- data/lib/axlsx/workbook/worksheet/row.rb +15 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +44 -1
- data/lib/axlsx.rb +3 -5
- data/test/rels/tc_relationships.rb +2 -6
- data/test/workbook/worksheet/tc_row.rb +6 -0
- data/test/workbook/worksheet/tc_worksheet.rb +36 -0
- metadata +139 -55
|
@@ -94,9 +94,9 @@
|
|
|
94
94
|
</div>
|
|
95
95
|
|
|
96
96
|
<div id="footer">
|
|
97
|
-
Generated on
|
|
97
|
+
Generated on Wed Nov 30 08:53:53 2011 by
|
|
98
98
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
99
|
-
0.7.3 (ruby-1.
|
|
99
|
+
0.7.3 (ruby-1.8.7).
|
|
100
100
|
</div>
|
|
101
101
|
|
|
102
102
|
</body>
|
data/examples/example.rb
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
1
2
|
# -*- coding: utf-8 -*-
|
|
2
|
-
# encoding: utf-8
|
|
3
3
|
require 'rubygems'
|
|
4
|
-
require 'axlsx'
|
|
4
|
+
require 'axlsx.rb'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
#A Simple Workbook
|
|
8
|
-
|
|
8
|
+
if ARGV.size == 0 || ARGV.include?("1")
|
|
9
9
|
p = Axlsx::Package.new
|
|
10
10
|
p.workbook.add_worksheet do |sheet|
|
|
11
11
|
sheet.add_row ["First", "Second", "Third"]
|
|
12
12
|
sheet.add_row [1, 2, 3]
|
|
13
13
|
end
|
|
14
14
|
p.serialize("example1.xlsx")
|
|
15
|
-
|
|
15
|
+
end
|
|
16
16
|
#Generating A Bar Chart
|
|
17
|
+
if ARGV.size==0 || ARGV.include?("2")
|
|
17
18
|
|
|
18
19
|
p = Axlsx::Package.new
|
|
19
20
|
p.workbook.add_worksheet do |sheet|
|
|
@@ -24,8 +25,9 @@
|
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
27
|
p.serialize("example2.xlsx")
|
|
27
|
-
|
|
28
|
+
end
|
|
28
29
|
#Generating A Pie Chart
|
|
30
|
+
if ARGV.size==0 || ARGV.include?("3")
|
|
29
31
|
|
|
30
32
|
p = Axlsx::Package.new
|
|
31
33
|
p.workbook.add_worksheet do |sheet|
|
|
@@ -36,9 +38,10 @@
|
|
|
36
38
|
end
|
|
37
39
|
end
|
|
38
40
|
p.serialize("example3.xlsx")
|
|
39
|
-
|
|
41
|
+
end
|
|
40
42
|
|
|
41
43
|
#Using Custom Styles
|
|
44
|
+
if ARGV.size==0 || ARGV.include?("4")
|
|
42
45
|
|
|
43
46
|
p = Axlsx::Package.new
|
|
44
47
|
wb = p.workbook
|
|
@@ -49,8 +52,9 @@
|
|
|
49
52
|
sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
|
|
50
53
|
end
|
|
51
54
|
p.serialize("example4.xlsx")
|
|
52
|
-
|
|
55
|
+
end
|
|
53
56
|
#Using Custom Formatting and date1904
|
|
57
|
+
if ARGV.size==0 || ARGV.include?("5")
|
|
54
58
|
|
|
55
59
|
p = Axlsx::Package.new
|
|
56
60
|
wb = p.workbook
|
|
@@ -63,8 +67,9 @@
|
|
|
63
67
|
sheet.add_row [Time.now, 0.2, 32], :style => [date, percent, padded]
|
|
64
68
|
end
|
|
65
69
|
p.serialize("example5.xlsx")
|
|
66
|
-
|
|
70
|
+
end
|
|
67
71
|
#Validation
|
|
72
|
+
if ARGV.size==0 || ARGV.include?("6")
|
|
68
73
|
|
|
69
74
|
p = Axlsx::Package.new
|
|
70
75
|
p.workbook.add_worksheet do |sheet|
|
|
@@ -75,8 +80,9 @@
|
|
|
75
80
|
p.validate.each do |error|
|
|
76
81
|
puts error.inspect
|
|
77
82
|
end
|
|
78
|
-
|
|
83
|
+
end
|
|
79
84
|
#Generating A Line Chart
|
|
85
|
+
if ARGV.size==0 || ARGV.include?("7")
|
|
80
86
|
|
|
81
87
|
p = Axlsx::Package.new
|
|
82
88
|
p.workbook.add_worksheet do |sheet|
|
|
@@ -90,9 +96,10 @@
|
|
|
90
96
|
end
|
|
91
97
|
|
|
92
98
|
end
|
|
93
|
-
p.serialize("
|
|
94
|
-
|
|
99
|
+
p.serialize("example7.xlsx")
|
|
100
|
+
end
|
|
95
101
|
#Add an Image
|
|
102
|
+
if ARGV.size==0 || ARGV.include?("8")
|
|
96
103
|
|
|
97
104
|
p = Axlsx::Package.new
|
|
98
105
|
p.workbook.add_worksheet do |sheet|
|
|
@@ -103,10 +110,11 @@
|
|
|
103
110
|
image.start_at 2, 2
|
|
104
111
|
end
|
|
105
112
|
end
|
|
106
|
-
p.serialize("
|
|
107
|
-
|
|
113
|
+
p.serialize("example8.xlsx")
|
|
114
|
+
end
|
|
108
115
|
|
|
109
116
|
#Asian Language Support
|
|
117
|
+
if ARGV.size==0 || ARGV.include?("9")
|
|
110
118
|
|
|
111
119
|
p = Axlsx::Package.new
|
|
112
120
|
p.workbook.add_worksheet do |sheet|
|
|
@@ -114,5 +122,54 @@
|
|
|
114
122
|
sheet.add_row ["华语/華語"]
|
|
115
123
|
sheet.add_row ["한국어/조선말"]
|
|
116
124
|
end
|
|
117
|
-
p.serialize("
|
|
125
|
+
p.serialize("example9.xlsx")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
#Styling Columns
|
|
130
|
+
if ARGV.size==0 || ARGV.include?("10")
|
|
131
|
+
p = Axlsx::Package.new
|
|
132
|
+
percent = p.workbook.styles.add_style :num_fmt => 9
|
|
133
|
+
p.workbook.add_worksheet do |sheet|
|
|
134
|
+
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
|
135
|
+
sheet.add_row [1, 2, 0.3, 4]
|
|
136
|
+
sheet.add_row [1, 2, 0.2, 4]
|
|
137
|
+
sheet.add_row [1, 2, 0.1, 4]
|
|
138
|
+
end
|
|
139
|
+
p.workbook.worksheets.first.col_style 2, percent, :row_offset=>1
|
|
140
|
+
p.serialize("example10.xlsx")
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
#Styling Rows
|
|
144
|
+
if ARGV.size==0 || ARGV.include?("11")
|
|
145
|
+
p = Axlsx::Package.new
|
|
146
|
+
p.workbook.add_worksheet do |sheet|
|
|
147
|
+
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
|
148
|
+
sheet.add_row [1, 2, 0.3, 4]
|
|
149
|
+
sheet.add_row [1, 2, 0.2, 4]
|
|
150
|
+
sheet.add_row [1, 2, 0.1, 4]
|
|
151
|
+
end
|
|
152
|
+
head = p.workbook.styles.add_style :bg_color => "FF000000", :fg_color=>"FFFFFFFF"
|
|
153
|
+
percent = p.workbook.styles.add_style :num_fmt => 9
|
|
154
|
+
p.workbook.worksheets.first.col_style 2, percent, :row_offset=>1
|
|
155
|
+
p.workbook.worksheets.first.row_style 0, head
|
|
156
|
+
p.serialize("example11.xlsx")
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
#Rails 3
|
|
160
|
+
|
|
161
|
+
# class MyModel < ActiveRecord::Base
|
|
162
|
+
# acts_as_axlsx
|
|
163
|
+
# end
|
|
164
|
+
#
|
|
165
|
+
# class MyModelController < ApplicationController
|
|
166
|
+
#
|
|
167
|
+
# GET /posts/xlsx
|
|
168
|
+
# def xlsx
|
|
169
|
+
# p = Post.to_xlsx
|
|
170
|
+
# p.serialize('posts.xlsx')
|
|
171
|
+
# send_file 'posts.xlsx', :type=>"application/xlsx", :x_sendfile=>true
|
|
172
|
+
# end
|
|
173
|
+
|
|
174
|
+
|
|
118
175
|
|
data/lib/axlsx/package.rb
CHANGED
|
@@ -15,7 +15,12 @@ module Axlsx
|
|
|
15
15
|
@core.creator = options[:author] || @core.creator
|
|
16
16
|
yield self if block_given?
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
# Accepts a ruport table for serialization to xlsx
|
|
20
|
+
# @param [Table] table a ruport Table object
|
|
21
|
+
def ruport_table(table)
|
|
22
|
+
puts table
|
|
23
|
+
end
|
|
19
24
|
|
|
20
25
|
# The workbook this package will serialize or validate.
|
|
21
26
|
# @return [Workbook] If no workbook instance has been assigned with this package a new Workbook instance is returned.
|
|
@@ -31,6 +36,8 @@ module Axlsx
|
|
|
31
36
|
# wb = Package.new().workbook = Workbook.new
|
|
32
37
|
def workbook
|
|
33
38
|
@workbook || @workbook = Workbook.new
|
|
39
|
+
yield @workbook if block_given?
|
|
40
|
+
@workbook
|
|
34
41
|
end
|
|
35
42
|
|
|
36
43
|
# @see workbook
|
|
@@ -258,7 +258,7 @@ module Axlsx
|
|
|
258
258
|
@numFmts.lock
|
|
259
259
|
|
|
260
260
|
@fonts = SimpleTypedList.new Font
|
|
261
|
-
@fonts << Font.new(:name => "Arial", :sz => 11, :family=>1)
|
|
261
|
+
@fonts << Font.new(:name => "Arial", :sz => 11, :family=>1, :numFmt=>"0")
|
|
262
262
|
@fonts.lock
|
|
263
263
|
|
|
264
264
|
@fills = SimpleTypedList.new Fill
|
data/lib/axlsx/version.rb
CHANGED
|
@@ -63,8 +63,10 @@ require 'axlsx/workbook/worksheet/worksheet.rb'
|
|
|
63
63
|
# @see Style#add_style
|
|
64
64
|
# @see Style
|
|
65
65
|
# @return [Styles]
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
def styles
|
|
67
|
+
yield @styles if block_given?
|
|
68
|
+
@styles
|
|
69
|
+
end
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
# Indicates if the epoc date for serialization should be 1904. If false, 1900 is used.
|
|
@@ -167,10 +167,14 @@ module Axlsx
|
|
|
167
167
|
# About Time - Time in OOXML is *different* from what you might expect. The history as to why is interesting, but you can safely assume that if you are generating docs on a mac, you will want to specify Workbook.1904 as true when using time typed values.
|
|
168
168
|
# @see Axlsx#date1904
|
|
169
169
|
def cast_value(v)
|
|
170
|
-
if @type == :time && v.is_a?(Time)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
(
|
|
170
|
+
if (@type == :time && v.is_a?(Time)) || (@type == :time && v.respond_to?(:to_time))
|
|
171
|
+
v = v.respond_to?(:to_time) ? v.to_time : v
|
|
172
|
+
# Using hardcoded offsets here as some operating systems will not except a 'negative' offset from the ruby epoc.
|
|
173
|
+
# (1970)
|
|
174
|
+
epoc1900 = -2209021200 #Time.local(1900, 1, 1)
|
|
175
|
+
epoc1904 = -2082877200 #Time.local(1904, 1, 1)
|
|
176
|
+
epoc = Workbook.date1904 ? epoc1904 : epoc1900
|
|
177
|
+
((v.localtime.to_f - epoc) /60.0/60.0/24.0).to_f
|
|
174
178
|
elsif @type == :float
|
|
175
179
|
v.to_f
|
|
176
180
|
elsif @type == :integer
|
|
@@ -178,15 +182,6 @@ module Axlsx
|
|
|
178
182
|
else
|
|
179
183
|
@type = :string
|
|
180
184
|
v.to_s
|
|
181
|
-
# curious as to why this would be the cells responsibility
|
|
182
|
-
# convert your values before passing them in wankers! CGI.unescapeHTML(v.to_s).to_xs
|
|
183
|
-
# to revert, load this once when the gem is loaded.
|
|
184
|
-
# unless String.method_defined? :to_xs
|
|
185
|
-
# require 'fast_xs' #dep
|
|
186
|
-
# class String
|
|
187
|
-
# alias_method :to_xs, :fast_xs
|
|
188
|
-
# end
|
|
189
|
-
# end
|
|
190
185
|
end
|
|
191
186
|
end
|
|
192
187
|
end
|
|
@@ -54,6 +54,20 @@ module Axlsx
|
|
|
54
54
|
c
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
# sets the style for every cell in this row
|
|
58
|
+
def style=(style)
|
|
59
|
+
cells.each_with_index do | cell, index |
|
|
60
|
+
s = style.is_a?(Array) ? style[index] : style
|
|
61
|
+
cell.style = s
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# returns the cells in this row as an array
|
|
66
|
+
# This lets us transpose the rows into columns
|
|
67
|
+
# @return [Array]
|
|
68
|
+
def to_ary
|
|
69
|
+
@cells.to_ary
|
|
70
|
+
end
|
|
57
71
|
|
|
58
72
|
private
|
|
59
73
|
|
|
@@ -66,6 +80,7 @@ module Axlsx
|
|
|
66
80
|
worksheet.send(:update_auto_fit_data, self.cells)
|
|
67
81
|
end
|
|
68
82
|
|
|
83
|
+
|
|
69
84
|
# Converts values, types, and style options into cells and associates them with this row.
|
|
70
85
|
# A new cell is created for each item in the values array.
|
|
71
86
|
# If value option is defined and is a symbol it is applied to all the cells created.
|
|
@@ -39,6 +39,7 @@ module Axlsx
|
|
|
39
39
|
@auto_fit_data = []
|
|
40
40
|
self.name = options[:name] || "Sheet" + (index+1).to_s
|
|
41
41
|
@magick_draw = Magick::Draw.new
|
|
42
|
+
@cols = SimpleTypedList.new Cell
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
# The name of the worksheet
|
|
@@ -89,6 +90,48 @@ module Axlsx
|
|
|
89
90
|
@rows.last
|
|
90
91
|
end
|
|
91
92
|
|
|
93
|
+
# Set the style for cells in a specific row
|
|
94
|
+
# @param [Integer] index or range of indexes in the table
|
|
95
|
+
# @param [Integer] the cellXfs index
|
|
96
|
+
# @option options [Integer] col_offset only cells after this column will be updated.
|
|
97
|
+
# @note You can also specify the style in the add_row call
|
|
98
|
+
# @see Worksheet#add_row
|
|
99
|
+
# @see README.md for an example
|
|
100
|
+
def row_style(index, style, options={})
|
|
101
|
+
offset = options.delete(:col_offset) || 0
|
|
102
|
+
rs = @rows[index]
|
|
103
|
+
if rs.is_a?(Array)
|
|
104
|
+
rs.each { |r| r.cells[(offset..-1)].each { |c| c.style = style } }
|
|
105
|
+
else
|
|
106
|
+
rs.cells[(offset..-1)].each { |c| c.style = style }
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# returns the sheet data as columnw
|
|
111
|
+
def cols
|
|
112
|
+
@rows.transpose
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
# Set the style for cells in a specific column
|
|
117
|
+
# @param [Integer] index the index of the column
|
|
118
|
+
# @param [Integer] the cellXfs index
|
|
119
|
+
# @option options [Integer] row_offset only cells after this column will be updated.
|
|
120
|
+
# @note You can also specify the style for specific columns in the call to add_row by using an array for the :styles option
|
|
121
|
+
# @see Worksheet#add_row
|
|
122
|
+
# @see README.md for an example
|
|
123
|
+
def col_style(index, style, options={})
|
|
124
|
+
offset = options.delete(:row_offset) || 0
|
|
125
|
+
@rows[(offset..-1)].each do |r|
|
|
126
|
+
cells = r.cells[index]
|
|
127
|
+
if cells.is_a?(Array)
|
|
128
|
+
cells.each { |c| c.style = style }
|
|
129
|
+
else
|
|
130
|
+
cells.style = style
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
92
135
|
# Adds a chart to this worksheets drawing. This is the recommended way to create charts for your worksheet. This method wraps the complexity of dealing with ooxml drawing, anchors, markers graphic frames chart objects and all the other dirty details.
|
|
93
136
|
# @param [Class] chart_type
|
|
94
137
|
# @option options [Array] start_at
|
|
@@ -183,7 +226,7 @@ module Axlsx
|
|
|
183
226
|
# From ECMA docs
|
|
184
227
|
# Column width measured as the number of characters of the maximum digit width of the numbers 0 .. 9 as
|
|
185
228
|
# rendered in the normal style's font. There are 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.
|
|
186
|
-
# width = Truncate([!{Number of Characters} * !{Maximum Digit Width} + !{5 pixel padding}]
|
|
229
|
+
# width = Truncate([!{Number of Characters} * !{Maximum Digit Width} + !{5 pixel padding}]/{Maximum Digit Width}*256)/256
|
|
187
230
|
# @return [Float]
|
|
188
231
|
# @param [Hash] A hash of auto_fit_data
|
|
189
232
|
def auto_width(col)
|
data/lib/axlsx.rb
CHANGED
|
@@ -16,19 +16,17 @@ require 'axlsx/drawing/drawing.rb'
|
|
|
16
16
|
require 'axlsx/workbook/workbook.rb'
|
|
17
17
|
require 'axlsx/package.rb'
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
19
|
#required gems
|
|
22
|
-
require '
|
|
20
|
+
require 'nokogiri'
|
|
23
21
|
require 'active_support/core_ext/object/instance_variables'
|
|
24
22
|
require 'active_support/inflector'
|
|
25
|
-
require '
|
|
23
|
+
require 'RMagick'
|
|
26
24
|
require 'zip/zip'
|
|
27
25
|
|
|
28
26
|
#core dependencies
|
|
29
27
|
require 'bigdecimal'
|
|
30
28
|
require 'time'
|
|
31
|
-
|
|
29
|
+
|
|
32
30
|
|
|
33
31
|
# xlsx generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
|
|
34
32
|
module Axlsx
|
|
@@ -2,14 +2,10 @@ require 'test/unit'
|
|
|
2
2
|
require 'axlsx.rb'
|
|
3
3
|
|
|
4
4
|
class TestRelationships < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
@rels = Axlsx::Relationships.new
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def teardown
|
|
10
|
-
end
|
|
5
|
+
|
|
11
6
|
|
|
12
7
|
def test_valid_document
|
|
8
|
+
@rels = Axlsx::Relationships.new
|
|
13
9
|
schema = Nokogiri::XML::Schema(File.open(Axlsx::RELS_XSD))
|
|
14
10
|
doc = Nokogiri::XML(@rels.to_xml)
|
|
15
11
|
errors = []
|
|
@@ -14,6 +14,12 @@ class TestRow < Test::Unit::TestCase
|
|
|
14
14
|
assert_equal(@row.worksheet, @ws, "has a reference to the worksheet")
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
def test_style
|
|
18
|
+
r = @ws.add_row([1,2,3,4,5])
|
|
19
|
+
r.style=1
|
|
20
|
+
r.cells.each { |c| assert_equal(c.style,1) }
|
|
21
|
+
end
|
|
22
|
+
|
|
17
23
|
def test_index
|
|
18
24
|
assert_equal(@row.index, @row.worksheet.rows.index(@row))
|
|
19
25
|
end
|
|
@@ -46,6 +46,42 @@ class TestWorksheet < Test::Unit::TestCase
|
|
|
46
46
|
assert @ws.drawing.is_a? Axlsx::Drawing
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
def test_col_style
|
|
50
|
+
@ws.add_row [1,2,3,4]
|
|
51
|
+
@ws.add_row [1,2,3,4]
|
|
52
|
+
@ws.add_row [1,2,3,4]
|
|
53
|
+
@ws.add_row [1,2,3,4]
|
|
54
|
+
@ws.col_style( (1..2), 1, :row_offset=>1)
|
|
55
|
+
@ws.rows[(1..-1)].each do | r |
|
|
56
|
+
assert_equal(r.cells[1].style, 1)
|
|
57
|
+
assert_equal(r.cells[2].style, 1)
|
|
58
|
+
end
|
|
59
|
+
assert_equal(@ws.rows.first.cells[1].style, 0)
|
|
60
|
+
assert_equal(@ws.rows.first.cells[0].style, 0)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_cols
|
|
64
|
+
@ws.add_row [1,2,3,4]
|
|
65
|
+
@ws.add_row [1,2,3,4]
|
|
66
|
+
@ws.add_row [1,2,3,4]
|
|
67
|
+
@ws.add_row [1,2,3,4]
|
|
68
|
+
c = @ws.cols[1]
|
|
69
|
+
assert_equal(c.size, 4)
|
|
70
|
+
assert_equal(c[0].value, 2)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_row_style
|
|
74
|
+
@ws.add_row [1,2,3,4]
|
|
75
|
+
@ws.add_row [1,2,3,4]
|
|
76
|
+
@ws.add_row [1,2,3,4]
|
|
77
|
+
@ws.add_row [1,2,3,4]
|
|
78
|
+
@ws.row_style 1, 1, :col_offset=>1
|
|
79
|
+
@ws.rows[1].cells[(1..-1)].each do | c |
|
|
80
|
+
assert_equal(c.style, 1)
|
|
81
|
+
end
|
|
82
|
+
assert_equal(@ws.rows[1].cells[0].style, 0)
|
|
83
|
+
assert_equal(@ws.rows[2].cells[1].style, 0)
|
|
84
|
+
end
|
|
49
85
|
|
|
50
86
|
def test_to_xml
|
|
51
87
|
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
|