axlsx 1.0.17 → 1.1.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.
Files changed (167) hide show
  1. data/CHANGELOG.md +11 -3
  2. data/README.md +159 -51
  3. data/examples/example.csv +1000 -0
  4. data/examples/example.rb +255 -150
  5. data/examples/example.xlsx +0 -0
  6. data/examples/example_streamed.xlsx +0 -0
  7. data/examples/no-use_autowidth.xlsx +0 -0
  8. data/examples/shared_strings_example.xlsx +0 -0
  9. data/lib/axlsx/content_type/content_type.rb +12 -12
  10. data/lib/axlsx/content_type/default.rb +9 -6
  11. data/lib/axlsx/content_type/override.rb +12 -8
  12. data/lib/axlsx/doc_props/app.rb +37 -40
  13. data/lib/axlsx/doc_props/core.rb +12 -17
  14. data/lib/axlsx/drawing/axis.rb +38 -19
  15. data/lib/axlsx/drawing/bar_3D_chart.rb +33 -32
  16. data/lib/axlsx/drawing/bar_series.rb +13 -14
  17. data/lib/axlsx/drawing/cat_axis.rb +15 -14
  18. data/lib/axlsx/drawing/cat_axis_data.rb +16 -18
  19. data/lib/axlsx/drawing/chart.rb +39 -40
  20. data/lib/axlsx/drawing/drawing.rb +15 -12
  21. data/lib/axlsx/drawing/graphic_frame.rb +21 -21
  22. data/lib/axlsx/drawing/hyperlink.rb +12 -11
  23. data/lib/axlsx/drawing/line_3D_chart.rb +30 -28
  24. data/lib/axlsx/drawing/line_series.rb +11 -11
  25. data/lib/axlsx/drawing/marker.rb +10 -8
  26. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  27. data/lib/axlsx/drawing/one_cell_anchor.rb +17 -16
  28. data/lib/axlsx/drawing/pic.rb +25 -37
  29. data/lib/axlsx/drawing/picture_locking.rb +21 -18
  30. data/lib/axlsx/drawing/pie_3D_chart.rb +10 -8
  31. data/lib/axlsx/drawing/pie_series.rb +15 -12
  32. data/lib/axlsx/drawing/scaling.rb +10 -10
  33. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  34. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  35. data/lib/axlsx/drawing/ser_axis.rb +10 -10
  36. data/lib/axlsx/drawing/series.rb +15 -15
  37. data/lib/axlsx/drawing/series_title.rb +14 -14
  38. data/lib/axlsx/drawing/title.rb +26 -26
  39. data/lib/axlsx/drawing/two_cell_anchor.rb +18 -20
  40. data/lib/axlsx/drawing/val_axis.rb +8 -7
  41. data/lib/axlsx/drawing/val_axis_data.rb +17 -17
  42. data/lib/axlsx/drawing/view_3D.rb +22 -20
  43. data/lib/axlsx/package.rb +60 -43
  44. data/lib/axlsx/rels/relationship.rb +11 -8
  45. data/lib/axlsx/rels/relationships.rb +7 -1
  46. data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
  47. data/lib/axlsx/stylesheet/border.rb +27 -23
  48. data/lib/axlsx/stylesheet/border_pr.rb +16 -15
  49. data/lib/axlsx/stylesheet/cell_alignment.rb +23 -21
  50. data/lib/axlsx/stylesheet/cell_protection.rb +10 -7
  51. data/lib/axlsx/stylesheet/cell_style.rb +8 -5
  52. data/lib/axlsx/stylesheet/color.rb +20 -14
  53. data/lib/axlsx/stylesheet/fill.rb +7 -5
  54. data/lib/axlsx/stylesheet/font.rb +21 -14
  55. data/lib/axlsx/stylesheet/gradient_fill.rb +19 -16
  56. data/lib/axlsx/stylesheet/gradient_stop.rb +9 -5
  57. data/lib/axlsx/stylesheet/num_fmt.rb +12 -6
  58. data/lib/axlsx/stylesheet/pattern_fill.rb +25 -10
  59. data/lib/axlsx/stylesheet/styles.rb +47 -35
  60. data/lib/axlsx/stylesheet/table_style.rb +9 -4
  61. data/lib/axlsx/stylesheet/table_style_element.rb +10 -7
  62. data/lib/axlsx/stylesheet/table_styles.rb +11 -8
  63. data/lib/axlsx/stylesheet/xf.rb +29 -25
  64. data/lib/axlsx/util/constants.rb +20 -14
  65. data/lib/axlsx/util/simple_typed_list.rb +18 -9
  66. data/lib/axlsx/util/validators.rb +13 -6
  67. data/lib/axlsx/version.rb +1 -1
  68. data/lib/axlsx/workbook/shared_strings_table.rb +19 -21
  69. data/lib/axlsx/workbook/workbook.rb +58 -34
  70. data/lib/axlsx/workbook/worksheet/cell.rb +149 -132
  71. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  72. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  73. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  74. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  75. data/lib/axlsx/workbook/worksheet/row.rb +40 -23
  76. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  77. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  78. data/lib/axlsx/workbook/worksheet/worksheet.rb +243 -127
  79. data/lib/axlsx.rb +30 -9
  80. data/lib/schema/dc.xsd +5 -5
  81. data/lib/schema/dcmitype.xsd +5 -3
  82. data/lib/schema/dcterms.xsd +15 -15
  83. data/lib/schema/opc-coreProperties.xsd +6 -2
  84. data/lib/schema/xml.xsd +7 -8
  85. data/test/#benchmark.txt# +7 -0
  86. data/test/#tc_helper.rb# +3 -0
  87. data/test/benchmark.rb +81 -0
  88. data/test/benchmark.rb~ +0 -0
  89. data/test/benchmark.txt +6 -0
  90. data/test/benchmark.txt~ +6 -0
  91. data/test/content_type/tc_content_type.rb +30 -32
  92. data/test/content_type/tc_default.rb +8 -23
  93. data/test/content_type/tc_override.rb +7 -21
  94. data/test/doc_props/tc_app.rb +2 -8
  95. data/test/doc_props/tc_core.rb +6 -7
  96. data/test/drawing/tc_axis.rb +7 -3
  97. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  98. data/test/drawing/tc_bar_series.rb +4 -5
  99. data/test/drawing/tc_cat_axis.rb +2 -3
  100. data/test/drawing/tc_cat_axis_data.rb +2 -3
  101. data/test/drawing/tc_chart.rb +13 -14
  102. data/test/drawing/tc_drawing.rb +7 -8
  103. data/test/drawing/tc_graphic_frame.rb +3 -4
  104. data/test/drawing/tc_hyperlink.rb +2 -3
  105. data/test/drawing/tc_line_3d_chart.rb +5 -6
  106. data/test/drawing/tc_line_series.rb +3 -4
  107. data/test/drawing/tc_marker.rb +3 -4
  108. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  109. data/test/drawing/tc_pic.rb +8 -9
  110. data/test/drawing/tc_picture_locking.rb +2 -3
  111. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  112. data/test/drawing/tc_pie_series.rb +4 -5
  113. data/test/drawing/tc_scaling.rb +3 -4
  114. data/test/drawing/tc_scatter_chart.rb +43 -0
  115. data/test/drawing/tc_scatter_series.rb +20 -0
  116. data/test/drawing/tc_ser_axis.rb +2 -3
  117. data/test/drawing/tc_series.rb +4 -5
  118. data/test/drawing/tc_series_title.rb +4 -5
  119. data/test/drawing/tc_title.rb +4 -5
  120. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  121. data/test/drawing/tc_val_axis.rb +2 -3
  122. data/test/drawing/tc_val_axis_data.rb +2 -3
  123. data/test/drawing/tc_view_3D.rb +6 -7
  124. data/test/example.csv +1000 -0
  125. data/test/example.xlsx +0 -0
  126. data/test/example_streamed.xlsx +0 -0
  127. data/test/profile.rb +33 -0
  128. data/test/rels/tc_relationship.rb +5 -6
  129. data/test/rels/tc_relationships.rb +4 -5
  130. data/test/stylesheet/tc_border.rb +3 -4
  131. data/test/stylesheet/tc_border_pr.rb +3 -4
  132. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  133. data/test/stylesheet/tc_cell_protection.rb +2 -3
  134. data/test/stylesheet/tc_cell_style.rb +2 -3
  135. data/test/stylesheet/tc_color.rb +2 -3
  136. data/test/stylesheet/tc_fill.rb +1 -2
  137. data/test/stylesheet/tc_font.rb +12 -5
  138. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  139. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  140. data/test/stylesheet/tc_num_fmt.rb +1 -2
  141. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  142. data/test/stylesheet/tc_styles.rb +16 -6
  143. data/test/stylesheet/tc_table_style.rb +2 -3
  144. data/test/stylesheet/tc_table_style_element.rb +2 -3
  145. data/test/stylesheet/tc_table_styles.rb +3 -4
  146. data/test/stylesheet/tc_xf.rb +16 -17
  147. data/test/tc_axlsx.rb +39 -0
  148. data/test/tc_axlsx.rb~ +0 -0
  149. data/test/tc_helper.rb +3 -0
  150. data/test/tc_helper.rb~ +3 -0
  151. data/test/tc_package.rb +13 -10
  152. data/test/util/tc_simple_typed_list.rb +8 -9
  153. data/test/util/tc_validators.rb +7 -8
  154. data/test/workbook/tc_shared_strings_table.rb +5 -6
  155. data/test/workbook/tc_workbook.rb +24 -6
  156. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  157. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  158. data/test/workbook/worksheet/tc_cell.rb +62 -18
  159. data/test/workbook/worksheet/tc_col.rb +59 -0
  160. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  161. data/test/workbook/worksheet/tc_date_time_converter.rb +126 -0
  162. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  163. data/test/workbook/worksheet/tc_row.rb +54 -4
  164. data/test/workbook/worksheet/tc_worksheet.rb +177 -34
  165. metadata +69 -41
  166. data/test/drawing/tc_hyperlink.rb~ +0 -71
  167. data/test/workbook/tc_shared_strings_table.rb~ +0 -8
