write_xlsx 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. data/.document +5 -0
  2. data/.gitattributes +1 -0
  3. data/Gemfile +12 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +82 -0
  6. data/Rakefile +78 -0
  7. data/VERSION +1 -0
  8. data/examples/a_simple.rb +45 -0
  9. data/examples/array_formula.rb +33 -0
  10. data/examples/autofilter.rb +235 -0
  11. data/examples/chart_area.rb +59 -0
  12. data/examples/chart_bar.rb +59 -0
  13. data/examples/chart_column.rb +58 -0
  14. data/examples/chart_line.rb +59 -0
  15. data/examples/chart_pie.rb +49 -0
  16. data/examples/chart_scatter.rb +59 -0
  17. data/examples/chart_stock.rb +65 -0
  18. data/examples/colors.rb +130 -0
  19. data/examples/comments1.rb +12 -0
  20. data/examples/comments2.rb +335 -0
  21. data/examples/conditional_format.rb +67 -0
  22. data/examples/data_validate.rb +279 -0
  23. data/examples/defined_name.rb +28 -0
  24. data/examples/demo.rb +104 -0
  25. data/examples/diag_border.rb +26 -0
  26. data/examples/headers.rb +119 -0
  27. data/examples/hide_sheet.rb +30 -0
  28. data/examples/hyperlink1.rb +58 -0
  29. data/examples/indent.rb +28 -0
  30. data/examples/merge1.rb +38 -0
  31. data/examples/merge2.rb +48 -0
  32. data/examples/merge3.rb +43 -0
  33. data/examples/merge4.rb +82 -0
  34. data/examples/merge5.rb +70 -0
  35. data/examples/merge6.rb +48 -0
  36. data/examples/outline.rb +252 -0
  37. data/examples/properties.rb +33 -0
  38. data/examples/protection.rb +34 -0
  39. data/examples/rich_strings.rb +42 -0
  40. data/examples/right_to_left.rb +24 -0
  41. data/examples/tab_colors.rb +26 -0
  42. data/lib/write_xlsx.rb +77 -0
  43. data/lib/write_xlsx/chart.rb +3027 -0
  44. data/lib/write_xlsx/chart/area.rb +52 -0
  45. data/lib/write_xlsx/chart/bar.rb +126 -0
  46. data/lib/write_xlsx/chart/column.rb +132 -0
  47. data/lib/write_xlsx/chart/line.rb +51 -0
  48. data/lib/write_xlsx/chart/pie.rb +210 -0
  49. data/lib/write_xlsx/chart/scatter.rb +252 -0
  50. data/lib/write_xlsx/chart/stock.rb +134 -0
  51. data/lib/write_xlsx/chartsheet.rb +173 -0
  52. data/lib/write_xlsx/colors.rb +65 -0
  53. data/lib/write_xlsx/compatibility.rb +71 -0
  54. data/lib/write_xlsx/drawing.rb +547 -0
  55. data/lib/write_xlsx/format.rb +683 -0
  56. data/lib/write_xlsx/package/app.rb +218 -0
  57. data/lib/write_xlsx/package/comments.rb +221 -0
  58. data/lib/write_xlsx/package/content_types.rb +189 -0
  59. data/lib/write_xlsx/package/core.rb +196 -0
  60. data/lib/write_xlsx/package/packager.rb +510 -0
  61. data/lib/write_xlsx/package/relationships.rb +98 -0
  62. data/lib/write_xlsx/package/shared_strings.rb +96 -0
  63. data/lib/write_xlsx/package/styles.rb +705 -0
  64. data/lib/write_xlsx/package/theme.rb +45 -0
  65. data/lib/write_xlsx/package/vml.rb +386 -0
  66. data/lib/write_xlsx/package/xml_writer_simple.rb +90 -0
  67. data/lib/write_xlsx/utility.rb +113 -0
  68. data/lib/write_xlsx/workbook.rb +1488 -0
  69. data/lib/write_xlsx/worksheet.rb +6578 -0
  70. data/lib/write_xlsx/zip_file_utils.rb +98 -0
  71. data/test/chart/test_add_series.rb +113 -0
  72. data/test/chart/test_process_names.rb +27 -0
  73. data/test/chart/test_write_auto.rb +15 -0
  74. data/test/chart/test_write_ax_id.rb +15 -0
  75. data/test/chart/test_write_ax_pos.rb +15 -0
  76. data/test/chart/test_write_chart_space.rb +15 -0
  77. data/test/chart/test_write_cross_ax.rb +15 -0
  78. data/test/chart/test_write_crosses.rb +15 -0
  79. data/test/chart/test_write_format_code.rb +15 -0
  80. data/test/chart/test_write_idx.rb +15 -0
  81. data/test/chart/test_write_label_align.rb +15 -0
  82. data/test/chart/test_write_label_offset.rb +15 -0
  83. data/test/chart/test_write_lang.rb +15 -0
  84. data/test/chart/test_write_layout.rb +15 -0
  85. data/test/chart/test_write_legend.rb +16 -0
  86. data/test/chart/test_write_legend_pos.rb +15 -0
  87. data/test/chart/test_write_major_gridlines.rb +15 -0
  88. data/test/chart/test_write_marker.rb +17 -0
  89. data/test/chart/test_write_marker_size.rb +15 -0
  90. data/test/chart/test_write_marker_value.rb +16 -0
  91. data/test/chart/test_write_num_cache.rb +16 -0
  92. data/test/chart/test_write_num_fmt.rb +16 -0
  93. data/test/chart/test_write_number_format.rb +15 -0
  94. data/test/chart/test_write_order.rb +15 -0
  95. data/test/chart/test_write_orientation.rb +15 -0
  96. data/test/chart/test_write_page_margins.rb +15 -0
  97. data/test/chart/test_write_page_setup.rb +15 -0
  98. data/test/chart/test_write_plot_vis_only.rb +15 -0
  99. data/test/chart/test_write_pt.rb +16 -0
  100. data/test/chart/test_write_pt_count.rb +16 -0
  101. data/test/chart/test_write_series_formula.rb +16 -0
  102. data/test/chart/test_write_style.rb +41 -0
  103. data/test/chart/test_write_symbol.rb +16 -0
  104. data/test/chart/test_write_tick_lbl_pos.rb +16 -0
  105. data/test/chart/test_write_v.rb +16 -0
  106. data/test/drawing/test_drawing_chart_01.rb +50 -0
  107. data/test/drawing/test_drawing_image_01.rb +59 -0
  108. data/test/helper.rb +90 -0
  109. data/test/package/app/test_app01.rb +44 -0
  110. data/test/package/app/test_app02.rb +46 -0
  111. data/test/package/app/test_app03.rb +53 -0
  112. data/test/package/comments/test_comments01.rb +36 -0
  113. data/test/package/comments/test_write_text_t.rb +44 -0
  114. data/test/package/content_types/test_content_types.rb +35 -0
  115. data/test/package/content_types/test_write_default.rb +13 -0
  116. data/test/package/content_types/test_write_override.rb +13 -0
  117. data/test/package/core/test_core01.rb +28 -0
  118. data/test/package/core/test_core02.rb +42 -0
  119. data/test/package/relationships/test_relationships.rb +28 -0
  120. data/test/package/relationships/test_sheet_rels.rb +22 -0
  121. data/test/package/shared_strings/test_shared_strings01.rb +30 -0
  122. data/test/package/shared_strings/test_shared_strings02.rb +30 -0
  123. data/test/package/shared_strings/test_write_si.rb +13 -0
  124. data/test/package/shared_strings/test_write_sst.rb +15 -0
  125. data/test/package/styles/test_styles_01.rb +69 -0
  126. data/test/package/styles/test_styles_02.rb +104 -0
  127. data/test/package/styles/test_styles_03.rb +90 -0
  128. data/test/package/styles/test_styles_04.rb +216 -0
  129. data/test/package/styles/test_styles_05.rb +150 -0
  130. data/test/package/styles/test_styles_06.rb +104 -0
  131. data/test/package/styles/test_styles_07.rb +104 -0
  132. data/test/package/styles/test_styles_08.rb +109 -0
  133. data/test/package/styles/test_styles_09.rb +95 -0
  134. data/test/package/vml/test_vml_01.rb +42 -0
  135. data/test/package/vml/test_write_anchor.rb +14 -0
  136. data/test/package/vml/test_write_auto_fill.rb +14 -0
  137. data/test/package/vml/test_write_column.rb +14 -0
  138. data/test/package/vml/test_write_div.rb +14 -0
  139. data/test/package/vml/test_write_fill.rb +14 -0
  140. data/test/package/vml/test_write_idmap.rb +14 -0
  141. data/test/package/vml/test_write_move_with_cells.rb +14 -0
  142. data/test/package/vml/test_write_path.rb +22 -0
  143. data/test/package/vml/test_write_row.rb +14 -0
  144. data/test/package/vml/test_write_shadow.rb +14 -0
  145. data/test/package/vml/test_write_shapelayout.rb +14 -0
  146. data/test/package/vml/test_write_shapetype.rb +14 -0
  147. data/test/package/vml/test_write_size_with_cells.rb +14 -0
  148. data/test/package/vml/test_write_stroke.rb +14 -0
  149. data/test/package/vml/test_write_textbox.rb +14 -0
  150. data/test/perl_output/a_simple.xlsx +0 -0
  151. data/test/perl_output/array_formula.xlsx +0 -0
  152. data/test/perl_output/autofilter.xlsx +0 -0
  153. data/test/perl_output/chart_area.xlsx +0 -0
  154. data/test/perl_output/chart_bar.xlsx +0 -0
  155. data/test/perl_output/chart_column.xlsx +0 -0
  156. data/test/perl_output/chart_line.xlsx +0 -0
  157. data/test/perl_output/chart_pie.xlsx +0 -0
  158. data/test/perl_output/chart_scatter.xlsx +0 -0
  159. data/test/perl_output/chart_stock.xlsx +0 -0
  160. data/test/perl_output/comments1.xlsx +0 -0
  161. data/test/perl_output/comments2.xlsx +0 -0
  162. data/test/perl_output/conditional_format.xlsx +0 -0
  163. data/test/perl_output/data_validate.xlsx +0 -0
  164. data/test/perl_output/defined_name.xlsx +0 -0
  165. data/test/perl_output/demo.xlsx +0 -0
  166. data/test/perl_output/diag_border.xlsx +0 -0
  167. data/test/perl_output/fit_to_pages.xlsx +0 -0
  168. data/test/perl_output/headers.xlsx +0 -0
  169. data/test/perl_output/hide_sheet.xlsx +0 -0
  170. data/test/perl_output/hyperlink.xlsx +0 -0
  171. data/test/perl_output/indent.xlsx +0 -0
  172. data/test/perl_output/merge1.xlsx +0 -0
  173. data/test/perl_output/merge2.xlsx +0 -0
  174. data/test/perl_output/merge3.xlsx +0 -0
  175. data/test/perl_output/merge4.xlsx +0 -0
  176. data/test/perl_output/merge5.xlsx +0 -0
  177. data/test/perl_output/merge6.xlsx +0 -0
  178. data/test/perl_output/outline.xlsx +0 -0
  179. data/test/perl_output/print_scale.xlsx +0 -0
  180. data/test/perl_output/properties.xlsx +0 -0
  181. data/test/perl_output/protection.xlsx +0 -0
  182. data/test/perl_output/rich_strings.xlsx +0 -0
  183. data/test/perl_output/right_to_left.xlsx +0 -0
  184. data/test/perl_output/tab_colors.xlsx +0 -0
  185. data/test/test_delete_files.rb +37 -0
  186. data/test/test_example_match.rb +2281 -0
  187. data/test/test_xml_writer_simple.rb +63 -0
  188. data/test/workbook/test_get_chart_range.rb +59 -0
  189. data/test/workbook/test_sort_defined_names.rb +77 -0
  190. data/test/workbook/test_workbook_01.rb +29 -0
  191. data/test/workbook/test_workbook_02.rb +31 -0
  192. data/test/workbook/test_workbook_03.rb +31 -0
  193. data/test/workbook/test_workbook_new.rb +18 -0
  194. data/test/workbook/test_write_defined_name.rb +17 -0
  195. data/test/workbook/test_write_defined_names.rb +41 -0
  196. data/test/worksheet/test_calculate_spans.rb +58 -0
  197. data/test/worksheet/test_convert_date_time_01.rb +439 -0
  198. data/test/worksheet/test_convert_date_time_02.rb +478 -0
  199. data/test/worksheet/test_convert_date_time_03.rb +435 -0
  200. data/test/worksheet/test_extract_filter_tokens.rb +109 -0
  201. data/test/worksheet/test_parse_filter_expression.rb +143 -0
  202. data/test/worksheet/test_position_object.rb +50 -0
  203. data/test/worksheet/test_repeat_formula.rb +55 -0
  204. data/test/worksheet/test_worksheet_01.rb +32 -0
  205. data/test/worksheet/test_worksheet_02.rb +38 -0
  206. data/test/worksheet/test_worksheet_03.rb +44 -0
  207. data/test/worksheet/test_worksheet_04.rb +45 -0
  208. data/test/worksheet/test_write_array_formula_01.rb +99 -0
  209. data/test/worksheet/test_write_autofilter.rb +260 -0
  210. data/test/worksheet/test_write_brk.rb +18 -0
  211. data/test/worksheet/test_write_cell.rb +49 -0
  212. data/test/worksheet/test_write_cell_value.rb +33 -0
  213. data/test/worksheet/test_write_col_breaks.rb +27 -0
  214. data/test/worksheet/test_write_col_info.rb +95 -0
  215. data/test/worksheet/test_write_conditional_formatting.rb +72 -0
  216. data/test/worksheet/test_write_custom_filter.rb +18 -0
  217. data/test/worksheet/test_write_custom_filters.rb +25 -0
  218. data/test/worksheet/test_write_data_validation_01.rb +113 -0
  219. data/test/worksheet/test_write_data_validation_02.rb +528 -0
  220. data/test/worksheet/test_write_dimension.rb +94 -0
  221. data/test/worksheet/test_write_ext.rb +18 -0
  222. data/test/worksheet/test_write_ext_lst.rb +18 -0
  223. data/test/worksheet/test_write_filter.rb +18 -0
  224. data/test/worksheet/test_write_filter_column.rb +18 -0
  225. data/test/worksheet/test_write_filters.rb +32 -0
  226. data/test/worksheet/test_write_header_footer.rb +53 -0
  227. data/test/worksheet/test_write_hyperlink.rb +39 -0
  228. data/test/worksheet/test_write_hyperlinks.rb +27 -0
  229. data/test/worksheet/test_write_legacy_drawing.rb +19 -0
  230. data/test/worksheet/test_write_merge_cell.rb +18 -0
  231. data/test/worksheet/test_write_merge_cells.rb +192 -0
  232. data/test/worksheet/test_write_methods.rb +353 -0
  233. data/test/worksheet/test_write_mx_plv.rb +19 -0
  234. data/test/worksheet/test_write_page_margins.rb +98 -0
  235. data/test/worksheet/test_write_page_set_up_pr.rb +19 -0
  236. data/test/worksheet/test_write_page_setup.rb +54 -0
  237. data/test/worksheet/test_write_pane.rb +123 -0
  238. data/test/worksheet/test_write_phonetic_pr.rb +19 -0
  239. data/test/worksheet/test_write_print_options.rb +77 -0
  240. data/test/worksheet/test_write_row_breaks.rb +27 -0
  241. data/test/worksheet/test_write_row_element.rb +69 -0
  242. data/test/worksheet/test_write_selection.rb +18 -0
  243. data/test/worksheet/test_write_sheet_calc_pr.rb +18 -0
  244. data/test/worksheet/test_write_sheet_data.rb +18 -0
  245. data/test/worksheet/test_write_sheet_format_pr.rb +18 -0
  246. data/test/worksheet/test_write_sheet_pr.rb +36 -0
  247. data/test/worksheet/test_write_sheet_protection.rb +174 -0
  248. data/test/worksheet/test_write_sheet_view.rb +62 -0
  249. data/test/worksheet/test_write_sheet_view1.rb +64 -0
  250. data/test/worksheet/test_write_sheet_view2.rb +56 -0
  251. data/test/worksheet/test_write_sheet_view3.rb +83 -0
  252. data/test/worksheet/test_write_sheet_view4.rb +83 -0
  253. data/test/worksheet/test_write_sheet_view5.rb +74 -0
  254. data/test/worksheet/test_write_sheet_view6.rb +51 -0
  255. data/test/worksheet/test_write_sheet_view7.rb +71 -0
  256. data/test/worksheet/test_write_sheet_view8.rb +51 -0
  257. data/test/worksheet/test_write_sheet_view9.rb +51 -0
  258. data/test/worksheet/test_write_tab_color.rb +23 -0
  259. data/test/worksheet/test_write_worksheet.rb +19 -0
  260. data/write_xlsx.gemspec +308 -0
  261. metadata +363 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ *.rb diff=ruby
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "rubyzip", ">= 0"
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.6.4"
11
+ gem "rcov", ">= 0"
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Hideo NAKAMURA
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,82 @@
1
+ = write_xlsx
2
+
3
+ gem to create a new file in the Excel 2007+ XLSX format, and you can use the same interface as writeexcel gem. write_xlsx is converted from Perl's module https://github.com/jmcnamara/excel-writer-xlsx .
4
+
5
+ == Description
6
+
7
+ The WriteXLSX supports the following features:
8
+ * Multiple worksheets
9
+ * Strings and numbers
10
+ * Unicode text
11
+ * Rich string formats
12
+ * Formulas (including array formats)
13
+ * cell formatting
14
+ * Embedded images
15
+ * Charts
16
+ * Autofilters
17
+ * Data validation
18
+ * Hyperlinks
19
+ * Defined names
20
+ * Grouping/Outlines
21
+ * Cell comments
22
+ * Panes
23
+ * Page set-up and printing options
24
+
25
+ write_xlsx uses the same interface as writeexcel gem.
26
+
27
+ documentation is not completed, but writeexcel's documentation will help you. See http://writeexcel.web.fc2.com/
28
+
29
+ And you can find many examples in this gem.
30
+
31
+ == Synopsis
32
+
33
+ To write a string, a formatted string, a number and a formula to the first worksheet
34
+ in an Excel XMLX spreadsheet called ruby.xlsx:
35
+
36
+ require 'rubygems'
37
+ require 'write_xlsx'
38
+
39
+ # Create a new Excel workbook
40
+ workbook = WriteXLSX.new('ruby.xlsx')
41
+
42
+ # Add a worksheet
43
+ worksheet = workbook.add_worksheet
44
+
45
+ # Add and define a format
46
+ format = workbook.add_format # Add a format
47
+ format.set_bold
48
+ format.set_color('red')
49
+ format.set_align('center')
50
+
51
+ # Write a formatted and unformatted string, row and column notation.
52
+ col = row = 0
53
+ worksheet.write(row, col, "Hi Excel!", format)
54
+ worksheet.write(1, col, "Hi Excel!")
55
+
56
+ # Write a number and a formula using A1 notation
57
+ worksheet.write('A3', 1.2345)
58
+ worksheet.write('A4', '=SIN(PI()/4)')
59
+ workbook.close
60
+
61
+ == Recent change
62
+
63
+ 2012-01-20 v0.0.1
64
+ initial release
65
+
66
+ == Copyright
67
+ Original Perl module was written by John McNamara(jmcnamara@cpan.org).
68
+
69
+ Converted to ruby by Hideo NAKAMURA(cxn03651@msj.biglobe.ne.jp) Copyright (c) 2012 HIDEO NAKAMURA. See LICENSE.txt for further details.
70
+
71
+ == Contributing to write_xlsx
72
+
73
+ * repsitory: http://github.com/cxn03651/write_xlsx
74
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
75
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
76
+ * Fork the project
77
+ * Start a feature/bugfix branch
78
+ * Commit and push until you are happy with your contribution
79
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
80
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
81
+
82
+
data/Rakefile ADDED
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "write_xlsx"
18
+ gem.homepage = "http://github.com/cxn03651/write_xlsx"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{write_xlsx is a gem to create a new file in the Excel 2007+ XLSX format.}
21
+ gem.description = <<EOS
22
+ write_xlsx s a gem to create a new file in the Excel 2007+ XLSX format, and you can use the same interface as writeexcel gem.
23
+ The WriteXLSX supports the following features:
24
+ * Multiple worksheets
25
+ * Strings and numbers
26
+ * Unicode text
27
+ * Rich string formats
28
+ * Formulas (including array formats)
29
+ * cell formatting
30
+ * Embedded images
31
+ * Charts
32
+ * Autofilters
33
+ * Data validation
34
+ * Hyperlinks
35
+ * Defined names
36
+ * Grouping/Outlines
37
+ * Cell comments
38
+ * Panes
39
+ * Page set-up and printing options
40
+
41
+ write_xlsx uses the same interface as writeexcel gem.
42
+
43
+ documentation is not completed, but writeexcel’s documentation will help you. See writeexcel.web.fc2.com/
44
+
45
+ And you can find many examples in this gem.
46
+ EOS
47
+ gem.email = "cxn03651@msj.biglobe.ne.jp"
48
+ gem.authors = ["Hideo NAKAMURA"]
49
+ # dependencies defined in Gemfile
50
+ end
51
+ Jeweler::RubygemsDotOrgTasks.new
52
+
53
+ require 'rake/testtask'
54
+ Rake::TestTask.new(:test) do |test|
55
+ test.libs << 'lib' << 'test'
56
+ test.pattern = 'test/**/test_*.rb'
57
+ test.verbose = true
58
+ end
59
+
60
+ require 'rcov/rcovtask'
61
+ Rcov::RcovTask.new do |test|
62
+ test.libs << 'test'
63
+ test.pattern = 'test/**/test_*.rb'
64
+ test.verbose = true
65
+ test.rcov_opts << '--exclude "gems/*"'
66
+ end
67
+
68
+ task :default => :test
69
+
70
+ require 'rake/rdoctask'
71
+ Rake::RDocTask.new do |rdoc|
72
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
73
+
74
+ rdoc.rdoc_dir = 'rdoc'
75
+ rdoc.title = "write_xlsx #{version}"
76
+ rdoc.rdoc_files.include('README*')
77
+ rdoc.rdoc_files.include('lib/**/*.rb')
78
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # A simple example of how to use the Excel::Writer::XLSX module to
7
+ # write text and numbers to an Excel xlsx file.
8
+ #
9
+ # reverse(c), March 2001, John McNamara, jmcnamara@cpan.org
10
+ # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+
13
+ require 'rubygems'
14
+ require 'write_xlsx'
15
+
16
+ # Create a new workbook called simple.xls and add a worksheet
17
+ workbook = WriteXLSX.new('a_simple.xlsx')
18
+ worksheet = workbook.add_worksheet
19
+
20
+ # The general syntax is write(row, column, token). Note that row and
21
+ # column are zero indexed
22
+ #
23
+
24
+ # Write some text
25
+ worksheet.write(0, 0, "Hi Excel!")
26
+
27
+ # Write some numbers
28
+ worksheet.write(2, 0, 3) # Writes 3
29
+ worksheet.write(3, 0, 3.00000) # Writes 3
30
+ worksheet.write(4, 0, 3.00001) # Writes 3.00001
31
+ worksheet.write(5, 0, 3.14159) # TeX revision no.?
32
+
33
+ # Write some formulas
34
+ worksheet.write(7, 0, '=A3 + A6')
35
+ worksheet.write(8, 0, '=IF(A5>3,"Yes", "No")')
36
+
37
+ # Write a hyperlink
38
+ hyperlink_format = workbook.add_format(
39
+ :color => 'blue',
40
+ :underline => 1
41
+ )
42
+
43
+ worksheet.write(10, 0, 'http://www.ruby-lang.org/', hyperlink_format)
44
+
45
+ workbook.close
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # Example of how to use the WriteXLSX gem to write simple
7
+ # array formulas.
8
+ #
9
+ # reverse(c), August 2004, John McNamara, jmcnamara@cpan.org
10
+ # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+
13
+ require 'rubygems'
14
+ require 'write_xlsx'
15
+
16
+ # Create a new workbook and add a worksheet
17
+ workbook = WriteXLSX.new('array_formula.xlsx')
18
+ worksheet = workbook.add_worksheet
19
+
20
+ # Write some test data.
21
+ worksheet.write('B1', [ [ 500, 10 ], [ 300, 15 ] ])
22
+ worksheet.write('B5', [ [ 1, 2, 3 ], [ 20234, 21003, 10000 ] ])
23
+
24
+ # Write an array formula that returns a single value
25
+ worksheet.write('A1', '{=SUM(B1:C1*B2:C2)}')
26
+
27
+ # Same as above but more verbose.
28
+ worksheet.write_array_formula('A2:A2', '{=SUM(B1:C1*B2:C2)}')
29
+
30
+ # Write an array formula that returns a range of values
31
+ worksheet.write_array_formula('A5:A7', '{=TREND(C5:C7,B5:B7)}')
32
+
33
+ workbook.close
@@ -0,0 +1,235 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # An example of how to create autofilters with Excel::Writer::XLSX.
7
+ #
8
+ # An autofilter is a way of adding drop down lists to the headers of a 2D range
9
+ # of worksheet data. This is turn allow users to filter the data based on
10
+ # simple criteria so that some data is shown and some is hidden.
11
+ #
12
+ # reverse('ゥ'), September 2007, John McNamara, jmcnamara@cpan.org
13
+ #
14
+
15
+ require 'rubygems'
16
+ require 'write_xlsx'
17
+
18
+ workbook = WriteXLSX.new( 'autofilter.xlsx' )
19
+
20
+ worksheet1 = workbook.add_worksheet
21
+ worksheet2 = workbook.add_worksheet
22
+ worksheet3 = workbook.add_worksheet
23
+ worksheet4 = workbook.add_worksheet
24
+ worksheet5 = workbook.add_worksheet
25
+ worksheet6 = workbook.add_worksheet
26
+
27
+ bold = workbook.add_format( :bold => 1 )
28
+
29
+ # Extract the data embedded at the end of this file.
30
+ headings = DATA.gets.split
31
+ data = []
32
+ DATA.each { |line| data << line.split }
33
+
34
+ # Set up several sheets with the same data.
35
+ workbook.worksheets.each do |worksheet|
36
+ worksheet.set_column( 'A:D', 12 )
37
+ worksheet.set_row( 0, 20, bold )
38
+ worksheet.write( 'A1', headings )
39
+ end
40
+
41
+
42
+ ###############################################################################
43
+ #
44
+ # Example 1. Autofilter without conditions.
45
+ #
46
+
47
+ worksheet1.autofilter( 'A1:D51' )
48
+ worksheet1.write( 'A2', [ data ] )
49
+
50
+ ###############################################################################
51
+ #
52
+ #
53
+ # Example 2. Autofilter with a filter condition in the first column.
54
+ #
55
+
56
+ # The range in this example is the same as above but in row-column notation.
57
+ worksheet2.autofilter( 0, 0, 50, 3 )
58
+
59
+ # The placeholder "Region" in the filter is ignored and can be any string
60
+ # that adds clarity to the expression.
61
+ #
62
+ worksheet2.filter_column( 0, 'Region eq East' )
63
+
64
+ #
65
+ # Hide the rows that don't match the filter criteria.
66
+ #
67
+ row = 1
68
+
69
+ data.each do |row_data|
70
+ region = row_data[0]
71
+
72
+ worksheet2.set_row(row, nil, nil, 1) unless region == 'East'
73
+ worksheet2.write(row, 0, row_data)
74
+ row += 1
75
+ end
76
+
77
+ ###############################################################################
78
+ #
79
+ #
80
+ # Example 3. Autofilter with a dual filter condition in one of the columns.
81
+ #
82
+
83
+ worksheet3.autofilter( 'A1:D51' )
84
+
85
+ worksheet3.filter_column( 'A', 'x eq East or x eq South' )
86
+
87
+ #
88
+ # Hide the rows that don't match the filter criteria.
89
+ #
90
+ row = 1
91
+
92
+ data.each do |row_data|
93
+ region = row_data[0]
94
+
95
+ worksheet3.set_row(row, nil, nil, 1) unless region == 'East' || region == 'South'
96
+ worksheet3.write(row, 0,row_data)
97
+ row += 1
98
+ end
99
+
100
+
101
+ ###############################################################################
102
+ #
103
+ #
104
+ # Example 4. Autofilter with filter conditions in two columns.
105
+ #
106
+
107
+ worksheet4.autofilter('A1:D51')
108
+
109
+ worksheet4.filter_column('A', 'x eq East')
110
+ worksheet4.filter_column('C', 'x > 3000 and x < 8000')
111
+
112
+ #
113
+ # Hide the rows that don't match the filter criteria.
114
+ #
115
+ row = 1
116
+
117
+ data.each do |row_data|
118
+ region = row_data[0]
119
+ volume = row_data[2]
120
+
121
+ unless region == 'East' && volume.to_i > 3000 && volume.to_i < 8000
122
+ # Hide row.
123
+ worksheet4.set_row(row, nil, nil, 1)
124
+ end
125
+
126
+ worksheet4.write(row, 0, row_data)
127
+ row += 1
128
+ end
129
+
130
+
131
+ ###############################################################################
132
+ #
133
+ #
134
+ # Example 5. Autofilter with filter for blanks.
135
+ #
136
+
137
+ # Create a blank cell in our test data.
138
+ data[5][0] = ''
139
+
140
+ worksheet5.autofilter('A1:D51')
141
+ worksheet5.filter_column('A', 'x eq Blanks')
142
+
143
+ #
144
+ # Hide the rows that don't match the filter criteria.
145
+ #
146
+ row = 1
147
+
148
+ data.each do |row_data|
149
+ region = row_data[0]
150
+
151
+ worksheet5.set_row(row, nil, nil, 1) unless region == ''
152
+
153
+ worksheet5.write(row, 0, row_data)
154
+ row += 1
155
+ end
156
+
157
+
158
+ ###############################################################################
159
+ #
160
+ #
161
+ # Example 6. Autofilter with filter for non-blanks.
162
+ #
163
+
164
+
165
+ worksheet6.autofilter('A1:D51')
166
+ worksheet6.filter_column('A', 'x eq NonBlanks')
167
+
168
+ #
169
+ # Hide the rows that don't match the filter criteria.
170
+ #
171
+ row = 1
172
+
173
+ data.each do |row_data|
174
+ region = row_data[0]
175
+
176
+ worksheet6.set_row(row, nil, nil, 1) unless region != ''
177
+
178
+ worksheet6.write(row, 0, row_data)
179
+ row += 1
180
+ end
181
+
182
+ workbook.close
183
+
184
+ __END__
185
+ Region Item Volume Month
186
+ East Apple 9000 July
187
+ East Apple 5000 July
188
+ South Orange 9000 September
189
+ North Apple 2000 November
190
+ West Apple 9000 November
191
+ South Pear 7000 October
192
+ North Pear 9000 August
193
+ West Orange 1000 December
194
+ West Grape 1000 November
195
+ South Pear 10000 April
196
+ West Grape 6000 January
197
+ South Orange 3000 May
198
+ North Apple 3000 December
199
+ South Apple 7000 February
200
+ West Grape 1000 December
201
+ East Grape 8000 February
202
+ South Grape 10000 June
203
+ West Pear 7000 December
204
+ South Apple 2000 October
205
+ East Grape 7000 December
206
+ North Grape 6000 April
207
+ East Pear 8000 February
208
+ North Apple 7000 August
209
+ North Orange 7000 July
210
+ North Apple 6000 June
211
+ South Grape 8000 September
212
+ West Apple 3000 October
213
+ South Orange 10000 November
214
+ West Grape 4000 July
215
+ North Orange 5000 August
216
+ East Orange 1000 November
217
+ East Orange 4000 October
218
+ North Grape 5000 August
219
+ East Apple 1000 December
220
+ South Apple 10000 March
221
+ East Grape 7000 October
222
+ West Grape 1000 September
223
+ East Grape 10000 October
224
+ South Orange 8000 March
225
+ North Apple 4000 July
226
+ South Orange 5000 July
227
+ West Apple 4000 June
228
+ East Apple 5000 April
229
+ North Pear 3000 August
230
+ East Grape 9000 November
231
+ North Orange 8000 October
232
+ East Apple 10000 June
233
+ South Pear 1000 December
234
+ North Grape 10000 July
235
+ East Grape 6000 February