axlsx 1.0.0
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/Rakefile +13 -0
- data/lib/axlsx.rb +38 -0
- data/lib/axlsx/content_type/content_type.rb +23 -0
- data/lib/axlsx/content_type/default.rb +32 -0
- data/lib/axlsx/content_type/override.rb +30 -0
- data/lib/axlsx/doc_props/app.rb +148 -0
- data/lib/axlsx/doc_props/core.rb +34 -0
- data/lib/axlsx/drawing/axis.rb +78 -0
- data/lib/axlsx/drawing/bar_3D_chart.rb +138 -0
- data/lib/axlsx/drawing/bar_series.rb +91 -0
- data/lib/axlsx/drawing/cat_axis.rb +58 -0
- data/lib/axlsx/drawing/chart.rb +120 -0
- data/lib/axlsx/drawing/drawing.rb +121 -0
- data/lib/axlsx/drawing/graphic_frame.rb +55 -0
- data/lib/axlsx/drawing/marker.rb +57 -0
- data/lib/axlsx/drawing/pie_3D_chart.rb +59 -0
- data/lib/axlsx/drawing/pie_series.rb +88 -0
- data/lib/axlsx/drawing/scaling.rb +53 -0
- data/lib/axlsx/drawing/series.rb +70 -0
- data/lib/axlsx/drawing/title.rb +69 -0
- data/lib/axlsx/drawing/two_cell_anchor.rb +88 -0
- data/lib/axlsx/drawing/val_axis.rb +34 -0
- data/lib/axlsx/drawing/view_3D.rb +72 -0
- data/lib/axlsx/package.rb +181 -0
- data/lib/axlsx/rels/relationship.rb +43 -0
- data/lib/axlsx/rels/relationships.rb +25 -0
- data/lib/axlsx/stylesheet/border.rb +52 -0
- data/lib/axlsx/stylesheet/border_pr.rb +65 -0
- data/lib/axlsx/stylesheet/cell_alignment.rb +96 -0
- data/lib/axlsx/stylesheet/cell_protection.rb +33 -0
- data/lib/axlsx/stylesheet/cell_style.rb +60 -0
- data/lib/axlsx/stylesheet/color.rb +57 -0
- data/lib/axlsx/stylesheet/fill.rb +31 -0
- data/lib/axlsx/stylesheet/font.rb +128 -0
- data/lib/axlsx/stylesheet/gradient_fill.rb +70 -0
- data/lib/axlsx/stylesheet/gradient_stop.rb +31 -0
- data/lib/axlsx/stylesheet/num_fmt.rb +61 -0
- data/lib/axlsx/stylesheet/pattern_fill.rb +64 -0
- data/lib/axlsx/stylesheet/styles.rb +296 -0
- data/lib/axlsx/stylesheet/table_style.rb +44 -0
- data/lib/axlsx/stylesheet/table_style_element.rb +66 -0
- data/lib/axlsx/stylesheet/table_styles.rb +39 -0
- data/lib/axlsx/stylesheet/xf.rb +117 -0
- data/lib/axlsx/util/constants.rb +189 -0
- data/lib/axlsx/util/simple_typed_list.rb +150 -0
- data/lib/axlsx/util/validators.rb +132 -0
- data/lib/axlsx/workbook/workbook.rb +130 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +184 -0
- data/lib/axlsx/workbook/worksheet/row.rb +92 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +194 -0
- data/lib/schema/dc.xsd +118 -0
- data/lib/schema/dcmitype.xsd +50 -0
- data/lib/schema/dcterms.xsd +331 -0
- data/lib/schema/dml-chart.xsd +1499 -0
- data/lib/schema/dml-chartDrawing.xsd +146 -0
- data/lib/schema/dml-compatibility.xsd +14 -0
- data/lib/schema/dml-diagram.xsd +1091 -0
- data/lib/schema/dml-lockedCanvas.xsd +11 -0
- data/lib/schema/dml-main.xsd +3048 -0
- data/lib/schema/dml-picture.xsd +23 -0
- data/lib/schema/dml-spreadsheetDrawing.xsd +185 -0
- data/lib/schema/dml-wordprocessingDrawing.xsd +185 -0
- data/lib/schema/opc-contentTypes.xsd +42 -0
- data/lib/schema/opc-coreProperties.xsd +50 -0
- data/lib/schema/opc-digSig.xsd +49 -0
- data/lib/schema/opc-relationships.xsd +33 -0
- data/lib/schema/pml.xsd +1676 -0
- data/lib/schema/shared-additionalCharacteristics.xsd +28 -0
- data/lib/schema/shared-bibliography.xsd +144 -0
- data/lib/schema/shared-commonSimpleTypes.xsd +166 -0
- data/lib/schema/shared-customXmlDataProperties.xsd +25 -0
- data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -0
- data/lib/schema/shared-documentPropertiesCustom.xsd +59 -0
- data/lib/schema/shared-documentPropertiesExtended.xsd +56 -0
- data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -0
- data/lib/schema/shared-math.xsd +582 -0
- data/lib/schema/shared-relationshipReference.xsd +25 -0
- data/lib/schema/sml.xsd +4430 -0
- data/lib/schema/vml-main.xsd +569 -0
- data/lib/schema/vml-officeDrawing.xsd +509 -0
- data/lib/schema/vml-presentationDrawing.xsd +12 -0
- data/lib/schema/vml-spreadsheetDrawing.xsd +108 -0
- data/lib/schema/vml-wordprocessingDrawing.xsd +96 -0
- data/lib/schema/wml.xsd +3644 -0
- data/lib/schema/xml.xsd +117 -0
- data/test/content_type/tc_content_type.rb +81 -0
- data/test/content_type/tc_content_type.rb~ +81 -0
- data/test/content_type/tc_default.rb +40 -0
- data/test/content_type/tc_default.rb~ +40 -0
- data/test/content_type/tc_override.rb +40 -0
- data/test/content_type/tc_override.rb~ +40 -0
- data/test/doc_props/tc_app.rb +19 -0
- data/test/doc_props/tc_app.rb~ +19 -0
- data/test/doc_props/tc_core.rb +34 -0
- data/test/drawing/tc_axis.rb +39 -0
- data/test/drawing/tc_axis.rb~ +0 -0
- data/test/drawing/tc_bar_3D_chart.rb +66 -0
- data/test/drawing/tc_bar_3D_chart.rb~ +4 -0
- data/test/drawing/tc_bar_series.rb +34 -0
- data/test/drawing/tc_bar_series.rb~ +31 -0
- data/test/drawing/tc_cat_axis.rb +32 -0
- data/test/drawing/tc_cat_axis.rb~ +39 -0
- data/test/drawing/tc_chart.rb +59 -0
- data/test/drawing/tc_chart.rb~ +58 -0
- data/test/drawing/tc_drawing.rb +71 -0
- data/test/drawing/tc_graphic_frame.rb +26 -0
- data/test/drawing/tc_graphic_frame.rb~ +21 -0
- data/test/drawing/tc_marker.rb +45 -0
- data/test/drawing/tc_marker.rb~ +26 -0
- data/test/drawing/tc_pie_3D_chart.rb +33 -0
- data/test/drawing/tc_pie_3D_chart.rb~ +58 -0
- data/test/drawing/tc_pie_series.rb +35 -0
- data/test/drawing/tc_pie_series.rb~ +26 -0
- data/test/drawing/tc_scaling.rb +37 -0
- data/test/drawing/tc_scaling.rb~ +45 -0
- data/test/drawing/tc_series.rb +24 -0
- data/test/drawing/tc_series.rb~ +31 -0
- data/test/drawing/tc_title.rb +34 -0
- data/test/drawing/tc_title.rb~ +37 -0
- data/test/drawing/tc_two_cell_anchor.rb +37 -0
- data/test/drawing/tc_two_cell_anchor.rb~ +35 -0
- data/test/drawing/tc_val_axis.rb +20 -0
- data/test/drawing/tc_val_axis.rb~ +32 -0
- data/test/drawing/tc_view_3D.rb +46 -0
- data/test/drawing/tc_view_3D.rb~ +37 -0
- data/test/rels/tc_relationship.rb +16 -0
- data/test/rels/tc_relationship.rb~ +39 -0
- data/test/rels/tc_relationships.rb +32 -0
- data/test/rels/tc_relationships.rb~ +37 -0
- data/test/stylesheet/tc_border.rb +38 -0
- data/test/stylesheet/tc_border.rb~ +31 -0
- data/test/stylesheet/tc_border_pr.rb +33 -0
- data/test/stylesheet/tc_border_pr.rb~ +31 -0
- data/test/stylesheet/tc_cell_alignment.rb +77 -0
- data/test/stylesheet/tc_cell_alignment.rb~ +38 -0
- data/test/stylesheet/tc_cell_protection.rb +30 -0
- data/test/stylesheet/tc_cell_protection.rb~ +77 -0
- data/test/stylesheet/tc_cell_style.rb +58 -0
- data/test/stylesheet/tc_cell_style.rb~ +30 -0
- data/test/stylesheet/tc_color.rb +38 -0
- data/test/stylesheet/tc_color.rb~ +38 -0
- data/test/stylesheet/tc_fill.rb +19 -0
- data/test/stylesheet/tc_fill.rb~ +19 -0
- data/test/stylesheet/tc_font.rb +114 -0
- data/test/stylesheet/tc_font.rb~ +19 -0
- data/test/stylesheet/tc_gradient_fill.rb +65 -0
- data/test/stylesheet/tc_gradient_fill.rb~ +114 -0
- data/test/stylesheet/tc_gradient_stop.rb +32 -0
- data/test/stylesheet/tc_gradient_stop.rb~ +65 -0
- data/test/stylesheet/tc_num_fmt.rb +31 -0
- data/test/stylesheet/tc_num_fmt.rb~ +32 -0
- data/test/stylesheet/tc_pattern_fill.rb +38 -0
- data/test/stylesheet/tc_pattern_fill.rb~ +31 -0
- data/test/stylesheet/tc_styles.rb +64 -0
- data/test/stylesheet/tc_table_style.rb +37 -0
- data/test/stylesheet/tc_table_style.rb~ +38 -0
- data/test/stylesheet/tc_table_style_element.rb +37 -0
- data/test/stylesheet/tc_table_style_element.rb~ +37 -0
- data/test/stylesheet/tc_table_styles.rb +30 -0
- data/test/stylesheet/tc_table_styles.rb~ +37 -0
- data/test/stylesheet/tc_xf.rb +121 -0
- data/test/stylesheet/tc_xf.rb~ +30 -0
- data/test/tc_app.rb~ +19 -0
- data/test/tc_border_pr.rb~ +21 -0
- data/test/tc_package.rb +70 -0
- data/test/tc_package.rb~ +64 -0
- data/test/tc_pie_3D_chart.rb~ +66 -0
- data/test/tc_relationships.rb~ +37 -0
- data/test/tc_series.rb~ +31 -0
- data/test/tc_styles.rb~ +64 -0
- data/test/tc_validators.rb~ +77 -0
- data/test/tc_worksheet.rb~ +85 -0
- data/test/util/tc_simple_typed_list.rb +66 -0
- data/test/util/tc_validators.rb +76 -0
- data/test/workbook/tc_workbook.rb +53 -0
- data/test/workbook/worksheet/tc_cell.rb +78 -0
- data/test/workbook/worksheet/tc_row.rb +30 -0
- data/test/workbook/worksheet/tc_worksheet.rb +85 -0
- metadata +378 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# A Row is a single row in a worksheet.
|
3
|
+
# @note The recommended way to manage rows and cells is to use Worksheet#add_row
|
4
|
+
# @see Worksheet#add_row
|
5
|
+
class Row
|
6
|
+
|
7
|
+
# The worksheet this row belongs to
|
8
|
+
# @return [Worksheet]
|
9
|
+
attr_reader :worksheet
|
10
|
+
|
11
|
+
# The cells this row holds
|
12
|
+
# @return [SimpleTypedList]
|
13
|
+
attr_reader :cells
|
14
|
+
|
15
|
+
# The index of this row in the worksheet
|
16
|
+
# @return [Integer]
|
17
|
+
attr_reader :index
|
18
|
+
|
19
|
+
# Creates a new row. New Cell objects are created based on the values, types and style options.
|
20
|
+
# A new cell is created for each item in the values array. style and types options are applied as follows:
|
21
|
+
# If the types option is defined and is a symbol it is applied to all the cells created.
|
22
|
+
# If the types option is an array, cell types are applied by index for each cell
|
23
|
+
# If the types option is not set, the cell will automatically determine its type.
|
24
|
+
# If the style option is defined and is an Integer, it is applied to all cells created.
|
25
|
+
# If the style option is an array, style is applied by index for each cell.
|
26
|
+
# If the style option is not defined, the default style (0) is applied to each cell.
|
27
|
+
# @param [Worksheet] worksheet
|
28
|
+
# @option options [Array] values
|
29
|
+
# @option options [Array, Symbol] types
|
30
|
+
# @option options [Array, Integer] style
|
31
|
+
# @see Row#array_to_cells
|
32
|
+
# @see Cell
|
33
|
+
def initialize(worksheet, options={})
|
34
|
+
self.worksheet = worksheet
|
35
|
+
@cells = SimpleTypedList.new Cell
|
36
|
+
@worksheet.rows << self
|
37
|
+
array_to_cells(options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def index
|
41
|
+
worksheet.rows.index(self)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Serializes the row
|
45
|
+
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
46
|
+
# @return [String]
|
47
|
+
def to_xml(xml)
|
48
|
+
xml.row(:r => index+1) { @cells.each { |cell| cell.to_xml(xml) } }
|
49
|
+
end
|
50
|
+
|
51
|
+
# Adds a singel sell to the row based on the data provided and updates the worksheet's autofit data.
|
52
|
+
# @return [Cell]
|
53
|
+
def add_cell(value="", options={})
|
54
|
+
c = Cell.new(self, value, options)
|
55
|
+
update_auto_fit_data
|
56
|
+
c
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# assigns the owning worksheet for this row
|
63
|
+
def worksheet=(v) DataTypeValidator.validate "Row.worksheet", Worksheet, v; @worksheet=v; end
|
64
|
+
|
65
|
+
# Tell the worksheet to update autofit data for the columns based on this row's cells.
|
66
|
+
# @return [SimpleTypedList]
|
67
|
+
def update_auto_fit_data
|
68
|
+
worksheet.send(:update_auto_fit_data, self.cells)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Converts values, types, and style options into cells and associates them with this row.
|
72
|
+
# A new cell is created for each item in the values array.
|
73
|
+
# If value option is defined and is a symbol it is applied to all the cells created.
|
74
|
+
# If the value option is an array, cell types are applied by index for each cell
|
75
|
+
# If the style option is defined and is an Integer, it is applied to all cells created.
|
76
|
+
# If the style option is an array, style is applied by index for each cell.
|
77
|
+
# @option options [Array] values
|
78
|
+
# @option options [Array, Symbol] types
|
79
|
+
# @option options [Array, Integer] style
|
80
|
+
def array_to_cells(options={})
|
81
|
+
values = options[:values] || []
|
82
|
+
DataTypeValidator.validate 'Row.array_to_cells', Array, values
|
83
|
+
types, style = options[:types], options[:style]
|
84
|
+
values.each_with_index do |value, index|
|
85
|
+
cell_style = style.is_a?(Array) ? style[index] : style
|
86
|
+
cell_type = types.is_a?(Array)? types[index] : types
|
87
|
+
Cell.new(self, value, :style=>cell_style, :type=>cell_type)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Axlsx
|
3
|
+
|
4
|
+
# The Worksheet class represents a worksheet in the workbook.
|
5
|
+
class Worksheet
|
6
|
+
|
7
|
+
# The name of the worksheet
|
8
|
+
# If not specified, it is Sheet#{index} where index is this worksheets index in the workbook's worksheet collection.
|
9
|
+
# @return [String]
|
10
|
+
attr_accessor :name
|
11
|
+
|
12
|
+
# The workbook that owns this worksheet
|
13
|
+
# @return [Workbook]
|
14
|
+
attr_reader :workbook
|
15
|
+
|
16
|
+
# The worksheet relationships. This is managed automatically by the worksheet
|
17
|
+
# @return [Relationships]
|
18
|
+
attr_reader :relationships
|
19
|
+
|
20
|
+
# The rows in this worksheet
|
21
|
+
# @note The recommended way to manage rows is Worksheet#add_row
|
22
|
+
# @return [SimpleTypedList]
|
23
|
+
# @see Worksheet#add_row
|
24
|
+
attr_reader :rows
|
25
|
+
|
26
|
+
# The drawing associated with this worksheet.
|
27
|
+
# @note the recommended way to work with drawings and charts is Worksheet#add_chart
|
28
|
+
# @return [Drawing]
|
29
|
+
# @see Worksheet#add_chart
|
30
|
+
attr_reader :drawing
|
31
|
+
|
32
|
+
# An array of content based calculated column widths.
|
33
|
+
# @note a single auto fit data item is a hash with :longest => [String] and :sz=> [Integer] members.
|
34
|
+
# @return [Array] of Hash
|
35
|
+
attr_reader :auto_fit_data
|
36
|
+
|
37
|
+
# The part name of this worksheet
|
38
|
+
# @return [String]
|
39
|
+
attr_reader :pn
|
40
|
+
|
41
|
+
# The relationship part name of this worksheet
|
42
|
+
# @return [String]
|
43
|
+
attr_reader :rels_pn
|
44
|
+
|
45
|
+
# The relationship Id of thiw worksheet
|
46
|
+
# @return [String]
|
47
|
+
attr_reader :rId
|
48
|
+
|
49
|
+
# The index of this worksheet in the owning Workbook's worksheets list.
|
50
|
+
# @return [Index]
|
51
|
+
attr_reader :index
|
52
|
+
|
53
|
+
# TODO Merge Cells
|
54
|
+
# attr_reader :merge_cells
|
55
|
+
|
56
|
+
# Creates a new worksheet.
|
57
|
+
# @note the recommended way to manage worksheets is Workbook#add_worksheet
|
58
|
+
# @see Workbook#add_worksheet
|
59
|
+
# @option options [String] name The name of this sheet.
|
60
|
+
def initialize(wb, options={})
|
61
|
+
@rows = SimpleTypedList.new Row
|
62
|
+
self.workbook = wb
|
63
|
+
@workbook.worksheets << self
|
64
|
+
@auto_fit_data = []
|
65
|
+
self.name = options[:name] || "Sheet" + (index+1).to_s
|
66
|
+
@magick_draw = Magick::Draw.new
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def name=(v) DataTypeValidator.validate "Worksheet.name", String, v; @name=v end
|
71
|
+
|
72
|
+
def pn
|
73
|
+
"#{WORKSHEET_PN % (index+1)}"
|
74
|
+
end
|
75
|
+
|
76
|
+
def rels_pn
|
77
|
+
"#{WORKSHEET_RELS_PN % (index+1)}"
|
78
|
+
end
|
79
|
+
|
80
|
+
def rId
|
81
|
+
"rId#{index+1}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def index
|
85
|
+
@workbook.worksheets.index(self)
|
86
|
+
end
|
87
|
+
|
88
|
+
def drawing
|
89
|
+
@drawing || @drawing = Axlsx::Drawing.new(self)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Adds a row to the worksheet and updates auto fit data
|
93
|
+
# @return [Row]
|
94
|
+
# @option options [Array] values
|
95
|
+
# @option options [Array, Symbol] types
|
96
|
+
# @option options [Array, Integer] style
|
97
|
+
def add_row(options={})
|
98
|
+
Row.new(self, options)
|
99
|
+
update_auto_fit_data @rows.last.cells
|
100
|
+
yield @rows.last if block_given?
|
101
|
+
@rows.last
|
102
|
+
end
|
103
|
+
|
104
|
+
# Adds a chart to this worksheets drawing.
|
105
|
+
# @param [Class] chart_type
|
106
|
+
# @option options [Array] start_at
|
107
|
+
# @option options [Array] end_at
|
108
|
+
# @option options [Cell, String] title
|
109
|
+
def add_chart(chart_type, options={})
|
110
|
+
chart = drawing.add_chart(chart_type, options)
|
111
|
+
yield chart if block_given?
|
112
|
+
chart
|
113
|
+
end
|
114
|
+
|
115
|
+
# Serializes the worksheet document
|
116
|
+
# @return [String]
|
117
|
+
def to_xml
|
118
|
+
builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
|
119
|
+
xml.worksheet(:xmlns => XML_NS, :'xmlns:r' => XML_NS_R) {
|
120
|
+
if @auto_fit_data.size > 0
|
121
|
+
xml.cols {
|
122
|
+
@auto_fit_data.each_with_index do |col, index|
|
123
|
+
min_max = index+1
|
124
|
+
xml.col(:min=>min_max, :max=>min_max, :width => auto_width(col), :customWidth=>"true")
|
125
|
+
end
|
126
|
+
}
|
127
|
+
end
|
128
|
+
xml.sheetData {
|
129
|
+
@rows.each do |row|
|
130
|
+
row.to_xml(xml)
|
131
|
+
end
|
132
|
+
}
|
133
|
+
xml.drawing :"r:id"=>"rId1" if @drawing
|
134
|
+
}
|
135
|
+
end
|
136
|
+
builder.to_xml(:indent=>0, :save_with=>0)
|
137
|
+
end
|
138
|
+
|
139
|
+
# The worksheet's relationships.
|
140
|
+
def relationships
|
141
|
+
r = Relationships.new
|
142
|
+
r << Relationship.new(DRAWING_R, "../#{@drawing.pn}") if @drawing
|
143
|
+
r
|
144
|
+
end
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
# assigns the owner workbook for this worksheet
|
149
|
+
def workbook=(v) DataTypeValidator.validate "Worksheet.workbook", Workbook, v; @workbook = v; end
|
150
|
+
|
151
|
+
# Updates auto fit data.
|
152
|
+
# Autofit data attempts to determine the cell in a column that has the greatest width by comparing the length of the text multiplied by the size of the font.
|
153
|
+
# @return [Array] of Cell objects
|
154
|
+
# @param [Array] cells an array of cells
|
155
|
+
def update_auto_fit_data(cells)
|
156
|
+
styles = self.workbook.styles
|
157
|
+
cellXfs, fonts = styles.cellXfs, styles.fonts
|
158
|
+
sz = fonts[0].sz
|
159
|
+
|
160
|
+
cells.each_with_index do |item, index|
|
161
|
+
col = @auto_fit_data[index] || {:longest=>"", :sz=>sz}
|
162
|
+
cell_xf = cellXfs[item.style]
|
163
|
+
font = fonts[cell_xf.fontId || 0]
|
164
|
+
sz = font.sz || sz
|
165
|
+
|
166
|
+
if (col[:longest].scan(/./mu).size * col[:sz]) < (item.value.to_s.scan(/./mu).size * sz)
|
167
|
+
col[:sz] = sz
|
168
|
+
col[:longest] = item.value.to_s
|
169
|
+
end
|
170
|
+
@auto_fit_data[index] = col
|
171
|
+
end
|
172
|
+
cells
|
173
|
+
end
|
174
|
+
|
175
|
+
# Determines the proper width for a column based on content.
|
176
|
+
# @note
|
177
|
+
# From ECMA docs
|
178
|
+
# Column width measured as the number of characters of the maximum digit width of the numbers 0 .. 9 as
|
179
|
+
# 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.
|
180
|
+
# width = Truncate([{Number of Characters} * {Maximum Digit Width} + {5 pixel padding}]/{Maximum Digit Width}*256)/256
|
181
|
+
# @return [Float]
|
182
|
+
# @param [Hash] A hash of auto_fit_data
|
183
|
+
def auto_width(col)
|
184
|
+
mdw = 6.0 # maximum digit with is always 6.0 in testable fonts so instead of beating RMagick every time, I am hardcoding it here.
|
185
|
+
mdw_count = 0
|
186
|
+
best_guess = 1.5 #direct testing shows the results of the documented formula to be a bit too small. This is a best guess scaling
|
187
|
+
font_scale = col[:sz].to_f / (self.workbook.styles.fonts[0].sz.to_f || 11.0)
|
188
|
+
col[:longest].scan(/./mu).each do |i|
|
189
|
+
mdw_count +=1 if @magick_draw.get_type_metrics(i).width >= mdw
|
190
|
+
end
|
191
|
+
((mdw_count * mdw + 5) / mdw * 256) / 256.0 * best_guess * font_scale
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
data/lib/schema/dc.xsd
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
3
|
+
xmlns="http://purl.org/dc/elements/1.1/"
|
4
|
+
targetNamespace="http://purl.org/dc/elements/1.1/"
|
5
|
+
elementFormDefault="qualified"
|
6
|
+
attributeFormDefault="unqualified">
|
7
|
+
|
8
|
+
<xs:annotation>
|
9
|
+
<xs:documentation xml:lang="en">
|
10
|
+
DCMES 1.1 XML Schema
|
11
|
+
XML Schema for http://purl.org/dc/elements/1.1/ namespace
|
12
|
+
|
13
|
+
Created 2003-04-02
|
14
|
+
|
15
|
+
Created by
|
16
|
+
|
17
|
+
Tim Cole (t-cole3@uiuc.edu)
|
18
|
+
Tom Habing (thabing@uiuc.edu)
|
19
|
+
Jane Hunter (jane@dstc.edu.au)
|
20
|
+
Pete Johnston (p.johnston@ukoln.ac.uk),
|
21
|
+
Carl Lagoze (lagoze@cs.cornell.edu)
|
22
|
+
|
23
|
+
This schema declares XML elements for the 15 DC elements from the
|
24
|
+
http://purl.org/dc/elements/1.1/ namespace.
|
25
|
+
|
26
|
+
It defines a complexType SimpleLiteral which permits mixed content
|
27
|
+
and makes the xml:lang attribute available. It disallows child elements by
|
28
|
+
use of minOcccurs/maxOccurs.
|
29
|
+
|
30
|
+
However, this complexType does permit the derivation of other complexTypes
|
31
|
+
which would permit child elements.
|
32
|
+
|
33
|
+
All elements are declared as substitutable for the abstract element any,
|
34
|
+
which means that the default type for all elements is dc:SimpleLiteral.
|
35
|
+
|
36
|
+
</xs:documentation>
|
37
|
+
|
38
|
+
</xs:annotation>
|
39
|
+
|
40
|
+
|
41
|
+
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
|
42
|
+
schemaLocation="xml.xsd">
|
43
|
+
</xs:import>
|
44
|
+
|
45
|
+
<xs:complexType name="SimpleLiteral">
|
46
|
+
<xs:annotation>
|
47
|
+
<xs:documentation xml:lang="en">
|
48
|
+
This is the default type for all of the DC elements.
|
49
|
+
It permits text content only with optional
|
50
|
+
xml:lang attribute.
|
51
|
+
Text is allowed because mixed="true", but sub-elements
|
52
|
+
are disallowed because minOccurs="0" and maxOccurs="0"
|
53
|
+
are on the xs:any tag.
|
54
|
+
|
55
|
+
This complexType allows for restriction or extension permitting
|
56
|
+
child elements.
|
57
|
+
</xs:documentation>
|
58
|
+
</xs:annotation>
|
59
|
+
|
60
|
+
<xs:complexContent mixed="true">
|
61
|
+
<xs:restriction base="xs:anyType">
|
62
|
+
<xs:sequence>
|
63
|
+
<xs:any processContents="lax" minOccurs="0" maxOccurs="0"/>
|
64
|
+
</xs:sequence>
|
65
|
+
<xs:attribute ref="xml:lang" use="optional"/>
|
66
|
+
</xs:restriction>
|
67
|
+
</xs:complexContent>
|
68
|
+
</xs:complexType>
|
69
|
+
|
70
|
+
<xs:element name="any" type="SimpleLiteral" abstract="true"/>
|
71
|
+
|
72
|
+
<xs:element name="title" substitutionGroup="any"/>
|
73
|
+
<xs:element name="creator" substitutionGroup="any"/>
|
74
|
+
<xs:element name="subject" substitutionGroup="any"/>
|
75
|
+
<xs:element name="description" substitutionGroup="any"/>
|
76
|
+
<xs:element name="publisher" substitutionGroup="any"/>
|
77
|
+
<xs:element name="contributor" substitutionGroup="any"/>
|
78
|
+
<xs:element name="date" substitutionGroup="any"/>
|
79
|
+
<xs:element name="type" substitutionGroup="any"/>
|
80
|
+
<xs:element name="format" substitutionGroup="any"/>
|
81
|
+
<xs:element name="identifier" substitutionGroup="any"/>
|
82
|
+
<xs:element name="source" substitutionGroup="any"/>
|
83
|
+
<xs:element name="language" substitutionGroup="any"/>
|
84
|
+
<xs:element name="relation" substitutionGroup="any"/>
|
85
|
+
<xs:element name="coverage" substitutionGroup="any"/>
|
86
|
+
<xs:element name="rights" substitutionGroup="any"/>
|
87
|
+
|
88
|
+
<xs:group name="elementsGroup">
|
89
|
+
<xs:annotation>
|
90
|
+
<xs:documentation xml:lang="en">
|
91
|
+
This group is included as a convenience for schema authors
|
92
|
+
who need to refer to all the elements in the
|
93
|
+
http://purl.org/dc/elements/1.1/ namespace.
|
94
|
+
</xs:documentation>
|
95
|
+
</xs:annotation>
|
96
|
+
|
97
|
+
<xs:sequence>
|
98
|
+
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
99
|
+
<xs:element ref="any"/>
|
100
|
+
</xs:choice>
|
101
|
+
</xs:sequence>
|
102
|
+
</xs:group>
|
103
|
+
|
104
|
+
<xs:complexType name="elementContainer">
|
105
|
+
<xs:annotation>
|
106
|
+
<xs:documentation xml:lang="en">
|
107
|
+
This complexType is included as a convenience for schema authors who need to define a root
|
108
|
+
or container element for all of the DC elements.
|
109
|
+
</xs:documentation>
|
110
|
+
</xs:annotation>
|
111
|
+
|
112
|
+
<xs:choice>
|
113
|
+
<xs:group ref="elementsGroup"/>
|
114
|
+
</xs:choice>
|
115
|
+
</xs:complexType>
|
116
|
+
|
117
|
+
|
118
|
+
</xs:schema>
|
@@ -0,0 +1,50 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
3
|
+
xmlns="http://purl.org/dc/dcmitype/"
|
4
|
+
targetNamespace="http://purl.org/dc/dcmitype/"
|
5
|
+
elementFormDefault="qualified"
|
6
|
+
attributeFormDefault="unqualified">
|
7
|
+
|
8
|
+
<xs:annotation>
|
9
|
+
<xs:documentation xml:lang="en">
|
10
|
+
DCMI Type Vocabulary XML Schema
|
11
|
+
XML Schema for http://purl.org/dc/dcmitype/ namespace
|
12
|
+
|
13
|
+
Created 2003-04-02
|
14
|
+
|
15
|
+
Created by
|
16
|
+
|
17
|
+
Tim Cole (t-cole3@uiuc.edu)
|
18
|
+
Tom Habing (thabing@uiuc.edu)
|
19
|
+
Jane Hunter (jane@dstc.edu.au)
|
20
|
+
Pete Johnston (p.johnston@ukoln.ac.uk),
|
21
|
+
Carl Lagoze (lagoze@cs.cornell.edu)
|
22
|
+
|
23
|
+
This schema defines a simpleType which enumerates
|
24
|
+
the allowable values for the DCMI Type Vocabulary.
|
25
|
+
</xs:documentation>
|
26
|
+
|
27
|
+
|
28
|
+
</xs:annotation>
|
29
|
+
|
30
|
+
|
31
|
+
<xs:simpleType name="DCMIType">
|
32
|
+
<xs:union>
|
33
|
+
<xs:simpleType>
|
34
|
+
<xs:restriction base="xs:Name">
|
35
|
+
<xs:enumeration value="Collection"/>
|
36
|
+
<xs:enumeration value="Dataset"/>
|
37
|
+
<xs:enumeration value="Event"/>
|
38
|
+
<xs:enumeration value="Image"/>
|
39
|
+
<xs:enumeration value="InteractiveResource"/>
|
40
|
+
<xs:enumeration value="Service"/>
|
41
|
+
<xs:enumeration value="Software"/>
|
42
|
+
<xs:enumeration value="Sound"/>
|
43
|
+
<xs:enumeration value="Text"/>
|
44
|
+
<xs:enumeration value="PhysicalObject"/>
|
45
|
+
</xs:restriction>
|
46
|
+
</xs:simpleType>
|
47
|
+
</xs:union>
|
48
|
+
</xs:simpleType>
|
49
|
+
|
50
|
+
</xs:schema>
|