axlsx 1.1.0 → 1.2.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 (214) hide show
  1. data/.yardopts +5 -2
  2. data/CHANGELOG.md +78 -0
  3. data/LICENSE +1 -1
  4. data/README.md +132 -331
  5. data/Rakefile +17 -5
  6. data/examples/basic_charts.rb +54 -0
  7. data/examples/chart_colors.rb +88 -0
  8. data/examples/conditional_formatting/example_conditional_formatting.rb +72 -0
  9. data/examples/conditional_formatting/getting_barred.rb +37 -0
  10. data/examples/conditional_formatting/hitting_the_high_notes.rb +37 -0
  11. data/examples/conditional_formatting/scaled_colors.rb +39 -0
  12. data/examples/conditional_formatting/stop_and_go.rb +37 -0
  13. data/examples/data_validation.rb +50 -0
  14. data/examples/example.rb +300 -152
  15. data/examples/example.xlsx +0 -0
  16. data/examples/example_streamed.xlsx +0 -0
  17. data/examples/extractive.pdf +0 -0
  18. data/examples/extractive.rb +45 -0
  19. data/examples/no-use_autowidth.xlsx +0 -0
  20. data/examples/sample.png +0 -0
  21. data/examples/scraping_html.rb +91 -0
  22. data/examples/shared_strings_example.xlsx +0 -0
  23. data/examples/sheet_protection.rb +10 -0
  24. data/examples/sheet_view.rb +34 -0
  25. data/examples/skydrive/real_example.rb +63 -0
  26. data/examples/two_cell_anchor_image.rb +11 -0
  27. data/lib/axlsx/content_type/content_type.rb +2 -0
  28. data/lib/axlsx/content_type/default.rb +30 -15
  29. data/lib/axlsx/content_type/override.rb +29 -14
  30. data/lib/axlsx/doc_props/app.rb +161 -104
  31. data/lib/axlsx/doc_props/core.rb +9 -5
  32. data/lib/axlsx/drawing/ax_data_source.rb +26 -0
  33. data/lib/axlsx/drawing/axis.rb +106 -35
  34. data/lib/axlsx/drawing/bar_3D_chart.rb +49 -45
  35. data/lib/axlsx/drawing/bar_series.rb +25 -7
  36. data/lib/axlsx/drawing/cat_axis.rb +50 -22
  37. data/lib/axlsx/drawing/chart.rb +69 -56
  38. data/lib/axlsx/drawing/d_lbls.rb +100 -0
  39. data/lib/axlsx/drawing/drawing.rb +28 -12
  40. data/lib/axlsx/drawing/graphic_frame.rb +2 -1
  41. data/lib/axlsx/drawing/line_3D_chart.rb +3 -10
  42. data/lib/axlsx/drawing/line_series.rb +20 -4
  43. data/lib/axlsx/drawing/num_data.rb +52 -0
  44. data/lib/axlsx/drawing/num_data_source.rb +61 -0
  45. data/lib/axlsx/drawing/num_val.rb +32 -0
  46. data/lib/axlsx/drawing/pic.rb +44 -4
  47. data/lib/axlsx/drawing/pie_3D_chart.rb +10 -7
  48. data/lib/axlsx/drawing/pie_series.rb +18 -4
  49. data/lib/axlsx/drawing/scatter_chart.rb +12 -18
  50. data/lib/axlsx/drawing/scatter_series.rb +28 -2
  51. data/lib/axlsx/drawing/ser_axis.rb +1 -1
  52. data/lib/axlsx/drawing/series.rb +1 -1
  53. data/lib/axlsx/drawing/str_data.rb +42 -0
  54. data/lib/axlsx/drawing/str_val.rb +33 -0
  55. data/lib/axlsx/drawing/title.rb +21 -9
  56. data/lib/axlsx/drawing/two_cell_anchor.rb +46 -9
  57. data/lib/axlsx/drawing/view_3D.rb +44 -31
  58. data/lib/axlsx/drawing/vml_drawing.rb +42 -0
  59. data/lib/axlsx/drawing/vml_shape.rb +125 -0
  60. data/lib/axlsx/package.rb +44 -16
  61. data/lib/axlsx/rels/relationship.rb +3 -3
  62. data/lib/axlsx/rels/relationships.rb +1 -11
  63. data/lib/axlsx/stylesheet/color.rb +0 -1
  64. data/lib/axlsx/stylesheet/dxf.rb +79 -0
  65. data/lib/axlsx/stylesheet/font.rb +2 -1
  66. data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
  67. data/lib/axlsx/stylesheet/styles.rb +143 -50
  68. data/lib/axlsx/stylesheet/table_style.rb +3 -3
  69. data/lib/axlsx/stylesheet/xf.rb +2 -0
  70. data/lib/axlsx/util/constants.rb +36 -0
  71. data/lib/axlsx/util/simple_typed_list.rb +15 -21
  72. data/lib/axlsx/util/validators.rb +122 -5
  73. data/lib/axlsx/version.rb +2 -7
  74. data/lib/axlsx/workbook/defined_name.rb +174 -0
  75. data/lib/axlsx/workbook/defined_names.rb +21 -0
  76. data/lib/axlsx/workbook/shared_strings_table.rb +12 -13
  77. data/lib/axlsx/workbook/workbook.rb +71 -13
  78. data/lib/axlsx/workbook/worksheet/auto_filter.rb +34 -0
  79. data/lib/axlsx/workbook/worksheet/cell.rb +45 -36
  80. data/lib/axlsx/workbook/worksheet/cfvo.rb +62 -0
  81. data/lib/axlsx/workbook/worksheet/col.rb +17 -1
  82. data/lib/axlsx/workbook/worksheet/color_scale.rb +76 -0
  83. data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
  84. data/lib/axlsx/workbook/worksheet/comment.rb +101 -0
  85. data/lib/axlsx/workbook/worksheet/comments.rb +85 -0
  86. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -0
  87. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +216 -0
  88. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
  89. data/lib/axlsx/workbook/worksheet/data_bar.rb +97 -0
  90. data/lib/axlsx/workbook/worksheet/data_validation.rb +245 -0
  91. data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
  92. data/lib/axlsx/workbook/worksheet/dimension.rb +65 -0
  93. data/lib/axlsx/workbook/worksheet/icon_set.rb +83 -0
  94. data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
  95. data/lib/axlsx/workbook/worksheet/page_setup.rb +113 -0
  96. data/lib/axlsx/workbook/worksheet/pane.rb +144 -0
  97. data/lib/axlsx/workbook/worksheet/print_options.rb +63 -0
  98. data/lib/axlsx/workbook/worksheet/protected_range.rb +46 -0
  99. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
  100. data/lib/axlsx/workbook/worksheet/row.rb +69 -12
  101. data/lib/axlsx/workbook/worksheet/selection.rb +111 -0
  102. data/lib/axlsx/workbook/worksheet/sheet_data.rb +25 -0
  103. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +24 -0
  104. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +224 -0
  105. data/lib/axlsx/workbook/worksheet/sheet_view.rb +379 -0
  106. data/lib/axlsx/workbook/worksheet/table.rb +3 -3
  107. data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
  108. data/lib/axlsx/workbook/worksheet/worksheet.rb +379 -233
  109. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
  110. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
  111. data/lib/axlsx.rb +31 -16
  112. data/test/benchmark.rb +30 -38
  113. data/test/content_type/tc_content_type.rb +1 -6
  114. data/test/doc_props/tc_app.rb +31 -1
  115. data/test/doc_props/tc_core.rb +3 -1
  116. data/test/drawing/tc_axis.rb +46 -3
  117. data/test/drawing/tc_bar_3D_chart.rb +12 -12
  118. data/test/drawing/tc_bar_series.rb +17 -13
  119. data/test/drawing/tc_cat_axis.rb +3 -3
  120. data/test/drawing/tc_cat_axis_data.rb +23 -13
  121. data/test/drawing/tc_chart.rb +29 -11
  122. data/test/drawing/tc_d_lbls.rb +47 -0
  123. data/test/drawing/tc_data_source.rb +17 -0
  124. data/test/drawing/tc_drawing.rb +11 -5
  125. data/test/drawing/tc_hyperlink.rb +4 -5
  126. data/test/drawing/tc_line_series.rb +9 -11
  127. data/test/drawing/tc_named_axis_data.rb +27 -0
  128. data/test/drawing/tc_num_data.rb +31 -0
  129. data/test/drawing/tc_num_val.rb +29 -0
  130. data/test/drawing/tc_pic.rb +22 -2
  131. data/test/drawing/tc_pie_3D_chart.rb +4 -8
  132. data/test/drawing/tc_pie_series.rb +11 -13
  133. data/test/drawing/tc_scatter_chart.rb +6 -1
  134. data/test/drawing/tc_scatter_series.rb +6 -5
  135. data/test/drawing/tc_series.rb +1 -1
  136. data/test/drawing/tc_str_data.rb +18 -0
  137. data/test/drawing/tc_str_val.rb +21 -0
  138. data/test/drawing/tc_title.rb +16 -0
  139. data/test/drawing/tc_two_cell_anchor.rb +2 -3
  140. data/test/drawing/tc_view_3D.rb +18 -18
  141. data/test/drawing/tc_vml_drawing.rb +25 -0
  142. data/test/drawing/tc_vml_shape.rb +100 -0
  143. data/test/profile.rb +2 -1
  144. data/test/rels/tc_relationship.rb +1 -0
  145. data/test/stylesheet/tc_dxf.rb +81 -0
  146. data/test/stylesheet/tc_gradient_fill.rb +8 -0
  147. data/test/stylesheet/tc_pattern_fill.rb +7 -1
  148. data/test/stylesheet/tc_styles.rb +163 -3
  149. data/test/stylesheet/tc_table_style.rb +8 -0
  150. data/test/stylesheet/tc_table_style_element.rb +10 -1
  151. data/test/tc_helper.rb +1 -0
  152. data/test/tc_package.rb +93 -17
  153. data/test/util/tc_simple_typed_list.rb +13 -0
  154. data/test/util/tc_validators.rb +95 -9
  155. data/test/workbook/tc_defined_name.rb +41 -0
  156. data/test/workbook/tc_workbook.rb +5 -3
  157. data/test/workbook/worksheet/table/tc_table.rb +3 -11
  158. data/test/workbook/worksheet/tc_cell.rb +52 -18
  159. data/test/workbook/worksheet/tc_cfvo.rb +31 -0
  160. data/test/workbook/worksheet/tc_col.rb +9 -0
  161. data/test/workbook/worksheet/tc_color_scale.rb +29 -0
  162. data/test/workbook/worksheet/tc_comment.rb +57 -0
  163. data/test/workbook/worksheet/tc_comments.rb +57 -0
  164. data/test/workbook/worksheet/tc_conditional_formatting.rb +217 -0
  165. data/test/workbook/worksheet/tc_data_bar.rb +39 -0
  166. data/test/workbook/worksheet/tc_data_validation.rb +265 -0
  167. data/test/workbook/worksheet/tc_date_time_converter.rb +11 -5
  168. data/test/workbook/worksheet/tc_icon_set.rb +45 -0
  169. data/test/workbook/worksheet/tc_page_setup.rb +138 -0
  170. data/test/workbook/worksheet/tc_pane.rb +94 -0
  171. data/test/workbook/worksheet/tc_print_options.rb +72 -0
  172. data/test/workbook/worksheet/tc_protected_range.rb +17 -0
  173. data/test/workbook/worksheet/tc_row.rb +44 -13
  174. data/test/workbook/worksheet/tc_selection.rb +94 -0
  175. data/test/workbook/worksheet/tc_sheet_protection.rb +117 -0
  176. data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
  177. data/test/workbook/worksheet/tc_worksheet.rb +147 -50
  178. metadata +216 -148
  179. data/examples/example.csv +0 -1000
  180. data/examples/example.rb~ +0 -112
  181. data/lib/axlsx/drawing/cat_axis_data.rb +0 -34
  182. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  183. data/lib/axlsx/drawing/hyperlink.rb~ +0 -64
  184. data/lib/axlsx/drawing/named_axis_data.rb +0 -36
  185. data/lib/axlsx/drawing/picture_locking.rb~ +0 -36
  186. data/lib/axlsx/drawing/val_axis_data.rb +0 -27
  187. data/lib/axlsx/stylesheet/#num_fmt.rb# +0 -69
  188. data/lib/axlsx/util/cbf.rb +0 -333
  189. data/lib/axlsx/util/cfb.rb~ +0 -201
  190. data/lib/axlsx/util/ms_off_crypto.rb +0 -189
  191. data/lib/axlsx/util/ms_off_crypto.rb~ +0 -3
  192. data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
  193. data/lib/axlsx/util/parser.rb~ +0 -6
  194. data/lib/axlsx/util/storage.rb~ +0 -0
  195. data/lib/axlsx/workbook/shared_strings_table.rb~ +0 -69
  196. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  197. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  198. data/lib/axlsx/workbook/worksheet/table.rb~ +0 -97
  199. data/lib/schema/dc.xsd~ +0 -118
  200. data/lib/schema/dcterms.xsd~ +0 -331
  201. data/lib/schema/opc-coreProperties.xsd~ +0 -50
  202. data/test/#benchmark.txt# +0 -7
  203. data/test/#tc_helper.rb# +0 -3
  204. data/test/benchmark.rb~ +0 -0
  205. data/test/benchmark.txt +0 -6
  206. data/test/benchmark.txt~ +0 -6
  207. data/test/drawing/tc_val_axis_data.rb +0 -17
  208. data/test/example.csv +0 -1000
  209. data/test/example.xlsx +0 -0
  210. data/test/example_streamed.xlsx +0 -0
  211. data/test/tc_axlsx.rb~ +0 -0
  212. data/test/tc_helper.rb~ +0 -3
  213. data/test/workbook/worksheet/table/tc_table.rb~ +0 -72
  214. data/test/workbook/worksheet/tc_col.rb~ +0 -10