@@ -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
 
@@ -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/" elementFormDefault="qualified" blockDefault="#all">
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
- <xs:import id="xml" namespace="http://www.w3.org/XML/1998/namespace"/>
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
- <!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "XMLSchema.dtd" >
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
  &lt;type . . .>
65
64
  . . .
66
65
  &lt;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)
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
+ require 'test/unit'
3
+ require "axlsx.rb"
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
File without changes
@@ -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)
@@ -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).to_xml)
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 = "Types Override [@ContentType='%s']"
25
- d_path = "Types Default [@ContentType='%s']"
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
- #default
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.css(d_path % Axlsx::RELS_CT).first
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.css("Types Override").size, 4, "There should be 4 Override types")
35
+ assert_equal(@doc.xpath("//xmlns:Override").size, 4, "There should be 4 Override types")
38
36
 
39
- node = @doc.css(o_path % Axlsx::APP_CT).first
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.css(o_path % Axlsx::CORE_CT).first
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.css(o_path % Axlsx::STYLES_CT).first
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.css(o_path % Axlsx::WORKBOOK_CT).first
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 = "Types Override [@ContentType='%s']"
51
+ o_path = "//xmlns:Override[@ContentType='%s']"
54
52
 
55
53
  ws = @package.workbook.add_worksheet
