axlsx 1.0.18 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +11 -3
- data/README.md +93 -18
- data/examples/example.csv +1000 -0
- data/examples/example.rb +97 -5
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/lib/axlsx.rb +30 -9
- data/lib/axlsx/content_type/content_type.rb +9 -9
- data/lib/axlsx/content_type/default.rb +9 -6
- data/lib/axlsx/content_type/override.rb +12 -8
- data/lib/axlsx/doc_props/app.rb +37 -40
- data/lib/axlsx/doc_props/core.rb +12 -17
- data/lib/axlsx/drawing/axis.rb +38 -19
- data/lib/axlsx/drawing/bar_3D_chart.rb +33 -32
- data/lib/axlsx/drawing/bar_series.rb +13 -14
- data/lib/axlsx/drawing/cat_axis.rb +15 -14
- data/lib/axlsx/drawing/cat_axis_data.rb +16 -18
- data/lib/axlsx/drawing/chart.rb +37 -38
- data/lib/axlsx/drawing/drawing.rb +15 -12
- data/lib/axlsx/drawing/graphic_frame.rb +21 -21
- data/lib/axlsx/drawing/hyperlink.rb +12 -11
- data/lib/axlsx/drawing/line_3D_chart.rb +30 -28
- data/lib/axlsx/drawing/line_series.rb +11 -11
- data/lib/axlsx/drawing/marker.rb +10 -8
- data/lib/axlsx/drawing/named_axis_data.rb +36 -0
- data/lib/axlsx/drawing/one_cell_anchor.rb +17 -16
- data/lib/axlsx/drawing/pic.rb +24 -37
- data/lib/axlsx/drawing/picture_locking.rb +21 -18
- data/lib/axlsx/drawing/pie_3D_chart.rb +10 -8
- data/lib/axlsx/drawing/pie_series.rb +15 -12
- data/lib/axlsx/drawing/scaling.rb +10 -10
- data/lib/axlsx/drawing/scatter_chart.rb +69 -0
- data/lib/axlsx/drawing/scatter_series.rb +39 -0
- data/lib/axlsx/drawing/ser_axis.rb +10 -10
- data/lib/axlsx/drawing/series.rb +15 -15
- data/lib/axlsx/drawing/series_title.rb +14 -14
- data/lib/axlsx/drawing/title.rb +26 -26
- data/lib/axlsx/drawing/two_cell_anchor.rb +18 -20
- data/lib/axlsx/drawing/val_axis.rb +8 -7
- data/lib/axlsx/drawing/val_axis_data.rb +17 -17
- data/lib/axlsx/drawing/view_3D.rb +22 -20
- data/lib/axlsx/package.rb +32 -15
- data/lib/axlsx/rels/relationship.rb +9 -6
- data/lib/axlsx/rels/relationships.rb +7 -1
- data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
- data/lib/axlsx/stylesheet/border.rb +27 -23
- data/lib/axlsx/stylesheet/border_pr.rb +16 -15
- data/lib/axlsx/stylesheet/cell_alignment.rb +23 -21
- data/lib/axlsx/stylesheet/cell_protection.rb +10 -7
- data/lib/axlsx/stylesheet/cell_style.rb +8 -5
- data/lib/axlsx/stylesheet/color.rb +20 -14
- data/lib/axlsx/stylesheet/fill.rb +7 -5
- data/lib/axlsx/stylesheet/font.rb +14 -14
- data/lib/axlsx/stylesheet/gradient_fill.rb +19 -16
- data/lib/axlsx/stylesheet/gradient_stop.rb +9 -5
- data/lib/axlsx/stylesheet/num_fmt.rb +12 -6
- data/lib/axlsx/stylesheet/pattern_fill.rb +25 -10
- data/lib/axlsx/stylesheet/styles.rb +41 -32
- data/lib/axlsx/stylesheet/table_style.rb +9 -4
- data/lib/axlsx/stylesheet/table_style_element.rb +10 -7
- data/lib/axlsx/stylesheet/table_styles.rb +11 -8
- data/lib/axlsx/stylesheet/xf.rb +29 -25
- data/lib/axlsx/util/constants.rb +4 -0
- data/lib/axlsx/util/simple_typed_list.rb +18 -9
- data/lib/axlsx/util/validators.rb +13 -6
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +19 -21
- data/lib/axlsx/workbook/workbook.rb +43 -19
- data/lib/axlsx/workbook/worksheet/cell.rb +93 -91
- data/lib/axlsx/workbook/worksheet/col.rb +114 -0
- data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +16 -13
- data/lib/axlsx/workbook/worksheet/row.rb +13 -13
- data/lib/axlsx/workbook/worksheet/table.rb +96 -0
- data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +152 -118
- data/lib/schema/dc.xsd +5 -5
- data/lib/schema/dcmitype.xsd +5 -3
- data/lib/schema/dcterms.xsd +15 -15
- data/lib/schema/opc-coreProperties.xsd +6 -2
- data/lib/schema/xml.xsd +7 -8
- data/test/#benchmark.txt# +7 -0
- data/test/#tc_helper.rb# +3 -0
- data/test/benchmark.rb +81 -0
- data/test/benchmark.rb~ +0 -0
- data/test/benchmark.txt +6 -0
- data/test/benchmark.txt~ +6 -0
- data/test/content_type/tc_content_type.rb +30 -32
- data/test/content_type/tc_default.rb +8 -23
- data/test/content_type/tc_override.rb +7 -21
- data/test/doc_props/tc_app.rb +2 -8
- data/test/doc_props/tc_core.rb +6 -7
- data/test/drawing/tc_axis.rb +7 -3
- data/test/drawing/tc_bar_3D_chart.rb +6 -7
- data/test/drawing/tc_bar_series.rb +4 -5
- data/test/drawing/tc_cat_axis.rb +2 -3
- data/test/drawing/tc_cat_axis_data.rb +2 -3
- data/test/drawing/tc_chart.rb +11 -12
- data/test/drawing/tc_drawing.rb +7 -8
- data/test/drawing/tc_graphic_frame.rb +3 -4
- data/test/drawing/tc_hyperlink.rb +2 -3
- data/test/drawing/tc_line_3d_chart.rb +5 -6
- data/test/drawing/tc_line_series.rb +3 -4
- data/test/drawing/tc_marker.rb +3 -4
- data/test/drawing/tc_one_cell_anchor.rb +6 -7
- data/test/drawing/tc_pic.rb +8 -9
- data/test/drawing/tc_picture_locking.rb +2 -3
- data/test/drawing/tc_pie_3D_chart.rb +5 -6
- data/test/drawing/tc_pie_series.rb +4 -5
- data/test/drawing/tc_scaling.rb +3 -4
- data/test/drawing/tc_scatter_chart.rb +43 -0
- data/test/drawing/tc_scatter_series.rb +20 -0
- data/test/drawing/tc_ser_axis.rb +2 -3
- data/test/drawing/tc_series.rb +4 -5
- data/test/drawing/tc_series_title.rb +4 -5
- data/test/drawing/tc_title.rb +4 -5
- data/test/drawing/tc_two_cell_anchor.rb +4 -5
- data/test/drawing/tc_val_axis.rb +2 -3
- data/test/drawing/tc_val_axis_data.rb +2 -3
- data/test/drawing/tc_view_3D.rb +6 -7
- data/test/example.csv +1000 -0
- data/test/example.xlsx +0 -0
- data/test/example_streamed.xlsx +0 -0
- data/test/profile.rb +33 -0
- data/test/rels/tc_relationship.rb +5 -6
- data/test/rels/tc_relationships.rb +4 -5
- data/test/stylesheet/tc_border.rb +3 -4
- data/test/stylesheet/tc_border_pr.rb +3 -4
- data/test/stylesheet/tc_cell_alignment.rb +4 -5
- data/test/stylesheet/tc_cell_protection.rb +2 -3
- data/test/stylesheet/tc_cell_style.rb +2 -3
- data/test/stylesheet/tc_color.rb +2 -3
- data/test/stylesheet/tc_fill.rb +1 -2
- data/test/stylesheet/tc_font.rb +5 -6
- data/test/stylesheet/tc_gradient_fill.rb +1 -2
- data/test/stylesheet/tc_gradient_stop.rb +1 -2
- data/test/stylesheet/tc_num_fmt.rb +1 -2
- data/test/stylesheet/tc_pattern_fill.rb +3 -4
- data/test/stylesheet/tc_styles.rb +15 -9
- data/test/stylesheet/tc_table_style.rb +2 -3
- data/test/stylesheet/tc_table_style_element.rb +2 -3
- data/test/stylesheet/tc_table_styles.rb +3 -4
- data/test/stylesheet/tc_xf.rb +16 -17
- data/test/tc_axlsx.rb +39 -0
- data/test/tc_axlsx.rb~ +0 -0
- data/test/tc_helper.rb +3 -0
- data/test/tc_helper.rb~ +3 -0
- data/test/tc_package.rb +13 -10
- data/test/util/tc_simple_typed_list.rb +8 -9
- data/test/util/tc_validators.rb +7 -8
- data/test/workbook/tc_shared_strings_table.rb +5 -6
- data/test/workbook/tc_workbook.rb +24 -6
- data/test/workbook/worksheet/table/tc_table.rb +71 -0
- data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
- data/test/workbook/worksheet/tc_cell.rb +24 -10
- data/test/workbook/worksheet/tc_col.rb +59 -0
- data/test/workbook/worksheet/tc_col.rb~ +10 -0
- data/test/workbook/worksheet/tc_date_time_converter.rb +1 -2
- data/test/workbook/worksheet/tc_page_margins.rb +6 -9
- data/test/workbook/worksheet/tc_row.rb +26 -12
- data/test/workbook/worksheet/tc_worksheet.rb +134 -68
- metadata +150 -90
- data/test/drawing/tc_hyperlink.rb~ +0 -71
- data/test/workbook/tc_shared_strings_table.rb~ +0 -8
- data/test/workbook/worksheet/tc_date_time_converter.rb~ +0 -69
data/lib/schema/dc.xsd
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
Created 2003-04-02
|
14
14
|
|
15
|
-
Created by
|
15
|
+
Created by
|
16
16
|
|
17
17
|
Tim Cole (t-cole3@uiuc.edu)
|
18
18
|
Tom Habing (thabing@uiuc.edu)
|
@@ -23,14 +23,14 @@
|
|
23
23
|
This schema declares XML elements for the 15 DC elements from the
|
24
24
|
http://purl.org/dc/elements/1.1/ namespace.
|
25
25
|
|
26
|
-
It defines a complexType SimpleLiteral which permits mixed content
|
26
|
+
It defines a complexType SimpleLiteral which permits mixed content
|
27
27
|
and makes the xml:lang attribute available. It disallows child elements by
|
28
28
|
use of minOcccurs/maxOccurs.
|
29
29
|
|
30
30
|
However, this complexType does permit the derivation of other complexTypes
|
31
31
|
which would permit child elements.
|
32
32
|
|
33
|
-
All elements are declared as substitutable for the abstract element any,
|
33
|
+
All elements are declared as substitutable for the abstract element any,
|
34
34
|
which means that the default type for all elements is dc:SimpleLiteral.
|
35
35
|
|
36
36
|
</xs:documentation>
|
@@ -49,7 +49,7 @@
|
|
49
49
|
It permits text content only with optional
|
50
50
|
xml:lang attribute.
|
51
51
|
Text is allowed because mixed="true", but sub-elements
|
52
|
-
are disallowed because minOccurs="0" and maxOccurs="0"
|
52
|
+
are disallowed because minOccurs="0" and maxOccurs="0"
|
53
53
|
are on the xs:any tag.
|
54
54
|
|
55
55
|
This complexType allows for restriction or extension permitting
|
@@ -89,7 +89,7 @@
|
|
89
89
|
<xs:annotation>
|
90
90
|
<xs:documentation xml:lang="en">
|
91
91
|
This group is included as a convenience for schema authors
|
92
|
-
who need to refer to all the elements in the
|
92
|
+
who need to refer to all the elements in the
|
93
93
|
http://purl.org/dc/elements/1.1/ namespace.
|
94
94
|
</xs:documentation>
|
95
95
|
</xs:annotation>
|
data/lib/schema/dcmitype.xsd
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
elementFormDefault="qualified"
|
6
6
|
attributeFormDefault="unqualified">
|
7
7
|
|
8
|
+
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>
|
9
|
+
|
8
10
|
<xs:annotation>
|
9
11
|
<xs:documentation xml:lang="en">
|
10
12
|
DCMI Type Vocabulary XML Schema
|
@@ -12,7 +14,7 @@
|
|
12
14
|
|
13
15
|
Created 2003-04-02
|
14
16
|
|
15
|
-
Created by
|
17
|
+
Created by
|
16
18
|
|
17
19
|
Tim Cole (t-cole3@uiuc.edu)
|
18
20
|
Tom Habing (thabing@uiuc.edu)
|
@@ -24,7 +26,7 @@
|
|
24
26
|
the allowable values for the DCMI Type Vocabulary.
|
25
27
|
</xs:documentation>
|
26
28
|
|
27
|
-
|
29
|
+
|
28
30
|
</xs:annotation>
|
29
31
|
|
30
32
|
|
@@ -43,7 +45,7 @@
|
|
43
45
|
<xs:enumeration value="Text"/>
|
44
46
|
<xs:enumeration value="PhysicalObject"/>
|
45
47
|
</xs:restriction>
|
46
|
-
</xs:simpleType>
|
48
|
+
</xs:simpleType>
|
47
49
|
</xs:union>
|
48
50
|
</xs:simpleType>
|
49
51
|
|
data/lib/schema/dcterms.xsd
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
Created 2003-04-02
|
16
16
|
|
17
|
-
Created by
|
17
|
+
Created by
|
18
18
|
|
19
19
|
Tim Cole (t-cole3@uiuc.edu)
|
20
20
|
Tom Habing (thabing@uiuc.edu)
|
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
This schema declares XML elements for the DC elements and
|
26
26
|
DC element refinements from the http://purl.org/dc/terms/ namespace.
|
27
|
-
|
27
|
+
|
28
28
|
It reuses the complexType dc:SimpleLiteral, imported from the dc.xsd
|
29
29
|
schema, which permits simple element content, and makes the xml:lang
|
30
30
|
attribute available.
|
@@ -32,22 +32,22 @@
|
|
32
32
|
This complexType permits the derivation of other complexTypes
|
33
33
|
which would permit child elements.
|
34
34
|
|
35
|
-
DC elements are declared as substitutable for the abstract element dc:any, and
|
36
|
-
DC element refinements are defined as substitutable for the base elements
|
35
|
+
DC elements are declared as substitutable for the abstract element dc:any, and
|
36
|
+
DC element refinements are defined as substitutable for the base elements
|
37
37
|
which they refine.
|
38
38
|
|
39
|
-
This means that the default type for all XML elements (i.e. all DC elements and
|
39
|
+
This means that the default type for all XML elements (i.e. all DC elements and
|
40
40
|
element refinements) is dc:SimpleLiteral.
|
41
41
|
|
42
42
|
Encoding schemes are defined as complexTypes which are restrictions
|
43
|
-
of the dc:SimpleLiteral complexType. These complexTypes restrict
|
43
|
+
of the dc:SimpleLiteral complexType. These complexTypes restrict
|
44
44
|
values to an appropriates syntax or format using data typing,
|
45
45
|
regular expressions, or enumerated lists.
|
46
|
-
|
47
|
-
In order to specify one of these encodings an xsi:type attribute must
|
46
|
+
|
47
|
+
In order to specify one of these encodings an xsi:type attribute must
|
48
48
|
be used in the instance document.
|
49
49
|
|
50
|
-
Also, note that one shortcoming of this approach is that any type can be
|
50
|
+
Also, note that one shortcoming of this approach is that any type can be
|
51
51
|
applied to any of the elements or refinements. There is no convenient way
|
52
52
|
to restrict types to specific elements using this approach.
|
53
53
|
|
@@ -184,7 +184,7 @@
|
|
184
184
|
<xs:attribute ref="xml:lang" use="prohibited"/>
|
185
185
|
</xs:restriction>
|
186
186
|
</xs:simpleContent>
|
187
|
-
</xs:complexType>
|
187
|
+
</xs:complexType>
|
188
188
|
|
189
189
|
<xs:complexType name="DCMIType">
|
190
190
|
<xs:simpleContent>
|
@@ -217,7 +217,7 @@
|
|
217
217
|
<xs:attribute ref="xml:lang" use="prohibited"/>
|
218
218
|
</xs:restriction>
|
219
219
|
</xs:simpleContent>
|
220
|
-
</xs:complexType>
|
220
|
+
</xs:complexType>
|
221
221
|
|
222
222
|
<xs:complexType name="ISO639-2">
|
223
223
|
<xs:simpleContent>
|
@@ -300,9 +300,9 @@
|
|
300
300
|
<xs:annotation>
|
301
301
|
<xs:documentation xml:lang="en">
|
302
302
|
This group is included as a convenience for schema authors
|
303
|
-
who need to refer to all the DC elements and element refinements
|
304
|
-
in the http://purl.org/dc/elements/1.1/ and
|
305
|
-
http://purl.org/dc/terms namespaces.
|
303
|
+
who need to refer to all the DC elements and element refinements
|
304
|
+
in the http://purl.org/dc/elements/1.1/ and
|
305
|
+
http://purl.org/dc/terms namespaces.
|
306
306
|
N.B. Refinements available via substitution groups.
|
307
307
|
</xs:documentation>
|
308
308
|
</xs:annotation>
|
@@ -312,7 +312,7 @@
|
|
312
312
|
<xs:element ref="dc:any" />
|
313
313
|
</xs:choice>
|
314
314
|
</xs:sequence>
|
315
|
-
</xs:group>
|
315
|
+
</xs:group>
|
316
316
|
|
317
317
|
<xs:complexType name="elementOrRefinementContainer">
|
318
318
|
<xs:annotation>
|
@@ -2,13 +2,17 @@
|
|
2
2
|
<xs:schema targetNamespace="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
|
3
3
|
xmlns="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
|
4
4
|
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/"
|
5
|
-
xmlns:dcterms="http://purl.org/dc/terms/"
|
5
|
+
xmlns:dcterms="http://purl.org/dc/terms/"
|
6
|
+
elementFormDefault="qualified" blockDefault="#all">
|
6
7
|
|
7
8
|
<xs:import namespace="http://purl.org/dc/elements/1.1/"
|
8
9
|
schemaLocation="dc.xsd"/>
|
10
|
+
|
9
11
|
<xs:import namespace="http://purl.org/dc/terms/"
|
10
12
|
schemaLocation="dcterms.xsd"/>
|
11
|
-
|
13
|
+
|
14
|
+
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
|
15
|
+
schemaLocation="xml.xsd"/>
|
12
16
|
|
13
17
|
<xs:element name="coreProperties" type="CT_CoreProperties"/>
|
14
18
|
|
data/lib/schema/xml.xsd
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
<?xml version='1.0'?>
|
2
|
-
|
3
|
-
<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="en">
|
2
|
+
<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
4
3
|
|
5
4
|
<xs:annotation>
|
6
5
|
<xs:documentation>
|
@@ -8,7 +7,7 @@
|
|
8
7
|
http://www.w3.org/TR/REC-xml for information about this namespace.
|
9
8
|
|
10
9
|
This schema document describes the XML namespace, in a form
|
11
|
-
suitable for import by other schema documents.
|
10
|
+
suitable for import by other schema documents.
|
12
11
|
|
13
12
|
Note that local names in this namespace are intended to be defined
|
14
13
|
only by the World Wide Web Consortium or its subgroups. The
|
@@ -26,16 +25,16 @@
|
|
26
25
|
is a language code for the natural language of the content of
|
27
26
|
any element; its value is inherited. This name is reserved
|
28
27
|
by virtue of its definition in the XML specification.
|
29
|
-
|
28
|
+
|
30
29
|
space (as an attribute name): denotes an attribute whose
|
31
30
|
value is a keyword indicating what whitespace processing
|
32
31
|
discipline is intended for the content of the element; its
|
33
32
|
value is inherited. This name is reserved by virtue of its
|
34
33
|
definition in the XML specification.
|
35
34
|
|
36
|
-
Father (in any context at all): denotes Jon Bosak, the chair of
|
37
|
-
the original XML Working Group. This name is reserved by
|
38
|
-
the following decision of the W3C XML Plenary and
|
35
|
+
Father (in any context at all): denotes Jon Bosak, the chair of
|
36
|
+
the original XML Working Group. This name is reserved by
|
37
|
+
the following decision of the W3C XML Plenary and
|
39
38
|
XML Coordination groups:
|
40
39
|
|
41
40
|
In appreciation for his vision, leadership and dedication
|
@@ -64,7 +63,7 @@
|
|
64
63
|
<type . . .>
|
65
64
|
. . .
|
66
65
|
<attributeGroup ref="xml:specialAttrs"/>
|
67
|
-
|
66
|
+
|
68
67
|
will define a type which will schema-validate an instance
|
69
68
|
element with any of those attributes</xs:documentation>
|
70
69
|
</xs:annotation>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
|
2
|
+
user system total real
|
3
|
+
axlsx_noautowidth 1.160000 0.030000 1.190000 ( 1.202237)
|
4
|
+
axlsx 1.710000 0.150000 1.860000 ( 2.298028)
|
5
|
+
axlsx_shared 2.650000 0.150000 2.800000 ( 2.864474)
|
6
|
+
axlsx_stream 1.650000 0.140000 1.790000 ( 1.848033)
|
7
|
+
csv 0.270000 0.020000 0.290000 ( 0.291206)
|
data/test/#tc_helper.rb#
ADDED
data/test/benchmark.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env ruby -s
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
$:.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
|
+
require 'axlsx'
|
5
|
+
require 'csv'
|
6
|
+
|
7
|
+
require 'benchmark'
|
8
|
+
row = []
|
9
|
+
input = (32..126).to_a.pack('U*').chars.to_a
|
10
|
+
20.times { row << input.shuffle.join}
|
11
|
+
times = 1000
|
12
|
+
Benchmark.bm(100) do |x|
|
13
|
+
# No Autowidth
|
14
|
+
x.report('axlsx_noautowidth') {
|
15
|
+
|
16
|
+
p = Axlsx::Package.new
|
17
|
+
p.use_autowidth = false
|
18
|
+
wb = p.workbook
|
19
|
+
|
20
|
+
#A Simple Workbook
|
21
|
+
|
22
|
+
wb.add_worksheet do |sheet|
|
23
|
+
times.times do
|
24
|
+
sheet << row
|
25
|
+
end
|
26
|
+
end
|
27
|
+
p.serialize("example.xlsx")
|
28
|
+
}
|
29
|
+
|
30
|
+
x.report('axlsx') {
|
31
|
+
p = Axlsx::Package.new
|
32
|
+
wb = p.workbook
|
33
|
+
|
34
|
+
#A Simple Workbook
|
35
|
+
|
36
|
+
wb.add_worksheet do |sheet|
|
37
|
+
times.times do
|
38
|
+
sheet << row
|
39
|
+
end
|
40
|
+
end
|
41
|
+
p.serialize("example.xlsx")
|
42
|
+
}
|
43
|
+
|
44
|
+
x.report('axlsx_shared') {
|
45
|
+
p = Axlsx::Package.new
|
46
|
+
wb = p.workbook
|
47
|
+
|
48
|
+
#A Simple Workbook
|
49
|
+
|
50
|
+
wb.add_worksheet do |sheet|
|
51
|
+
times.times do
|
52
|
+
sheet << row
|
53
|
+
end
|
54
|
+
end
|
55
|
+
p.use_shared_strings = true
|
56
|
+
p.serialize("example.xlsx")
|
57
|
+
}
|
58
|
+
|
59
|
+
x.report('axlsx_stream') {
|
60
|
+
p = Axlsx::Package.new
|
61
|
+
wb = p.workbook
|
62
|
+
|
63
|
+
#A Simple Workbook
|
64
|
+
|
65
|
+
wb.add_worksheet do |sheet|
|
66
|
+
times.times do
|
67
|
+
sheet << row
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
s = p.to_stream()
|
72
|
+
File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
|
73
|
+
}
|
74
|
+
x.report('csv') {
|
75
|
+
CSV.open("example.csv", "wb") do |csv|
|
76
|
+
times.times do
|
77
|
+
csv << row
|
78
|
+
end
|
79
|
+
end
|
80
|
+
}
|
81
|
+
end
|
data/test/benchmark.rb~
ADDED
File without changes
|
data/test/benchmark.txt
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
user system total real
|
2
|
+
axlsx_noautowidth 1.160000 0.030000 1.190000 ( 1.202237)
|
3
|
+
axlsx 1.710000 0.150000 1.860000 ( 2.298028)
|
4
|
+
axlsx_shared 2.650000 0.150000 2.800000 ( 2.864474)
|
5
|
+
axlsx_stream 1.650000 0.140000 1.790000 ( 1.848033)
|
6
|
+
csv 0.270000 0.020000 0.290000 ( 0.291206)
|
data/test/benchmark.txt~
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
user system total real
|
2
|
+
axlsx_noautowidth 1.160000 0.030000 1.190000 ( 1.202237)
|
3
|
+
axlsx 1.710000 0.150000 1.860000 ( 2.298028)
|
4
|
+
axlsx_shared 2.650000 0.150000 2.800000 ( 2.864474)
|
5
|
+
axlsx_stream 1.650000 0.140000 1.790000 ( 1.848033)
|
6
|
+
csv 0.270000 0.020000 0.290000 ( 0.291206)
|
@@ -1,12 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'axlsx.rb'
|
2
|
+
require 'tc_helper.rb'
|
5
3
|
|
6
4
|
class TestContentType < Test::Unit::TestCase
|
7
|
-
def setup
|
5
|
+
def setup
|
8
6
|
@package = Axlsx::Package.new
|
9
|
-
@doc = Nokogiri::XML(@package.send(:content_types).
|
7
|
+
@doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
|
10
8
|
end
|
11
9
|
|
12
10
|
def test_valid_document
|
@@ -21,63 +19,63 @@ class TestContentType < Test::Unit::TestCase
|
|
21
19
|
|
22
20
|
def test_pre_built_types
|
23
21
|
|
24
|
-
o_path = "
|
25
|
-
d_path = "
|
22
|
+
o_path = "//xmlns:Override[@ContentType='%s']"
|
23
|
+
d_path = "//xmlns:Default[@ContentType='%s']"
|
24
|
+
|
25
|
+
#default
|
26
|
+
assert_equal(@doc.xpath("//xmlns:Default").size, 2, "There should be 2 default types")
|
26
27
|
|
27
|
-
|
28
|
-
assert_equal(@doc.css("Types Default").size, 2, "There should be 2 default types")
|
29
|
-
|
30
|
-
node = @doc.css(d_path % Axlsx::XML_CT).first
|
28
|
+
node = @doc.xpath(d_path % Axlsx::XML_CT).first
|
31
29
|
assert_equal(node["Extension"], "#{Axlsx::XML_EX}", "xml content type invalid")
|
32
30
|
|
33
|
-
node = @doc.
|
31
|
+
node = @doc.xpath(d_path % Axlsx::RELS_CT).first
|
34
32
|
assert_equal(node["Extension"],"#{Axlsx::RELS_EX}", "relationships content type invalid")
|
35
33
|
|
36
34
|
#overrride
|
37
|
-
assert_equal(@doc.
|
35
|
+
assert_equal(@doc.xpath("//xmlns:Override").size, 4, "There should be 4 Override types")
|
38
36
|
|
39
|
-
node = @doc.
|
37
|
+
node = @doc.xpath(o_path % Axlsx::APP_CT).first
|
40
38
|
assert_equal(node["PartName"], "/#{Axlsx::APP_PN}", "App part name invalid")
|
41
39
|
|
42
|
-
node = @doc.
|
40
|
+
node = @doc.xpath(o_path % Axlsx::CORE_CT).first
|
43
41
|
assert_equal(node["PartName"], "/#{Axlsx::CORE_PN}", "Core part name invalid")
|
44
42
|
|
45
|
-
node = @doc.
|
43
|
+
node = @doc.xpath(o_path % Axlsx::STYLES_CT).first
|
46
44
|
assert_equal(node["PartName"], "/xl/#{Axlsx::STYLES_PN}", "Styles part name invalid")
|
47
45
|
|
48
|
-
node = @doc.
|
46
|
+
node = @doc.xpath(o_path % Axlsx::WORKBOOK_CT).first
|
49
47
|
assert_equal(node["PartName"], "/#{Axlsx::WORKBOOK_PN}", "Workbook part invalid")
|
50
48
|
end
|
51
49
|
|
52
50
|
def test_should_get_worksheet_for_worksheets
|
53
|
-
o_path = "
|
51
|
+
o_path = "//xmlns:Override[@ContentType='%s']"
|
54
52
|
|
55
53
|
ws = @package.workbook.add_worksheet
|
56
|
-
doc = Nokogiri::XML(@package.send(:content_types).
|
57
|
-
assert_equal(doc.
|
58
|
-
assert_equal(doc.
|
54
|
+
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
|
55
|
+
assert_equal(doc.xpath("//xmlns:Override").size, 5, "adding a worksheet should add another type")
|
56
|
+
assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
|
59
57
|
|
60
58
|
ws = @package.workbook.add_worksheet
|
61
|
-
doc = Nokogiri::XML(@package.send(:content_types).
|
62
|
-
assert_equal(doc.
|
63
|
-
assert_equal(doc.
|
59
|
+
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
|
60
|
+
assert_equal(doc.xpath("//xmlns:Override").size, 6, "adding workship should add another type")
|
61
|
+
assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
|
64
62
|
|
65
63
|
end
|
66
64
|
|
67
65
|
def test_drawings_and_charts_need_content_types
|
68
|
-
o_path = "
|
66
|
+
o_path = "//xmlns:Override[@ContentType='%s']"
|
69
67
|
ws = @package.workbook.add_worksheet
|
70
68
|
|
71
69
|
c = ws.add_chart Axlsx::Pie3DChart
|
72
|
-
doc = Nokogiri::XML(@package.send(:content_types).
|
73
|
-
assert_equal(doc.
|
74
|
-
assert_equal(doc.
|
75
|
-
assert_equal(doc.
|
70
|
+
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
|
71
|
+
assert_equal(doc.xpath("//xmlns:Override").size, 7, "expected 7 types got #{doc.css("Types Override").size}")
|
72
|
+
assert_equal(doc.xpath(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid")
|
73
|
+
assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
|
76
74
|
|
77
75
|
c = ws.add_chart Axlsx::Pie3DChart
|
78
|
-
doc = Nokogiri::XML(@package.send(:content_types).
|
79
|
-
assert_equal(doc.
|
80
|
-
assert_equal(doc.
|
76
|
+
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
|
77
|
+
assert_equal(doc.xpath("//xmlns:Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}")
|
78
|
+
assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
|
81
79
|
end
|
82
80
|
|
83
81
|
end
|