caxlsx 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +41 -33
- data/Rakefile +9 -11
- data/examples/auto_filter.rb +10 -1
- data/examples/conditional_formatting/example_conditional_formatting.rb +18 -3
- data/examples/data_validation.rb +57 -40
- data/examples/example.rb +115 -7
- data/examples/merge_cells.rb +17 -0
- data/examples/no_grid_with_borders.rb +18 -0
- data/examples/pivot_test.rb +63 -0
- data/examples/split.rb +16 -0
- data/lib/axlsx.rb +34 -15
- data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
- data/lib/axlsx/content_type/content_type.rb +1 -1
- data/lib/axlsx/doc_props/app.rb +1 -1
- data/lib/axlsx/doc_props/core.rb +5 -5
- data/lib/axlsx/drawing/area_chart.rb +99 -0
- data/lib/axlsx/drawing/area_series.rb +110 -0
- data/lib/axlsx/drawing/axes.rb +1 -1
- data/lib/axlsx/drawing/axis.rb +12 -9
- data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
- data/lib/axlsx/drawing/bar_chart.rb +143 -0
- data/lib/axlsx/drawing/bar_series.rb +9 -9
- data/lib/axlsx/drawing/bubble_chart.rb +59 -0
- data/lib/axlsx/drawing/bubble_series.rb +63 -0
- data/lib/axlsx/drawing/cat_axis.rb +5 -5
- data/lib/axlsx/drawing/chart.rb +52 -8
- data/lib/axlsx/drawing/d_lbls.rb +3 -3
- data/lib/axlsx/drawing/drawing.rb +6 -1
- data/lib/axlsx/drawing/graphic_frame.rb +3 -3
- data/lib/axlsx/drawing/hyperlink.rb +1 -3
- data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
- data/lib/axlsx/drawing/line_chart.rb +10 -10
- data/lib/axlsx/drawing/line_series.rb +32 -3
- data/lib/axlsx/drawing/marker.rb +1 -1
- data/lib/axlsx/drawing/num_data.rb +4 -4
- data/lib/axlsx/drawing/num_data_source.rb +6 -6
- data/lib/axlsx/drawing/num_val.rb +3 -1
- data/lib/axlsx/drawing/one_cell_anchor.rb +3 -2
- data/lib/axlsx/drawing/pic.rb +25 -19
- data/lib/axlsx/drawing/picture_locking.rb +1 -3
- data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
- data/lib/axlsx/drawing/pie_series.rb +6 -6
- data/lib/axlsx/drawing/scaling.rb +6 -6
- data/lib/axlsx/drawing/scatter_chart.rb +10 -10
- data/lib/axlsx/drawing/scatter_series.rb +40 -7
- data/lib/axlsx/drawing/ser_axis.rb +2 -2
- data/lib/axlsx/drawing/series.rb +3 -3
- data/lib/axlsx/drawing/series_title.rb +2 -2
- data/lib/axlsx/drawing/str_data.rb +3 -3
- data/lib/axlsx/drawing/str_val.rb +3 -1
- data/lib/axlsx/drawing/title.rb +22 -4
- data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
- data/lib/axlsx/drawing/val_axis.rb +1 -1
- data/lib/axlsx/drawing/view_3D.rb +2 -2
- data/lib/axlsx/drawing/vml_drawing.rb +1 -1
- data/lib/axlsx/package.rb +33 -31
- data/lib/axlsx/rels/relationship.rb +1 -1
- data/lib/axlsx/rels/relationships.rb +7 -4
- data/lib/axlsx/stylesheet/border_pr.rb +2 -2
- data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
- data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
- data/lib/axlsx/stylesheet/cell_style.rb +1 -3
- data/lib/axlsx/stylesheet/color.rb +1 -3
- data/lib/axlsx/stylesheet/font.rb +1 -1
- data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
- data/lib/axlsx/stylesheet/num_fmt.rb +10 -3
- data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
- data/lib/axlsx/stylesheet/styles.rb +7 -7
- data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
- data/lib/axlsx/util/accessors.rb +6 -6
- data/lib/axlsx/util/constants.rb +107 -99
- data/lib/axlsx/util/mime_type_utils.rb +11 -0
- data/lib/axlsx/util/options_parser.rb +2 -1
- data/lib/axlsx/util/parser.rb +4 -4
- data/lib/axlsx/util/serialized_attributes.rb +16 -6
- data/lib/axlsx/util/simple_typed_list.rb +28 -52
- data/lib/axlsx/util/storage.rb +4 -4
- data/lib/axlsx/util/validators.rb +29 -17
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/defined_name.rb +11 -12
- data/lib/axlsx/workbook/defined_names.rb +2 -2
- data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
- data/lib/axlsx/workbook/workbook.rb +36 -11
- data/lib/axlsx/workbook/workbook_view.rb +80 -0
- data/lib/axlsx/workbook/workbook_views.rb +22 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
- data/lib/axlsx/workbook/worksheet/break.rb +1 -3
- data/lib/axlsx/workbook/worksheet/cell.rb +136 -74
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +63 -43
- data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
- data/lib/axlsx/workbook/worksheet/cfvos.rb +4 -1
- data/lib/axlsx/workbook/worksheet/col.rb +7 -10
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
- data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
- data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
- data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
- data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
- data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
- data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
- data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
- data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +4 -2
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
- data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
- data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +44 -28
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
- data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
- data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -2
- data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -0
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -0
- data/lib/axlsx/workbook/worksheet/row.rb +40 -51
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
- data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
- data/lib/axlsx/workbook/worksheet/table.rb +6 -6
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
- data/lib/axlsx/workbook/worksheet/tables.rb +4 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +64 -78
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
- data/test/drawing/tc_area_chart.rb +39 -0
- data/test/drawing/tc_area_series.rb +71 -0
- data/test/drawing/tc_axis.rb +27 -0
- data/test/drawing/tc_bar_chart.rb +71 -0
- data/test/drawing/tc_bubble_chart.rb +44 -0
- data/test/drawing/tc_bubble_series.rb +21 -0
- data/test/drawing/tc_chart.rb +23 -10
- data/test/drawing/tc_data_source.rb +6 -0
- data/test/drawing/tc_drawing.rb +2 -2
- data/test/drawing/tc_line_chart.rb +5 -5
- data/test/drawing/tc_line_series.rb +47 -6
- data/test/drawing/tc_pic.rb +11 -15
- data/test/drawing/tc_scatter_series.rb +36 -1
- data/test/drawing/tc_str_val.rb +9 -0
- data/test/drawing/tc_title.rb +5 -0
- data/test/stylesheet/tc_styles.rb +2 -2
- data/test/tc_axlsx.rb +31 -0
- data/test/tc_helper.rb +2 -0
- data/test/tc_package.rb +19 -1
- data/test/util/tc_mime_type_utils.rb +13 -0
- data/test/util/tc_simple_typed_list.rb +2 -3
- data/test/util/tc_validators.rb +34 -10
- data/test/workbook/tc_defined_name.rb +12 -4
- data/test/workbook/tc_shared_strings_table.rb +16 -1
- data/test/workbook/tc_workbook.rb +38 -3
- data/test/workbook/tc_workbook_view.rb +50 -0
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
- data/test/workbook/worksheet/tc_break.rb +1 -1
- data/test/workbook/worksheet/tc_cell.rb +76 -8
- data/test/workbook/worksheet/tc_col.rb +2 -2
- data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
- data/test/workbook/worksheet/tc_data_bar.rb +1 -1
- data/test/workbook/worksheet/tc_data_validation.rb +11 -11
- data/test/workbook/worksheet/tc_header_footer.rb +2 -2
- data/test/workbook/worksheet/tc_icon_set.rb +1 -1
- data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
- data/test/workbook/worksheet/tc_page_setup.rb +3 -3
- data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
- data/test/workbook/worksheet/tc_print_options.rb +1 -1
- data/test/workbook/worksheet/tc_rich_text.rb +44 -0
- data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
- data/test/workbook/worksheet/tc_row.rb +7 -2
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
- data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
- data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
- data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
- data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
- data/test/workbook/worksheet/tc_table.rb +2 -3
- data/test/workbook/worksheet/tc_worksheet.rb +99 -45
- metadata +89 -16
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
|
+
|
5
|
+
#```ruby
|
6
|
+
require 'axlsx'
|
7
|
+
package = Axlsx::Package.new
|
8
|
+
package.workbook do |workbook|
|
9
|
+
workbook.add_worksheet name: 'merged_cells' do |sheet|
|
10
|
+
4.times do
|
11
|
+
sheet.add_row %w(a b c d e f g)
|
12
|
+
end
|
13
|
+
sheet.merge_cells "A1:A2"
|
14
|
+
sheet.merge_cells "B1:B2"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
package.serialize 'merged_cells.xlsx'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
|
+
|
5
|
+
#```ruby
|
6
|
+
require 'axlsx'
|
7
|
+
package = Axlsx::Package.new
|
8
|
+
package.workbook do |workbook|
|
9
|
+
workbook.styles do |s|
|
10
|
+
gridstyle_border = s.add_style :border => { :style => :thin, :color =>"FFCDCDCD" }
|
11
|
+
workbook.add_worksheet :name => "Custom Borders" do |sheet|
|
12
|
+
sheet.sheet_view.show_grid_lines = false
|
13
|
+
sheet.add_row ["with", "grid", "style"], :style => gridstyle_border
|
14
|
+
sheet.add_row ["no", "border"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
package.serialize 'no_grid_with_borders.xlsx'
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class RandomReportGenerator
|
2
|
+
def date
|
3
|
+
Date.today.strftime("%m/%d/%Y")
|
4
|
+
end
|
5
|
+
def member_id
|
6
|
+
@i ||= 0
|
7
|
+
@i += 1
|
8
|
+
end
|
9
|
+
def name
|
10
|
+
"John S."
|
11
|
+
end
|
12
|
+
def gender
|
13
|
+
["Male", "Female"].sample
|
14
|
+
end
|
15
|
+
def age
|
16
|
+
rand(100)
|
17
|
+
end
|
18
|
+
def city
|
19
|
+
["New York", "Mountain View", "Newark", "Phoenix"].sample
|
20
|
+
end
|
21
|
+
def state
|
22
|
+
["NY", "CA", "NJ", "AZ"].sample
|
23
|
+
end
|
24
|
+
def parenting
|
25
|
+
"Foo"
|
26
|
+
end
|
27
|
+
def student
|
28
|
+
"Bar"
|
29
|
+
end
|
30
|
+
def income
|
31
|
+
"Bar"
|
32
|
+
end
|
33
|
+
def education
|
34
|
+
"Bar"
|
35
|
+
end
|
36
|
+
def answer
|
37
|
+
["Yes", "No", "Maybe", "I dont know"].sample
|
38
|
+
end
|
39
|
+
def run
|
40
|
+
package = Axlsx::Package.new
|
41
|
+
workbook = package.workbook
|
42
|
+
|
43
|
+
workbook.add_worksheet(:name => "Data Sheet") do |sheet|
|
44
|
+
sheet.add_row [
|
45
|
+
"Date", "Member ID", "Name", "Gender", "Age", "City", "State",
|
46
|
+
"Parenting Status", "Student Status", "Income", "Education", "Answer"
|
47
|
+
]
|
48
|
+
30.times do
|
49
|
+
sheet.add_row [date, member_id, name, gender, age, city, state,
|
50
|
+
parenting, student, income, education, answer]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
workbook.add_worksheet(:name => "Summary") do |sheet|
|
55
|
+
pivot_table = Axlsx::PivotTable.new 'A1:B15', "A1:L31", workbook.worksheets[0]
|
56
|
+
pivot_table.rows = ['Answer']
|
57
|
+
pivot_table.data = [{:ref => "Member ID", :subtotal => "count"}]
|
58
|
+
sheet.pivot_tables << pivot_table
|
59
|
+
end
|
60
|
+
|
61
|
+
package.serialize("pivot_table.xlsx")
|
62
|
+
end
|
63
|
+
end
|
data/examples/split.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
|
+
require 'axlsx'
|
5
|
+
p = Axlsx::Package.new
|
6
|
+
wb = p.workbook
|
7
|
+
wb.add_worksheet name: 'pane' do |sheet|
|
8
|
+
sheet.sheet_view.pane do |pane|
|
9
|
+
pane.top_left_cell = "B2"
|
10
|
+
pane.state = :frozen_split
|
11
|
+
pane.y_split = 2
|
12
|
+
pane.x_split = 1
|
13
|
+
pane.active_pane = :bottom_right
|
14
|
+
end
|
15
|
+
end
|
16
|
+
p.serialize 'pane.xlsx'
|
data/lib/axlsx.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'htmlentities'
|
3
3
|
require 'axlsx/version.rb'
|
4
|
+
require 'mimemagic'
|
4
5
|
|
5
6
|
require 'axlsx/util/simple_typed_list.rb'
|
6
7
|
require 'axlsx/util/constants.rb'
|
@@ -10,6 +11,7 @@ require 'axlsx/util/serialized_attributes'
|
|
10
11
|
require 'axlsx/util/options_parser'
|
11
12
|
# to be included with parsable intitites.
|
12
13
|
#require 'axlsx/util/parser.rb'
|
14
|
+
require 'axlsx/util/mime_type_utils'
|
13
15
|
|
14
16
|
require 'axlsx/stylesheet/styles.rb'
|
15
17
|
|
@@ -53,7 +55,7 @@ module Axlsx
|
|
53
55
|
cells = sort_cells(cells)
|
54
56
|
reference = "#{cells.first.reference(absolute)}:#{cells.last.reference(absolute)}"
|
55
57
|
if absolute
|
56
|
-
escaped_name = cells.first.row.worksheet.name.gsub
|
58
|
+
escaped_name = cells.first.row.worksheet.name.gsub ''', "''"
|
57
59
|
"'#{escaped_name}'!#{reference}"
|
58
60
|
else
|
59
61
|
reference
|
@@ -65,7 +67,7 @@ module Axlsx
|
|
65
67
|
# @param [Array] cells
|
66
68
|
# @return [Array]
|
67
69
|
def self.sort_cells(cells)
|
68
|
-
cells.sort { |x, y| [x.index, x.row.
|
70
|
+
cells.sort { |x, y| [x.index, x.row.row_index] <=> [y.index, y.row.row_index] }
|
69
71
|
end
|
70
72
|
|
71
73
|
#global reference html entity encoding
|
@@ -88,20 +90,21 @@ module Axlsx
|
|
88
90
|
# @note This follows the standard spreadsheet convention of naming columns A to Z, followed by AA to AZ etc.
|
89
91
|
# @return [String]
|
90
92
|
def self.col_ref(index)
|
91
|
-
chars =
|
93
|
+
chars = ''
|
92
94
|
while index >= 26 do
|
93
|
-
|
94
|
-
|
95
|
+
index, char = index.divmod(26)
|
96
|
+
chars.prepend((char + 65).chr)
|
97
|
+
index -= 1
|
95
98
|
end
|
96
|
-
chars
|
97
|
-
chars
|
99
|
+
chars.prepend((index + 65).chr)
|
100
|
+
chars
|
98
101
|
end
|
99
102
|
|
100
103
|
# @return [String] The alpha(column)numeric(row) reference for this sell.
|
101
104
|
# @example Relative Cell Reference
|
102
105
|
# ws.rows.first.cells.first.r #=> "A1"
|
103
106
|
def self.cell_r(c_index, r_index)
|
104
|
-
|
107
|
+
col_ref(c_index) << (r_index+1).to_s
|
105
108
|
end
|
106
109
|
|
107
110
|
# Creates an array of individual cell references based on an excel reference range.
|
@@ -113,7 +116,7 @@ module Axlsx
|
|
113
116
|
end_col, end_row = name_to_indices($2)
|
114
117
|
(start_row..end_row).to_a.map do |row_num|
|
115
118
|
(start_col..end_col).to_a.map do |col_num|
|
116
|
-
|
119
|
+
cell_r(col_num, row_num)
|
117
120
|
end
|
118
121
|
end
|
119
122
|
end
|
@@ -127,14 +130,30 @@ module Axlsx
|
|
127
130
|
s.gsub(/_(.)/){ $1.upcase }
|
128
131
|
end
|
129
132
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
133
|
+
# returns the provided string with all invalid control charaters
|
134
|
+
# removed.
|
135
|
+
# @param [String] str The string to process
|
136
|
+
# @return [String]
|
137
|
+
def self.sanitize(str)
|
138
|
+
if str.frozen?
|
139
|
+
str.delete(CONTROL_CHARS)
|
140
|
+
else
|
141
|
+
str.delete!(CONTROL_CHARS)
|
142
|
+
str
|
136
143
|
end
|
144
|
+
end
|
137
145
|
|
146
|
+
# If value is boolean return 1 or 0
|
147
|
+
# else return the value
|
148
|
+
# @param [Object] value The value to process
|
149
|
+
# @return [Object]
|
150
|
+
def self.booleanize(value)
|
151
|
+
if value == true || value == false
|
152
|
+
value ? 1 : 0
|
153
|
+
else
|
154
|
+
value
|
155
|
+
end
|
156
|
+
end
|
138
157
|
|
139
158
|
# Instructs the serializer to not try to escape cell value input.
|
140
159
|
# This will give you a huge speed bonus, but if you content has <, > or other xml character data
|
@@ -24,7 +24,7 @@ module Axlsx
|
|
24
24
|
# Serialize the contenty type to xml
|
25
25
|
def to_xml_string(node_name = '', str = '')
|
26
26
|
str << "<#{node_name} "
|
27
|
-
str << instance_values.map { |key, value|
|
27
|
+
str << instance_values.map { |key, value| Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ')
|
28
28
|
str << '/>'
|
29
29
|
end
|
30
30
|
|
@@ -16,7 +16,7 @@ module Axlsx
|
|
16
16
|
# @return [String]
|
17
17
|
def to_xml_string(str = '')
|
18
18
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
19
|
-
str << '<Types xmlns="' << XML_NS_T << '">'
|
19
|
+
str << ('<Types xmlns="' << XML_NS_T << '">')
|
20
20
|
each { |type| type.to_xml_string(str) }
|
21
21
|
str << '</Types>'
|
22
22
|
end
|
data/lib/axlsx/doc_props/app.rb
CHANGED
@@ -222,7 +222,7 @@ module Axlsx
|
|
222
222
|
# @return [String]
|
223
223
|
def to_xml_string(str = '')
|
224
224
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
225
|
-
str << '<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">'
|
225
|
+
str << ('<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">')
|
226
226
|
instance_values.each do |key, value|
|
227
227
|
node_name = Axlsx.camel(key)
|
228
228
|
str << "<#{node_name}>#{value}</#{node_name}>"
|
data/lib/axlsx/doc_props/core.rb
CHANGED
@@ -25,11 +25,11 @@ module Axlsx
|
|
25
25
|
# @return [String]
|
26
26
|
def to_xml_string(str = '')
|
27
27
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
28
|
-
str << '<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" '
|
29
|
-
str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" '
|
30
|
-
str << 'xmlns:xsi="' << CORE_NS_XSI << '">'
|
31
|
-
str << '<dc:creator>' << self.creator << '</dc:creator>'
|
32
|
-
str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>'
|
28
|
+
str << ('<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" ')
|
29
|
+
str << ('xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" ')
|
30
|
+
str << ('xmlns:xsi="' << CORE_NS_XSI << '">')
|
31
|
+
str << ('<dc:creator>' << self.creator << '</dc:creator>')
|
32
|
+
str << ('<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>')
|
33
33
|
str << '<cp:revision>0</cp:revision>'
|
34
34
|
str << '</cp:coreProperties>'
|
35
35
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Axlsx
|
3
|
+
|
4
|
+
# The AreaChart is a two dimentional line chart (who would have guessed?) that you can add to your worksheet.
|
5
|
+
# @example Creating a chart
|
6
|
+
# # This example creates a line in a single sheet.
|
7
|
+
# require "rubygems" # if that is your preferred way to manage gems!
|
8
|
+
# require "axlsx"
|
9
|
+
#
|
10
|
+
# p = Axlsx::Package.new
|
11
|
+
# ws = p.workbook.add_worksheet
|
12
|
+
# ws.add_row ["This is a chart with no data in the sheet"]
|
13
|
+
#
|
14
|
+
# chart = ws.add_chart(Axlsx::AreaChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
|
15
|
+
# chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
|
16
|
+
#
|
17
|
+
# @see Worksheet#add_chart
|
18
|
+
# @see Worksheet#add_row
|
19
|
+
# @see Chart#add_series
|
20
|
+
# @see Series
|
21
|
+
# @see Package#serialize
|
22
|
+
class AreaChart < Chart
|
23
|
+
|
24
|
+
# the category axis
|
25
|
+
# @return [CatAxis]
|
26
|
+
def cat_axis
|
27
|
+
axes[:cat_axis]
|
28
|
+
end
|
29
|
+
alias :catAxis :cat_axis
|
30
|
+
|
31
|
+
# the category axis
|
32
|
+
# @return [ValAxis]
|
33
|
+
def val_axis
|
34
|
+
axes[:val_axis]
|
35
|
+
end
|
36
|
+
alias :valAxis :val_axis
|
37
|
+
|
38
|
+
# must be one of [:percentStacked, :clustered, :standard, :stacked]
|
39
|
+
# @return [Symbol]
|
40
|
+
attr_reader :grouping
|
41
|
+
|
42
|
+
# Creates a new line chart object
|
43
|
+
# @param [GraphicFrame] frame The workbook that owns this chart.
|
44
|
+
# @option options [Cell, String] title
|
45
|
+
# @option options [Boolean] show_legend
|
46
|
+
# @option options [Symbol] grouping
|
47
|
+
# @see Chart
|
48
|
+
def initialize(frame, options={})
|
49
|
+
@vary_colors = false
|
50
|
+
@grouping = :standard
|
51
|
+
super(frame, options)
|
52
|
+
@series_type = AreaSeries
|
53
|
+
@d_lbls = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
# @see grouping
|
57
|
+
def grouping=(v)
|
58
|
+
RestrictionValidator.validate "AreaChart.grouping", [:percentStacked, :standard, :stacked], v
|
59
|
+
@grouping = v
|
60
|
+
end
|
61
|
+
|
62
|
+
# The node name to use in serialization. As AreaChart is used as the
|
63
|
+
# base class for Liine3DChart we need to be sure to serialize the
|
64
|
+
# chart based on the actual class type and not a fixed node name.
|
65
|
+
# @return [String]
|
66
|
+
def node_name
|
67
|
+
path = self.class.to_s
|
68
|
+
if i = path.rindex('::')
|
69
|
+
path = path[(i+2)..-1]
|
70
|
+
end
|
71
|
+
path[0] = path[0].chr.downcase
|
72
|
+
path
|
73
|
+
end
|
74
|
+
|
75
|
+
# Serializes the object
|
76
|
+
# @param [String] str
|
77
|
+
# @return [String]
|
78
|
+
def to_xml_string(str = '')
|
79
|
+
super(str) do
|
80
|
+
str << ("<c:" << node_name << ">")
|
81
|
+
str << ('<c:grouping val="' << grouping.to_s << '"/>')
|
82
|
+
str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
|
83
|
+
@series.each { |ser| ser.to_xml_string(str) }
|
84
|
+
@d_lbls.to_xml_string(str) if @d_lbls
|
85
|
+
yield if block_given?
|
86
|
+
axes.to_xml_string(str, :ids => true)
|
87
|
+
str << ("</c:" << node_name << ">")
|
88
|
+
axes.to_xml_string(str)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# The axes for this chart. AreaCharts have a category and value
|
93
|
+
# axis.
|
94
|
+
# @return [Axes]
|
95
|
+
def axes
|
96
|
+
@axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Axlsx
|
3
|
+
# A AreaSeries defines the title, data and labels for line charts
|
4
|
+
# @note The recommended way to manage series is to use Chart#add_series
|
5
|
+
# @see Worksheet#add_chart
|
6
|
+
# @see Chart#add_series
|
7
|
+
class AreaSeries < Series
|
8
|
+
|
9
|
+
# The data for this series.
|
10
|
+
# @return [ValAxisData]
|
11
|
+
attr_reader :data
|
12
|
+
|
13
|
+
# The labels for this series.
|
14
|
+
# @return [CatAxisData]
|
15
|
+
attr_reader :labels
|
16
|
+
|
17
|
+
# The fill color for this series.
|
18
|
+
# Red, green, and blue is expressed as sequence of hex digits, RRGGBB. A perceptual gamma of 2.2 is used.
|
19
|
+
# @return [String]
|
20
|
+
attr_reader :color
|
21
|
+
|
22
|
+
# show markers on values
|
23
|
+
# @return [Boolean]
|
24
|
+
attr_reader :show_marker
|
25
|
+
|
26
|
+
# custom marker symbol
|
27
|
+
# @return [String]
|
28
|
+
attr_reader :marker_symbol
|
29
|
+
|
30
|
+
# line smoothing on values
|
31
|
+
# @return [Boolean]
|
32
|
+
attr_reader :smooth
|
33
|
+
|
34
|
+
# Creates a new series
|
35
|
+
# @option options [Array, SimpleTypedList] data
|
36
|
+
# @option options [Array, SimpleTypedList] labels
|
37
|
+
# @param [Chart] chart
|
38
|
+
def initialize(chart, options={})
|
39
|
+
@show_marker = false
|
40
|
+
@marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default
|
41
|
+
@smooth = false
|
42
|
+
@labels, @data = nil, nil
|
43
|
+
super(chart, options)
|
44
|
+
@labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
|
45
|
+
@data = NumDataSource.new(options) unless options[:data].nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
# @see color
|
49
|
+
def color=(v)
|
50
|
+
@color = v
|
51
|
+
end
|
52
|
+
|
53
|
+
# @see show_marker
|
54
|
+
def show_marker=(v)
|
55
|
+
Axlsx::validate_boolean(v)
|
56
|
+
@show_marker = v
|
57
|
+
end
|
58
|
+
|
59
|
+
# @see marker_symbol
|
60
|
+
def marker_symbol=(v)
|
61
|
+
Axlsx::validate_marker_symbol(v)
|
62
|
+
@marker_symbol = v
|
63
|
+
end
|
64
|
+
|
65
|
+
# @see smooth
|
66
|
+
def smooth=(v)
|
67
|
+
Axlsx::validate_boolean(v)
|
68
|
+
@smooth = v
|
69
|
+
end
|
70
|
+
|
71
|
+
# Serializes the object
|
72
|
+
# @param [String] str
|
73
|
+
# @return [String]
|
74
|
+
def to_xml_string(str = '')
|
75
|
+
super(str) do
|
76
|
+
if color
|
77
|
+
str << '<c:spPr><a:solidFill>'
|
78
|
+
str << ('<a:srgbClr val="' << color << '"/>')
|
79
|
+
str << '</a:solidFill>'
|
80
|
+
str << '<a:ln w="28800">'
|
81
|
+
str << '<a:solidFill>'
|
82
|
+
str << ('<a:srgbClr val="' << color << '"/>')
|
83
|
+
str << '</a:solidFill>'
|
84
|
+
str << '</a:ln>'
|
85
|
+
str << '<a:round/>'
|
86
|
+
str << '</c:spPr>'
|
87
|
+
end
|
88
|
+
|
89
|
+
if !@show_marker
|
90
|
+
str << '<c:marker><c:symbol val="none"/></c:marker>'
|
91
|
+
elsif @marker_symbol != :default
|
92
|
+
str << '<c:marker><c:symbol val="' + @marker_symbol.to_s + '"/></c:marker>'
|
93
|
+
end
|
94
|
+
|
95
|
+
@labels.to_xml_string(str) unless @labels.nil?
|
96
|
+
@data.to_xml_string(str) unless @data.nil?
|
97
|
+
str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
# assigns the data for this series
|
104
|
+
def data=(v) DataTypeValidator.validate "Series.data", [NumDataSource], v; @data = v; end
|
105
|
+
|
106
|
+
# assigns the labels for this series
|
107
|
+
def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|