56
- doc = Nokogiri::XML(@package.send(:content_types).to_xml)
57
- assert_equal(doc.css("Types Override").size, 5, "adding a worksheet should add another type")
58
- assert_equal(doc.css(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
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).to_xml)
62
- assert_equal(doc.css("Types Override").size, 6, "adding workship should add another type")
63
- assert_equal(doc.css(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
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 = "Types Override [@ContentType='%s']"
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).to_xml)
73
- assert_equal(doc.css("Types Override").size, 7, "expected 7 types got #{doc.css("Types Override").size}")
74
- assert_equal(doc.css(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid")
75
- assert_equal(doc.css(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
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).to_xml)
79
- assert_equal(doc.css("Types Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}")
80
- assert_equal(doc.css(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
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
@@ -1,13 +1,8 @@
1
1
  # encoding: UTF-8
2
-
3
- require 'test/unit'
4
- require 'axlsx.rb'
2
+ require 'tc_helper.rb'
5
3
 
6
4
  class TestDefault < Test::Unit::TestCase
7
- def setup
8
- end
9
- def teardown
10
- end
5
+
11
6
  def test_initialization_requires_Extension_and_ContentType
12
7
  assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new }
13
8
  assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new :Extension=>"xml" }
@@ -19,23 +14,13 @@ class TestDefault < Test::Unit::TestCase
19
14
  def test_content_type_restriction
20
15
  assert_raise(ArgumentError, "raises argument error if invlalid ContentType is") { Axlsx::Default.new :ContentType=>"asdf" }
21
16
  end
22
-
23
- def test_to_xml
24
- schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
17
+
18
+ def test_to_xml_string
25
19
  type = Axlsx::Default.new :Extension=>"xml", :ContentType=>Axlsx::XML_CT
26
- builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
27
- xml.Types(:xmlns => Axlsx::XML_NS_T) {
28
- type.to_xml(xml)
29
- }
30
- end
31
- doc = Nokogiri::XML(builder.to_xml)
32
- errors = []
33
- schema.validate(doc).each do |error|
34
- puts error.message
35
- errors << error
36
- end
37
- assert_equal(errors.size, 0, "[Content Types].xml Invalid" + errors.map{ |e| e.message }.to_s)
38
-
20
+ doc = Nokogiri::XML(type.to_xml_string)
21
+ assert_equal(doc.xpath("Default[@ContentType='#{Axlsx::XML_CT}']").size, 1)
22
+ assert_equal(doc.xpath("Default[@Extension='xml']").size, 1)
23
+
39
24
  end
40
25
 
41
26
 
@@ -1,12 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'test/unit'
3
- require 'axlsx.rb'
2
+ require 'tc_helper.rb'
4
3
 
5
4
  class TestOverride < Test::Unit::TestCase
6
- def setup
7
- end
8
- def teardown
9
- end
5
+
10
6
  def test_initialization_requires_Extension_and_ContentType
11
7
  err = "requires PartName and ContentType options"
12
8
  assert_raise(ArgumentError, err) { Axlsx::Override.new }
@@ -18,23 +14,13 @@ class TestOverride < Test::Unit::TestCase
18
14
  def test_content_type_restriction
19
15
  assert_raise(ArgumentError, "requires known content type") { Axlsx::Override.new :ContentType=>"asdf" }
20
16
  end
21
-
17
+
22
18
  def test_to_xml
23
- schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
24
19
  type = Axlsx::Override.new :PartName=>"somechart.xml", :ContentType=>Axlsx::CHART_CT
25
- builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
26
- xml.Types(:xmlns => Axlsx::XML_NS_T) {
27
- type.to_xml(xml)
28
- }
29
- end
30
- doc = Nokogiri::XML(builder.to_xml)
31
- errors = []
32
- schema.validate(doc).each do |error|
33
- puts error.message
34
- errors << error
35
- end
36
- assert_equal(errors.size, 0, "Override content type caused invalid content_type doc" + errors.map{ |e| e.message }.to_s)
37
-
20
+ doc = Nokogiri::XML(type.to_xml_string)
21
+ assert_equal(doc.xpath("Override[@ContentType='#{Axlsx::CHART_CT}']").size, 1)
22
+ assert_equal(doc.xpath("Override[@PartName='somechart.xml']").size, 1)
23
+
38
24
  end
39
25
 
40
26
 
@@ -1,15 +1,9 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestApp < Test::Unit::TestCase
5
- def setup
6
- end
7
- def teardown
8
- end
9
-
10
4
  def test_valid_document
11
5
  schema = Nokogiri::XML::Schema(File.open(Axlsx::APP_XSD))
12
- doc = Nokogiri::XML(Axlsx::App.new.to_xml)
6
+ doc = Nokogiri::XML(Axlsx::App.new.to_xml_string)
13
7
  errors = []
14
8
  schema.validate(doc).each do |error|
15
9
  errors << error
@@ -1,11 +1,10 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestCore < Test::Unit::TestCase
5
-
6
- def setup
4
+
5
+ def setup
7
6
  @core = Axlsx::Core.new
8
- @doc = Nokogiri::XML(@core.to_xml)
7
+ @doc = Nokogiri::XML(@core.to_xml_string)
9
8
  end
10
9
 
11
10
  def test_valid_document
@@ -21,14 +20,14 @@ class TestCore < Test::Unit::TestCase
21
20
  def test_populates_created
22
21
  assert_equal(@doc.xpath('//dcterms:created').text, Time.now.strftime('%Y-%m-%dT%H:%M:%S'), "dcterms:created incorrect")
23
22
  end
24
-
23
+
25
24
  def test_populates_default_name
26
25
  assert_equal(@doc.xpath('//dc:creator').text, "axlsx", "Default name not populated")
27
26
  end
28
27
 
29
28
  def test_creator_as_option
30
29
  c = Axlsx::Core.new :creator => "some guy"
31
- doc = Nokogiri::XML(c.to_xml)
30
+ doc = Nokogiri::XML(c.to_xml_string)
32
31
  assert(doc.xpath('//dc:creator').text == "some guy")
33
32
  end
34
33
  end
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestAxis < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @axis = Axlsx::Axis.new 12345, 54321
7
6
  end
8
7
  def teardown
@@ -37,4 +36,9 @@ class TestAxis < Test::Unit::TestCase
37
36
  assert_nothing_raised("accepts valid crosses") { @axis.crosses = :min }
38
37
  end
39
38
 
39
+ def test_gridlines
40
+ assert_raise(ArgumentError, "requires valid gridlines") { @axis.gridlines = 'alice' }
41
+ assert_nothing_raised("accepts valid crosses") { @axis.gridlines = false }
42
+ end
43
+
40
44
  end
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestBar3DChart < Test::Unit::TestCase
5
4
 
@@ -13,7 +12,7 @@ class TestBar3DChart < Test::Unit::TestCase
13
12
  def teardown
14
13
  end
15
14
 
16
- def test_initialization
15
+ def test_initialization
17
16
  assert_equal(@chart.grouping, :clustered, "grouping defualt incorrect")
18
17
  assert_equal(@chart.series_type, Axlsx::BarSeries, "series type incorrect")
19
18
  assert_equal(@chart.barDir, :bar, " bar direction incorrect")
@@ -52,15 +51,15 @@ class TestBar3DChart < Test::Unit::TestCase
52
51
  assert(@chart.shape == :cone)
53
52
  end
54
53
 
55
- def test_to_xml
54
+ def test_to_xml_string
56
55
  schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
57
- doc = Nokogiri::XML(@chart.to_xml)
56
+ doc = Nokogiri::XML(@chart.to_xml_string)
58
57
  errors = []
59
58
  schema.validate(doc).each do |error|
60
59
  errors.push error
61
60
  puts error.message
62
61
  end
63
62
  assert(errors.empty?, "error free validation")
64
- end
65
-
63
+ end
64
+
66
65
  end
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestBarSeries < Test::Unit::TestCase
5
4
 
@@ -9,12 +8,12 @@ class TestBarSeries < Test::Unit::TestCase
9
8
  chart = @ws.drawing.add_chart Axlsx::Bar3DChart, :title => "fishery"
10
9
  @series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob"
11
10
  end
12
-
11
+
13
12
  def test_initialize
14
13
  assert_equal(@series.title.text, "bob", "series title has been applied")
15
14
  assert_equal(@series.data, [0,1,2], "data option applied")
16
- assert_equal(@series.labels, ["zero", "one","two"], "labels option applied")
17
- assert_equal(@series.shape, :box, "series shape has been applied")
15
+ assert_equal(@series.labels, ["zero", "one","two"], "labels option applied")
16
+ assert_equal(@series.shape, :box, "series shape has been applied")
18
17
  end
19
18
 
20
19
  def test_data
@@ -1,8 +1,7 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestCatAxis < Test::Unit::TestCase
5
- def setup
4
+ def setup
6
5
  @axis = Axlsx::CatAxis.new 12345, 54321
7
6
  end
8
7
  def teardown
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'axlsx.rb'
1
+ require 'tc_helper.rb'
3
2
 
4
3
  class TestCatAxisData < Test::Unit::TestCase
5
4
 
@@ -9,7 +8,7 @@ class TestCatAxisData < Test::Unit::TestCase
9
8
  chart = @ws.drawing.add_chart Axlsx::Bar3DChart
10
9
  @series = chart.add_series :labels=>["zero", "one", "two"]
11
10
  end
12
-
11
+
13
12
  def test_initialize
14
13
  assert(@series.labels.is_a?Axlsx::SimpleTypedList)
15
14
  assert_equal(@series.labels, ["zero", "one", "two"])