@@ -1,189 +0,0 @@
1
- # encoding: UTF-8
2
- require 'digest'
3
- require 'base64'
4
- require 'openssl'
5
-
6
- module Axlsx
7
-
8
- # The MsOffCrypto class implements ECMA-367 encryption based on the MS-OFF-CRYPTO specification
9
- class MsOffCrypto
10
-
11
- # Creates a new MsOffCrypto Object
12
- # @param [String] file_name the location of the file you want to encrypt
13
- # @param [String] pwd the password to use when encrypting the file
14
- def initialize(file_name, pwd)
15
- self.password = pwd
16
- self.file_name = file_name
17
- end
18
-
19
- # Generates a new CBF file based on this instance of ms-off-crypto and overwrites the unencrypted file.
20
- def save
21
- cfb = Cbf.new(self)
22
- cfb.save
23
- end
24
-
25
- # returns the raw password used in encryption
26
- # @return [String]
27
- attr_reader :password
28
-
29
- # sets the password to be used for encryption
30
- # @param [String] v the password, @default 'password'
31
- # @return [String]
32
- def password=(v)
33
- @password = v || 'password'
34
- end
35
-
36
- # retruns the file name of the archive to be encrypted
37
- # @return [String]
38
- attr_reader :file_name
39
-
40
- # sets the filename
41
- # @return [String]
42
- def file_name=(v)
43
- #TODO verfify that the file specified exists and is an unencrypted xlsx archive
44
- @file_name = v
45
- end
46
-
47
-
48
- # encrypts and returns the package specified by the file name
49
- # @return [String]
50
- def encrypted_package
51
- @encrypted_package ||= encrypt_package(file_name)
52
- end
53
-
54
- # returns the encryption info for this instance of ms-off-crypto
55
- # @return [String]
56
- def encryption_info
57
- @encryption_info ||= create_encryption_info
58
- end
59
-
60
- # returns a random salt
61
- # @return [String]
62
- def salt
63
- @salt ||= Digest::SHA1.digest(rand(16**16).to_s)
64
- end
65
-
66
- # returns a random verifier
67
- # @return [String]
68
- def verifier
69
- @verifier ||= rand(16**16).to_s
70
- end
71
-
72
- # returns the verifier encrytped
73
- # @return [String]
74
- def encrypted_verifier
75
- @encrypted_verifier ||= encrypt(verifier)
76
- end
77
-
78
- # returns the verifier hash encrypted
79
- # @return [String]
80
- def encrypted_verifier_hash
81
- @encrypted_verifier_hash ||= encrypt(verifier_hash)
82
- end
83
-
84
- # returns a verifier hash
85
- # @return [String]
86
- def verifier_hash
87
- @verifier_hash ||= create_verifier_hash
88
- end
89
-
90
- # returns an encryption key
91
- # @return [String]
92
- def key
93
- @key ||= create_key
94
- end
95
-
96
- # size of unencrypted package? concated with encrypted package
97
- def encrypt_package(file_name)
98
- package = File.open(file_name, 'r')
99
- crypt_pack = encrypt(package.read)
100
- [crypt_pack.size].pack('q') + crypt_pack
101
- end
102
-
103
- # Generates an encryption info structure
104
- # @return [String]
105
- def create_encryption_info
106
- header = [3, 0, 2, 0] # version
107
- # Header flags copy
108
- header.concat [0x24, 0, 0, 0] #flags -- VERY UNSURE ABOUT THIS STILL
109
- # header.concat [0, 0, 0, 0] #unused
110
- header.concat [0xA4, 0, 0, 0] #length
111
- # Header
112
- header.concat [0x24, 0, 0, 0] #flags again
113
- # header.concat [0, 0, 0, 0] #unused again,
114
- header.concat [0x0E, 0x66, 0, 0] #alg id
115
- header.concat [0x04, 0x80, 0, 0] #alg hash id
116
- header.concat [key.size, 0, 0, 0] #key size
117
- header.concat [0x18, 0, 0, 0] #provider type
118
- # header.concat [0, 0, 0, 0] #reserved 1
119
- # header.concat [0, 0, 0, 0] #reserved 2
120
- header.concat [0xA0, 0xC7, 0xDC, 0x2, 0, 0, 0, 0]
121
- header.concat "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)".bytes.to_a.pack('s*').bytes.to_a
122
- header.concat [0, 0] #null terminator
123
-
124
- #Salt Size
125
- header.concat [salt.bytes.to_a.size].pack('l').bytes.to_a
126
- #Salt
127
- header.concat salt.bytes.to_a.pack('c*').bytes.to_a
128
- # encryption verifier
129
- header.concat encrypted_verifier.bytes.to_a.pack('c*').bytes.to_a
130
-
131
- # verifier hash size -- MUST BE 32 bytes
132
- header.concat [verifier_hash.bytes.to_a.size].pack('l').bytes.to_a
133
-
134
- #encryption verifier hash
135
- header.concat encrypted_verifier_hash.bytes.to_a.pack('c*').bytes.to_a
136
-
137
- header.flatten!
138
- header.pack('c*')
139
- end
140
-
141
- # 2.3.3
142
- def create_verifier_hash
143
- vh = Digest::SHA1.digest(verifier)
144
- vh << Array.new(32 - vh.size, 0).join('')
145
- end
146
-
147
- # 2.3.4.7 ECMA-376 Document Encryption Key Generation (Standard Encryption)
148
- def create_key
149
- sha = Digest::SHA1.new() << (salt + @password)
150
- (0..49999).each { |i| sha.update(i.to_s+sha.to_s) }
151
- key = sha.update(sha.to_s+'0').digest
152
- a = key.bytes.each_with_index.map { |item, i| 0x36 ^ item }
153
- x1 = Digest::SHA1.digest((a.concat Array.new(64 - key.size, 0x36)).to_s)
154
- a = key.bytes.each_with_index.map { |item, i| 0x5C ^ item }
155
- x2 = Digest::SHA1.digest( (a.concat Array.new(64 - key.size, 0x5C) ).to_s)
156
- x3 = x1 + x2
157
- x3.bytes.to_a[(0..31)].pack('c*')
158
- end
159
-
160
- # ensures that the a hashed decryption of the encryption verifier matches the decrypted verifier hash.
161
- # @return [Boolean]
162
- def verify_password
163
- v = Digest::SHA1.digest decrypt(@encrypted_verifier)
164
- vh = decrypt(@encrypted_verifier_hash)
165
- vh[0..15] == v[0..15]
166
- end
167
-
168
- # encrypts the data proved
169
- # @param [String] data
170
- # @return [String] the encrypted data
171
- def encrypt(data)
172
- aes = OpenSSL::Cipher.new("AES-128-ECB")
173
- aes.encrypt
174
- aes.key = key
175
- aes.update(data) << aes.final
176
- end
177
-
178
- # dencrypts the data proved
179
- # @param [String] data
180
- # @return [String] the dencrypted data
181
- def decrypt(data)
182
- aes = OpenSSL::Cipher.new("AES-128-ECB")
183
- aes.decrypt
184
- aes.key = key
185
- aes.update(data) << aes.final
186
- end
187
-
188
- end
189
- end
@@ -1,3 +0,0 @@
1
- module Axlsx
2
- class MsOffcrypto
3
- end
File without changes
@@ -1,6 +0,0 @@
1
- module Axlsx
2
- # THe Parser class unzips an xlsx spread sheet and populates a new axlsx package from it.
3
- class Parser
4
-
5
- end
6
- end
File without changes
@@ -1,69 +0,0 @@
1
- # encoding: UTF--8
2
- module Axlsx
3
-
4
- # The Shared String Table class is responsible for managing and serializing common strings in a workbook.
5
- # While the ECMA-376 spec allows for both inline and shared strings it seems that at least some applications like Numbers (Mac)
6
- # and Google Docs require that the shared string table is populated in order to interoperate properly.
7
- # As a developer, you should never need to directly work against this class. Simply set 'use_shared_strings'
8
- # on the package or workbook to generate a package that uses the shared strings table instead of inline strings.
9
- # @note Serialization performance is affected by using this serialization method so if you do not need interoperability
10
- # it is recomended that you use the default inline string method of serialization.
11
- class SharedStringsTable
12
-
13
- # The total number of strings in the workbook including duplicates
14
- # Empty cells are treated as blank strings
15
- # @return [Integer]
16
- attr_reader :count
17
-
18
- # The total number of unique strings in the workbook.
19
- # @return [Integer]
20
- def unique_count
21
- @unique_cells.size
22
- end
23
-
24
- # An array of unique cells. Multiple attributes of the cell are used in comparison
25
- # each of these unique cells is parsed into the shared string table.
26
- # @see Cell#sharable
27
- attr_reader :unique_cells
28
-
29
- # Creates a new Shared Strings Table agains an array of cells
30
- # @param [Array] cells This is an array of all of the cells in the workbook
31
- def initialize(cells)
32
- cells = cells.reject { |c| c.type != :string }
33
- @count = cells.size
34
- @unique_cells = []
35
- resolve cells
36
- end
37
-
38
- # Interate over all of the cells in the array.
39
- # if our unique cells array does not contain a sharable cell,
40
- # add the cell to our unique cells array and set the ssti attribute on the index of this cell in the shared strings table
41
- # if a sharable cell already exists in our unique_cells array, set the ssti attribute of the cell and move on.
42
- # @return [Array] unique cells
43
- def resolve(cells)
44
- cells.each do |cell|
45
- index = @unique_cells.index { |item| item.sharable(cell) }
46
- if index == nil
47
- cell.ssti = @unique_cells.size
48
- @unique_cells << cell
49
- else
50
- cell.ssti = index
51
- end
52
- end
53
- end
54
-
55
- # Generate the xml document for the Shared Strings Table
56
- # @return [String]
57
- def to_xml
58
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
59
- xml.sst(:xmlns => Axlsx::XML_NS, :count => count, :uniqueCount => unique_count) {
60
- @unique_cells.each do |cell|
61
- xml.si { xml.t cell.value.to_s }
62
- end
63
- }
64
- end
65
- builder.to_xml(:save_with => 0)
66
- end
67
- end
68
-
69
- end
File without changes
@@ -1,97 +0,0 @@
1
- # encoding: UTF-8
2
- module Axlsx
3
- # Table
4
- # @note Worksheet#add_table is the recommended way to create charts for your worksheets.
5
- # @see README for examples
6
- class Table
7
-
8
-
9
- # The reference to the table data
10
- # @return [String]
11
- attr_reader :ref
12
-
13
- # The name of the table.
14
- # @return [String]
15
- attr_reader :name
16
-
17
- # The style for the table.
18
- # @return [TableStyle]
19
- attr_reader :style
20
-
21
- # Creates a new Table object
22
- # @param [String] ref The reference to the table data.
23
- # @param [Sheet] ref The sheet containing the table data.
24
- # @option options [Cell, String] name
25
- # @option options [TableStyle] style
26
- def initialize(ref, sheet, options={})
27
- @ref = ref
28
- @sheet = sheet
29
- @style = nil
30
- @sheet.workbook.tables << self
31
- @name = "Table#{index+1}"
32
- options.each do |o|
33
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
34
- end
35
- yield self if block_given?
36
- end
37
-
38
- # The index of this chart in the workbooks charts collection
39
- # @return [Integer]
40
- def index
41
- @sheet.workbook.tables.index(self)
42
- end
43
-
44
- # The part name for this table
45
- # @return [String]
46
- def pn
47
- "#{TABLE_PN % (index+1)}"
48
- end
49
-
50
- # The relation reference id for this table
51
- # @return [String]
52
- def rId
53
- "rId#{index+1}"
54
- end
55
-
56
- # The name of the Table.
57
- # @param [String, Cell] v
58
- # @return [Title]
59
- def name=(v)
60
- DataTypeValidator.validate "#{self.class}.name", [String], v
61
- if v.is_a?(String)
62
- @name = v
63
- end
64
- end
65
-
66
-
67
- # The style for the table.
68
- # TODO
69
- # def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end
70
-
71
- # Table Serialization
72
- # serializes the table
73
- def to_xml
74
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
75
- xml.table(:xmlns => XML_NS, :id => index+1, :name => @name, :displayName => @name.gsub(/\s/,'_'), :ref => @ref, :totalsRowShown => 0) {
76
- xml.autoFilter :ref=>@ref
77
- xml.tableColumns(:count => header_cells.length) {
78
- header_cells.each_with_index do |cell,index|
79
- xml.tableColumn :id => index+1, :name => cell.value
80
- end
81
- }
82
- xml.tableStyleInfo :showFirstColumn=>"0", :showLastColumn=>"0", :showRowStripes=>"1", :showColumnStripes=>"0", :name=>"TableStyleMedium9"
83
- #TODO implement tableStyleInfo
84
- }
85
- end
86
- builder.to_xml(:save_with => 0)
87
- end
88
-
89
- private
90
-
91
- # get the header cells (hackish)
92
- def header_cells
93
- header = @ref.gsub(/^(\w+)(\d+)\:(\w+)\d+$/, '\1\2:\3\2')
94
- @sheet[header]
95
- end
96
- end
97
- end
data/lib/schema/dc.xsd~ DELETED
@@ -1,118 +0,0 @@
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="http://www.w3.org/2001/03/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>