ricardoo27-writeexcel 0.6.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. data/.document +5 -0
  2. data/.gitattributes +1 -0
  3. data/README.rdoc +136 -0
  4. data/Rakefile +52 -0
  5. data/VERSION +1 -0
  6. data/charts/chartex.rb +316 -0
  7. data/charts/demo1.rb +46 -0
  8. data/charts/demo101.bin +0 -0
  9. data/charts/demo2.rb +65 -0
  10. data/charts/demo201.bin +0 -0
  11. data/charts/demo3.rb +117 -0
  12. data/charts/demo301.bin +0 -0
  13. data/charts/demo4.rb +119 -0
  14. data/charts/demo401.bin +0 -0
  15. data/charts/demo5.rb +48 -0
  16. data/charts/demo501.bin +0 -0
  17. data/examples/a_simple.rb +43 -0
  18. data/examples/autofilter.rb +265 -0
  19. data/examples/bigfile.rb +30 -0
  20. data/examples/chart_area.rb +121 -0
  21. data/examples/chart_bar.rb +120 -0
  22. data/examples/chart_column.rb +120 -0
  23. data/examples/chart_line.rb +120 -0
  24. data/examples/chart_pie.rb +108 -0
  25. data/examples/chart_scatter.rb +121 -0
  26. data/examples/chart_stock.rb +148 -0
  27. data/examples/chess.rb +142 -0
  28. data/examples/colors.rb +129 -0
  29. data/examples/comments1.rb +27 -0
  30. data/examples/comments2.rb +352 -0
  31. data/examples/copyformat.rb +52 -0
  32. data/examples/data_validate.rb +279 -0
  33. data/examples/date_time.rb +87 -0
  34. data/examples/defined_name.rb +32 -0
  35. data/examples/demo.rb +124 -0
  36. data/examples/diag_border.rb +36 -0
  37. data/examples/formats.rb +490 -0
  38. data/examples/formula_result.rb +30 -0
  39. data/examples/header.rb +137 -0
  40. data/examples/hide_sheet.rb +29 -0
  41. data/examples/hyperlink.rb +43 -0
  42. data/examples/images.rb +63 -0
  43. data/examples/indent.rb +31 -0
  44. data/examples/merge1.rb +40 -0
  45. data/examples/merge2.rb +45 -0
  46. data/examples/merge3.rb +66 -0
  47. data/examples/merge4.rb +83 -0
  48. data/examples/merge5.rb +80 -0
  49. data/examples/merge6.rb +67 -0
  50. data/examples/outline.rb +255 -0
  51. data/examples/outline_collapsed.rb +209 -0
  52. data/examples/panes.rb +113 -0
  53. data/examples/password_protection.rb +33 -0
  54. data/examples/properties.rb +34 -0
  55. data/examples/properties_jp.rb +33 -0
  56. data/examples/protection.rb +47 -0
  57. data/examples/regions.rb +53 -0
  58. data/examples/repeat.rb +43 -0
  59. data/examples/republic.png +0 -0
  60. data/examples/right_to_left.rb +27 -0
  61. data/examples/row_wrap.rb +53 -0
  62. data/examples/set_first_sheet.rb +14 -0
  63. data/examples/stats.rb +74 -0
  64. data/examples/stocks.rb +81 -0
  65. data/examples/store_formula.rb +15 -0
  66. data/examples/tab_colors.rb +31 -0
  67. data/examples/utf8.rb +15 -0
  68. data/examples/write_arrays.rb +83 -0
  69. data/html/en/doc_en.html +5946 -0
  70. data/html/images/a_simple.jpg +0 -0
  71. data/html/images/area1.jpg +0 -0
  72. data/html/images/bar1.jpg +0 -0
  73. data/html/images/chart_area.xls +0 -0
  74. data/html/images/column1.jpg +0 -0
  75. data/html/images/data_validation.jpg +0 -0
  76. data/html/images/line1.jpg +0 -0
  77. data/html/images/pie1.jpg +0 -0
  78. data/html/images/regions.jpg +0 -0
  79. data/html/images/scatter1.jpg +0 -0
  80. data/html/images/stats.jpg +0 -0
  81. data/html/images/stock1.jpg +0 -0
  82. data/html/images/stocks.jpg +0 -0
  83. data/html/index.html +16 -0
  84. data/html/style.css +433 -0
  85. data/lib/writeexcel.rb +1159 -0
  86. data/lib/writeexcel/biffwriter.rb +223 -0
  87. data/lib/writeexcel/caller_info.rb +12 -0
  88. data/lib/writeexcel/cell_range.rb +332 -0
  89. data/lib/writeexcel/chart.rb +1968 -0
  90. data/lib/writeexcel/charts/area.rb +154 -0
  91. data/lib/writeexcel/charts/bar.rb +177 -0
  92. data/lib/writeexcel/charts/column.rb +156 -0
  93. data/lib/writeexcel/charts/external.rb +66 -0
  94. data/lib/writeexcel/charts/line.rb +154 -0
  95. data/lib/writeexcel/charts/pie.rb +169 -0
  96. data/lib/writeexcel/charts/scatter.rb +192 -0
  97. data/lib/writeexcel/charts/stock.rb +213 -0
  98. data/lib/writeexcel/col_info.rb +87 -0
  99. data/lib/writeexcel/colors.rb +68 -0
  100. data/lib/writeexcel/comments.rb +460 -0
  101. data/lib/writeexcel/compatibility.rb +65 -0
  102. data/lib/writeexcel/convert_date_time.rb +117 -0
  103. data/lib/writeexcel/data_validations.rb +370 -0
  104. data/lib/writeexcel/debug_info.rb +41 -0
  105. data/lib/writeexcel/embedded_chart.rb +35 -0
  106. data/lib/writeexcel/excelformula.y +139 -0
  107. data/lib/writeexcel/excelformulaparser.rb +587 -0
  108. data/lib/writeexcel/format.rb +1575 -0
  109. data/lib/writeexcel/formula.rb +987 -0
  110. data/lib/writeexcel/helper.rb +78 -0
  111. data/lib/writeexcel/image.rb +218 -0
  112. data/lib/writeexcel/olewriter.rb +305 -0
  113. data/lib/writeexcel/outline.rb +24 -0
  114. data/lib/writeexcel/properties.rb +242 -0
  115. data/lib/writeexcel/shared_string_table.rb +153 -0
  116. data/lib/writeexcel/storage_lite.rb +984 -0
  117. data/lib/writeexcel/workbook.rb +2478 -0
  118. data/lib/writeexcel/worksheet.rb +6925 -0
  119. data/lib/writeexcel/worksheets.rb +25 -0
  120. data/lib/writeexcel/write_file.rb +63 -0
  121. data/test/excelfile/Chart1.xls +0 -0
  122. data/test/excelfile/Chart2.xls +0 -0
  123. data/test/excelfile/Chart3.xls +0 -0
  124. data/test/excelfile/Chart4.xls +0 -0
  125. data/test/excelfile/Chart5.xls +0 -0
  126. data/test/helper.rb +31 -0
  127. data/test/perl_output/Chart1.xls.data +0 -0
  128. data/test/perl_output/Chart2.xls.data +0 -0
  129. data/test/perl_output/Chart3.xls.data +0 -0
  130. data/test/perl_output/Chart4.xls.data +0 -0
  131. data/test/perl_output/Chart5.xls.data +0 -0
  132. data/test/perl_output/README +31 -0
  133. data/test/perl_output/a_simple.xls +0 -0
  134. data/test/perl_output/autofilter.xls +0 -0
  135. data/test/perl_output/biff_add_continue_testdata +0 -0
  136. data/test/perl_output/chart_area.xls +0 -0
  137. data/test/perl_output/chart_bar.xls +0 -0
  138. data/test/perl_output/chart_column.xls +0 -0
  139. data/test/perl_output/chart_line.xls +0 -0
  140. data/test/perl_output/chess.xls +0 -0
  141. data/test/perl_output/colors.xls +0 -0
  142. data/test/perl_output/comments0.xls +0 -0
  143. data/test/perl_output/comments1.xls +0 -0
  144. data/test/perl_output/comments2.xls +0 -0
  145. data/test/perl_output/data_validate.xls +0 -0
  146. data/test/perl_output/date_time.xls +0 -0
  147. data/test/perl_output/defined_name.xls +0 -0
  148. data/test/perl_output/demo.xls +0 -0
  149. data/test/perl_output/demo101.bin +0 -0
  150. data/test/perl_output/demo201.bin +0 -0
  151. data/test/perl_output/demo301.bin +0 -0
  152. data/test/perl_output/demo401.bin +0 -0
  153. data/test/perl_output/demo501.bin +0 -0
  154. data/test/perl_output/diag_border.xls +0 -0
  155. data/test/perl_output/f_font_biff +0 -0
  156. data/test/perl_output/f_font_key +1 -0
  157. data/test/perl_output/f_xf_biff +0 -0
  158. data/test/perl_output/file_font_biff +0 -0
  159. data/test/perl_output/file_font_key +1 -0
  160. data/test/perl_output/file_xf_biff +0 -0
  161. data/test/perl_output/formula_result.xls +0 -0
  162. data/test/perl_output/headers.xls +0 -0
  163. data/test/perl_output/hidden.xls +0 -0
  164. data/test/perl_output/hide_zero.xls +0 -0
  165. data/test/perl_output/hyperlink.xls +0 -0
  166. data/test/perl_output/images.xls +0 -0
  167. data/test/perl_output/indent.xls +0 -0
  168. data/test/perl_output/merge1.xls +0 -0
  169. data/test/perl_output/merge2.xls +0 -0
  170. data/test/perl_output/merge3.xls +0 -0
  171. data/test/perl_output/merge4.xls +0 -0
  172. data/test/perl_output/merge5.xls +0 -0
  173. data/test/perl_output/merge6.xls +0 -0
  174. data/test/perl_output/ole_write_header +0 -0
  175. data/test/perl_output/outline.xls +0 -0
  176. data/test/perl_output/outline_collapsed.xls +0 -0
  177. data/test/perl_output/panes.xls +0 -0
  178. data/test/perl_output/password_protection.xls +0 -0
  179. data/test/perl_output/protection.xls +0 -0
  180. data/test/perl_output/regions.xls +0 -0
  181. data/test/perl_output/right_to_left.xls +0 -0
  182. data/test/perl_output/set_first_sheet.xls +0 -0
  183. data/test/perl_output/stats.xls +0 -0
  184. data/test/perl_output/stocks.xls +0 -0
  185. data/test/perl_output/store_formula.xls +0 -0
  186. data/test/perl_output/tab_colors.xls +0 -0
  187. data/test/perl_output/unicode_cyrillic.xls +0 -0
  188. data/test/perl_output/utf8.xls +0 -0
  189. data/test/perl_output/workbook1.xls +0 -0
  190. data/test/perl_output/workbook2.xls +0 -0
  191. data/test/perl_output/ws_colinfo +1 -0
  192. data/test/perl_output/ws_store_colinfo +0 -0
  193. data/test/perl_output/ws_store_dimensions +0 -0
  194. data/test/perl_output/ws_store_filtermode +0 -0
  195. data/test/perl_output/ws_store_filtermode_off +0 -0
  196. data/test/perl_output/ws_store_filtermode_on +0 -0
  197. data/test/perl_output/ws_store_selection +0 -0
  198. data/test/perl_output/ws_store_window2 +1 -0
  199. data/test/republic.png +0 -0
  200. data/test/test_00_IEEE_double.rb +13 -0
  201. data/test/test_01_add_worksheet.rb +10 -0
  202. data/test/test_02_merge_formats.rb +49 -0
  203. data/test/test_04_dimensions.rb +388 -0
  204. data/test/test_05_rows.rb +175 -0
  205. data/test/test_06_extsst.rb +74 -0
  206. data/test/test_11_date_time.rb +475 -0
  207. data/test/test_12_date_only.rb +525 -0
  208. data/test/test_13_date_seconds.rb +477 -0
  209. data/test/test_21_escher.rb +624 -0
  210. data/test/test_22_mso_drawing_group.rb +741 -0
  211. data/test/test_23_note.rb +57 -0
  212. data/test/test_24_txo.rb +74 -0
  213. data/test/test_25_position_object.rb +80 -0
  214. data/test/test_26_autofilter.rb +309 -0
  215. data/test/test_27_autofilter.rb +126 -0
  216. data/test/test_28_autofilter.rb +156 -0
  217. data/test/test_29_process_jpg.rb +670 -0
  218. data/test/test_30_validation_dval.rb +74 -0
  219. data/test/test_31_validation_dv_strings.rb +123 -0
  220. data/test/test_32_validation_dv_formula.rb +203 -0
  221. data/test/test_40_property_types.rb +188 -0
  222. data/test/test_41_properties.rb +235 -0
  223. data/test/test_42_set_properties.rb +434 -0
  224. data/test/test_50_name_stored.rb +295 -0
  225. data/test/test_51_name_print_area.rb +353 -0
  226. data/test/test_52_name_print_titles.rb +450 -0
  227. data/test/test_53_autofilter.rb +199 -0
  228. data/test/test_60_chart_generic.rb +574 -0
  229. data/test/test_61_chart_subclasses.rb +84 -0
  230. data/test/test_62_chart_formats.rb +268 -0
  231. data/test/test_63_chart_area_formats.rb +645 -0
  232. data/test/test_biff.rb +71 -0
  233. data/test/test_big_workbook.rb +17 -0
  234. data/test/test_compatibility.rb +12 -0
  235. data/test/test_example_match.rb +3246 -0
  236. data/test/test_format.rb +1189 -0
  237. data/test/test_formula.rb +61 -0
  238. data/test/test_ole.rb +102 -0
  239. data/test/test_storage_lite.rb +116 -0
  240. data/test/test_workbook.rb +146 -0
  241. data/test/test_worksheet.rb +106 -0
  242. data/utils/add_magic_comment.rb +80 -0
  243. data/writeexcel.gemspec +278 -0
  244. data/writeexcel.rdoc +1425 -0
  245. metadata +292 -0
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+ require 'stringio'
4
+ #
5
+ # magic commentを付与する
6
+ #
7
+
8
+ # カレントディレクトリ以下の.rbファイルパスの配列を返す
9
+ def rb_files
10
+ Dir.glob("./**/*\.rb")
11
+ end
12
+
13
+ # カレントディレクトリ以下の.orgファイルパスの配列を返す
14
+ def org_files
15
+ Dir.glob("./**/*\.org")
16
+ end
17
+
18
+ # ファイル名を*.orgに変更し、変更後のファイル名を返す
19
+ def rename_to_org(file)
20
+ orgfile = change_ext_name(file, 'org')
21
+ File.rename(file, orgfile)
22
+ orgfile
23
+ end
24
+
25
+ # ファイル名の拡張子を変更した際のフルパスを返す(実際の変更はしない)
26
+ def change_ext_name(file, new_ext)
27
+ File.join(File.dirname(file), File.basename(file, ".*")) + ".#{new_ext}"
28
+ end
29
+
30
+ # shebang か
31
+ def shebang?(line)
32
+ line =~ /^#!.*ruby/ ? true : false
33
+ end
34
+
35
+ # magic_comment か
36
+ def magic_comment?(line)
37
+ line =~ /coding[:=]\s*[\w.-]+/ ? true : false
38
+ end
39
+
40
+ def add_magic_comment(input = nil, output = nil)
41
+ input ||= STDIN
42
+ output ||= STDOUT
43
+
44
+ magic_comment = "# -*- coding: utf-8 -*-\n"
45
+ if shebang?(line = input.gets)
46
+ output.write(line)
47
+ if magic_comment?(line = input.gets)
48
+ output.write(line)
49
+ else
50
+ output.write(magic_comment)
51
+ output.write(line)
52
+ end
53
+ elsif magic_comment?(line)
54
+ output.write(line)
55
+ else
56
+ output.write(magic_comment)
57
+ output.write(line)
58
+ end
59
+ while(line = input.gets)
60
+ output.write(line)
61
+ end
62
+ end
63
+
64
+ if $0 == __FILE__
65
+
66
+ rb_files.each do |file|
67
+ orgfile = rename_to_org(file)
68
+ print("#{file}: renamed to #{orgfile}.\n")
69
+ io = StringIO.new
70
+ File.open(orgfile) do |fin|
71
+ File.open(file, 'w') { |fout| add_magic_comment(fin, fout) }
72
+ end
73
+ print("#{file}: contains magic comment.\n")
74
+ end
75
+ #
76
+ # orgファイルをすべて消すには、以下を有効に。
77
+ #
78
+ org_files.each { |f| File.unlink(f) }
79
+
80
+ end
@@ -0,0 +1,278 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "ricardoo27-writeexcel"
8
+ s.version = "0.6.12.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Hideo NAKAMURA","ricardoo27"]
12
+ s.date = "2012-02-17"
13
+ s.description = "Forked from original writeexcel gem. Multiple worksheets can be added to a workbook and formatting can be applied to cells. Text, numbers, formulas, hyperlinks and images can be written to the cells."
14
+ s.email = ""
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".gitattributes",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "charts/chartex.rb",
25
+ "charts/demo1.rb",
26
+ "charts/demo101.bin",
27
+ "charts/demo2.rb",
28
+ "charts/demo201.bin",
29
+ "charts/demo3.rb",
30
+ "charts/demo301.bin",
31
+ "charts/demo4.rb",
32
+ "charts/demo401.bin",
33
+ "charts/demo5.rb",
34
+ "charts/demo501.bin",
35
+ "examples/a_simple.rb",
36
+ "examples/autofilter.rb",
37
+ "examples/bigfile.rb",
38
+ "examples/chart_area.rb",
39
+ "examples/chart_bar.rb",
40
+ "examples/chart_column.rb",
41
+ "examples/chart_line.rb",
42
+ "examples/chart_pie.rb",
43
+ "examples/chart_scatter.rb",
44
+ "examples/chart_stock.rb",
45
+ "examples/chess.rb",
46
+ "examples/colors.rb",
47
+ "examples/comments1.rb",
48
+ "examples/comments2.rb",
49
+ "examples/copyformat.rb",
50
+ "examples/data_validate.rb",
51
+ "examples/date_time.rb",
52
+ "examples/defined_name.rb",
53
+ "examples/demo.rb",
54
+ "examples/diag_border.rb",
55
+ "examples/formats.rb",
56
+ "examples/formula_result.rb",
57
+ "examples/header.rb",
58
+ "examples/hide_sheet.rb",
59
+ "examples/hyperlink.rb",
60
+ "examples/images.rb",
61
+ "examples/indent.rb",
62
+ "examples/merge1.rb",
63
+ "examples/merge2.rb",
64
+ "examples/merge3.rb",
65
+ "examples/merge4.rb",
66
+ "examples/merge5.rb",
67
+ "examples/merge6.rb",
68
+ "examples/outline.rb",
69
+ "examples/outline_collapsed.rb",
70
+ "examples/panes.rb",
71
+ "examples/password_protection.rb",
72
+ "examples/properties.rb",
73
+ "examples/properties_jp.rb",
74
+ "examples/protection.rb",
75
+ "examples/regions.rb",
76
+ "examples/repeat.rb",
77
+ "examples/republic.png",
78
+ "examples/right_to_left.rb",
79
+ "examples/row_wrap.rb",
80
+ "examples/set_first_sheet.rb",
81
+ "examples/stats.rb",
82
+ "examples/stocks.rb",
83
+ "examples/store_formula.rb",
84
+ "examples/tab_colors.rb",
85
+ "examples/utf8.rb",
86
+ "examples/write_arrays.rb",
87
+ "html/en/doc_en.html",
88
+ "html/images/a_simple.jpg",
89
+ "html/images/area1.jpg",
90
+ "html/images/bar1.jpg",
91
+ "html/images/chart_area.xls",
92
+ "html/images/column1.jpg",
93
+ "html/images/data_validation.jpg",
94
+ "html/images/line1.jpg",
95
+ "html/images/pie1.jpg",
96
+ "html/images/regions.jpg",
97
+ "html/images/scatter1.jpg",
98
+ "html/images/stats.jpg",
99
+ "html/images/stock1.jpg",
100
+ "html/images/stocks.jpg",
101
+ "html/index.html",
102
+ "html/style.css",
103
+ "lib/writeexcel.rb",
104
+ "lib/writeexcel/biffwriter.rb",
105
+ "lib/writeexcel/caller_info.rb",
106
+ "lib/writeexcel/cell_range.rb",
107
+ "lib/writeexcel/chart.rb",
108
+ "lib/writeexcel/charts/area.rb",
109
+ "lib/writeexcel/charts/bar.rb",
110
+ "lib/writeexcel/charts/column.rb",
111
+ "lib/writeexcel/charts/external.rb",
112
+ "lib/writeexcel/charts/line.rb",
113
+ "lib/writeexcel/charts/pie.rb",
114
+ "lib/writeexcel/charts/scatter.rb",
115
+ "lib/writeexcel/charts/stock.rb",
116
+ "lib/writeexcel/col_info.rb",
117
+ "lib/writeexcel/colors.rb",
118
+ "lib/writeexcel/comments.rb",
119
+ "lib/writeexcel/compatibility.rb",
120
+ "lib/writeexcel/convert_date_time.rb",
121
+ "lib/writeexcel/data_validations.rb",
122
+ "lib/writeexcel/debug_info.rb",
123
+ "lib/writeexcel/embedded_chart.rb",
124
+ "lib/writeexcel/excelformula.y",
125
+ "lib/writeexcel/excelformulaparser.rb",
126
+ "lib/writeexcel/format.rb",
127
+ "lib/writeexcel/formula.rb",
128
+ "lib/writeexcel/helper.rb",
129
+ "lib/writeexcel/image.rb",
130
+ "lib/writeexcel/olewriter.rb",
131
+ "lib/writeexcel/outline.rb",
132
+ "lib/writeexcel/properties.rb",
133
+ "lib/writeexcel/shared_string_table.rb",
134
+ "lib/writeexcel/storage_lite.rb",
135
+ "lib/writeexcel/workbook.rb",
136
+ "lib/writeexcel/worksheet.rb",
137
+ "lib/writeexcel/worksheets.rb",
138
+ "lib/writeexcel/write_file.rb",
139
+ "test/excelfile/Chart1.xls",
140
+ "test/excelfile/Chart2.xls",
141
+ "test/excelfile/Chart3.xls",
142
+ "test/excelfile/Chart4.xls",
143
+ "test/excelfile/Chart5.xls",
144
+ "test/helper.rb",
145
+ "test/perl_output/Chart1.xls.data",
146
+ "test/perl_output/Chart2.xls.data",
147
+ "test/perl_output/Chart3.xls.data",
148
+ "test/perl_output/Chart4.xls.data",
149
+ "test/perl_output/Chart5.xls.data",
150
+ "test/perl_output/README",
151
+ "test/perl_output/a_simple.xls",
152
+ "test/perl_output/autofilter.xls",
153
+ "test/perl_output/biff_add_continue_testdata",
154
+ "test/perl_output/chart_area.xls",
155
+ "test/perl_output/chart_bar.xls",
156
+ "test/perl_output/chart_column.xls",
157
+ "test/perl_output/chart_line.xls",
158
+ "test/perl_output/chess.xls",
159
+ "test/perl_output/colors.xls",
160
+ "test/perl_output/comments0.xls",
161
+ "test/perl_output/comments1.xls",
162
+ "test/perl_output/comments2.xls",
163
+ "test/perl_output/data_validate.xls",
164
+ "test/perl_output/date_time.xls",
165
+ "test/perl_output/defined_name.xls",
166
+ "test/perl_output/demo.xls",
167
+ "test/perl_output/demo101.bin",
168
+ "test/perl_output/demo201.bin",
169
+ "test/perl_output/demo301.bin",
170
+ "test/perl_output/demo401.bin",
171
+ "test/perl_output/demo501.bin",
172
+ "test/perl_output/diag_border.xls",
173
+ "test/perl_output/f_font_biff",
174
+ "test/perl_output/f_font_key",
175
+ "test/perl_output/f_xf_biff",
176
+ "test/perl_output/file_font_biff",
177
+ "test/perl_output/file_font_key",
178
+ "test/perl_output/file_xf_biff",
179
+ "test/perl_output/formula_result.xls",
180
+ "test/perl_output/headers.xls",
181
+ "test/perl_output/hidden.xls",
182
+ "test/perl_output/hide_zero.xls",
183
+ "test/perl_output/hyperlink.xls",
184
+ "test/perl_output/images.xls",
185
+ "test/perl_output/indent.xls",
186
+ "test/perl_output/merge1.xls",
187
+ "test/perl_output/merge2.xls",
188
+ "test/perl_output/merge3.xls",
189
+ "test/perl_output/merge4.xls",
190
+ "test/perl_output/merge5.xls",
191
+ "test/perl_output/merge6.xls",
192
+ "test/perl_output/ole_write_header",
193
+ "test/perl_output/outline.xls",
194
+ "test/perl_output/outline_collapsed.xls",
195
+ "test/perl_output/panes.xls",
196
+ "test/perl_output/password_protection.xls",
197
+ "test/perl_output/protection.xls",
198
+ "test/perl_output/regions.xls",
199
+ "test/perl_output/right_to_left.xls",
200
+ "test/perl_output/set_first_sheet.xls",
201
+ "test/perl_output/stats.xls",
202
+ "test/perl_output/stocks.xls",
203
+ "test/perl_output/store_formula.xls",
204
+ "test/perl_output/tab_colors.xls",
205
+ "test/perl_output/unicode_cyrillic.xls",
206
+ "test/perl_output/utf8.xls",
207
+ "test/perl_output/workbook1.xls",
208
+ "test/perl_output/workbook2.xls",
209
+ "test/perl_output/ws_colinfo",
210
+ "test/perl_output/ws_store_colinfo",
211
+ "test/perl_output/ws_store_dimensions",
212
+ "test/perl_output/ws_store_filtermode",
213
+ "test/perl_output/ws_store_filtermode_off",
214
+ "test/perl_output/ws_store_filtermode_on",
215
+ "test/perl_output/ws_store_selection",
216
+ "test/perl_output/ws_store_window2",
217
+ "test/republic.png",
218
+ "test/test_00_IEEE_double.rb",
219
+ "test/test_01_add_worksheet.rb",
220
+ "test/test_02_merge_formats.rb",
221
+ "test/test_04_dimensions.rb",
222
+ "test/test_05_rows.rb",
223
+ "test/test_06_extsst.rb",
224
+ "test/test_11_date_time.rb",
225
+ "test/test_12_date_only.rb",
226
+ "test/test_13_date_seconds.rb",
227
+ "test/test_21_escher.rb",
228
+ "test/test_22_mso_drawing_group.rb",
229
+ "test/test_23_note.rb",
230
+ "test/test_24_txo.rb",
231
+ "test/test_25_position_object.rb",
232
+ "test/test_26_autofilter.rb",
233
+ "test/test_27_autofilter.rb",
234
+ "test/test_28_autofilter.rb",
235
+ "test/test_29_process_jpg.rb",
236
+ "test/test_30_validation_dval.rb",
237
+ "test/test_31_validation_dv_strings.rb",
238
+ "test/test_32_validation_dv_formula.rb",
239
+ "test/test_40_property_types.rb",
240
+ "test/test_41_properties.rb",
241
+ "test/test_42_set_properties.rb",
242
+ "test/test_50_name_stored.rb",
243
+ "test/test_51_name_print_area.rb",
244
+ "test/test_52_name_print_titles.rb",
245
+ "test/test_53_autofilter.rb",
246
+ "test/test_60_chart_generic.rb",
247
+ "test/test_61_chart_subclasses.rb",
248
+ "test/test_62_chart_formats.rb",
249
+ "test/test_63_chart_area_formats.rb",
250
+ "test/test_biff.rb",
251
+ "test/test_big_workbook.rb",
252
+ "test/test_compatibility.rb",
253
+ "test/test_example_match.rb",
254
+ "test/test_format.rb",
255
+ "test/test_formula.rb",
256
+ "test/test_ole.rb",
257
+ "test/test_storage_lite.rb",
258
+ "test/test_workbook.rb",
259
+ "test/test_worksheet.rb",
260
+ "utils/add_magic_comment.rb",
261
+ "writeexcel.gemspec",
262
+ "writeexcel.rdoc"
263
+ ]
264
+ s.homepage = "http://github.com/ricardoo27/writeexcel"
265
+ s.require_paths = ["lib"]
266
+ s.rubygems_version = "1.8.10"
267
+ s.summary = "Write to a cross-platform Excel binary file."
268
+
269
+ if s.respond_to? :specification_version then
270
+ s.specification_version = 3
271
+
272
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
273
+ else
274
+ end
275
+ else
276
+ end
277
+ end
278
+
@@ -0,0 +1,1425 @@
1
+ = 目次
2
+ 概要
3
+ 説明
4
+ クイックスタート
5
+ WORDBOOK メソッド
6
+ WORKSHEET メソッド
7
+ PAGE セットアップメソッド
8
+ セルフォーマッティング
9
+ 色の扱い
10
+ 日付、時刻の扱い
11
+ アウトライン、グルーピング
12
+ データの検証
13
+ 数式と関数
14
+
15
+ == 概要
16
+ 最初の Sheet に、文字列、書式付き文字列、数値、数式を書き込んだ ruby.xls を作成するには、
17
+ 次のようにします。
18
+
19
+ require 'writeexcel'
20
+
21
+ # エクセルワークブックオブジェクトを作成
22
+ workbook = WriteExcel.new('ruby.xls')
23
+
24
+ # シートを追加
25
+ worksheet = workbook.add_worksheet
26
+
27
+ # 書式を作成
28
+ format = workbook.add_format # Add a format
29
+ format.set_bold()
30
+ format.set_color('red')
31
+ format.set_align('center')
32
+
33
+ # 文字列を書式指定有りと無しの2形式で格納。行・桁でセルを指定。
34
+ col = row = 0
35
+ worksheet.write(row, col, 'Hi Excel!', format)
36
+ worksheet.write(1, col, 'Hi Excel!')
37
+
38
+ # 数値と数式を格納。A1形式でセルを指定。
39
+ worksheet.write('A3', 1.2345)
40
+ worksheet.write('A4', '=SIN(PI()/4)')
41
+
42
+ # 作成を完了し、エクセルファイルを書き出し。
43
+ workbook.close
44
+
45
+ == 説明
46
+
47
+ WriteExcelライブラリは、エクセルのバイナリファイルを作成することができます。プラットフォームを問いません。
48
+ 複数のワークシートを作成することができますし、セルの書式を設定することもできます。
49
+ テキスト、数値、数式、ハイパーリンク、画像、グラフを格納することが出来ます。
50
+
51
+ このライブラリで作成されるエクセルファイルは、エクセル97、2000、2002、2003、2007と互換性があります。
52
+
53
+ このライブラリはWindows、UNIX、マッキントッシュプラットフォームのほとんどで動作します。
54
+ 作成されたファイルは、LinuxやUNIXのスプレッドシートアプリケーションであるGnumericやOpenOffice.orgとも互換性があります。
55
+
56
+ このライブラリは、既存のエクセルファイルの編集には使うことができません。
57
+
58
+ このライブラリは、PerlのSpreadsheet::WriteexcelモジュールをRubyに移植したものです。
59
+ http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.37/
60
+
61
+ == クイックスタート
62
+
63
+ WriteExcelは、エクセルの機能へのできるだけ多くのインターフェイスを提供しようとしています。
64
+ 結果として、インターフェイスに関する多くのドキュメントがあります。最初はどれが重要でどれが
65
+ そうでないかわかりずらいでしょう。イケアの家具を組み立てるのが好みの人は、まずこの使用説明を読んでください。
66
+ 4つの簡単なステップです。
67
+
68
+ 1.new()メソッドで新規にエクセルのワークブックを作成する。
69
+ 2.add_worksheet()メソッドでこのワークブックにワークシートを加える。
70
+ 3.write()メソッドでこのワークシートにデータを書き込む。
71
+ 4.ファイルに保存する。
72
+
73
+ こんな感じです。
74
+
75
+ require 'writeexcel' # Step 0
76
+
77
+ workbook = WriteExcel.new('ruby.xls') # Step 1
78
+ worksheet = workbook.add_worksheet # Step 2
79
+ worksheet.write('A1', 'Hi Excel!') # Step 3
80
+ workbook.close # Step 4
81
+
82
+ これで、一つのワークシートを持ち、A1セルに'Hi Excel!'というテキストが書き込まれたエクセル
83
+ ファイル(ruby.xls)が作成されます。これでできあがりです。多くの使用例がgemには含まれていますので、
84
+ それを参考にすることも出来ます。
85
+
86
+ = Workbook メソッド
87
+
88
+ WriteExcel ライブラリは新規のワークブックへのオブジェクト指向のインターフェイスを提供します。新たなワークブックに対して次のメソッドを使用することが出来ます。
89
+
90
+ new
91
+ add_worksheet
92
+ add_format
93
+ add_chart
94
+ add_chart_ext
95
+ close
96
+ compatibility_mode
97
+ set_properties
98
+ set_tempdir
99
+ set_custom_color
100
+ sheets
101
+ set_1904
102
+ set_codepage
103
+
104
+ == new()
105
+
106
+ new コンストラクタは新しいエクセルワークブックを作成します。パラメータとしてファイル名かioオブジェクトを受け取ります。
107
+
108
+ workbook = WriteExcel.new('filename.xls')
109
+ worksheet = workbook.add_worksheet
110
+ worksheet.write(0, 0, 'Hi Excel!')
111
+
112
+ ※ また、デフォルトのフォーマットを指定することもできます。例えば、MSP ゴシックで11ポイントなど。
113
+
114
+ workbook = WriteExcel.new('filename.xls', :font => 'MSP ゴシック', :size = 11)
115
+
116
+ ファイル名を使った別の使用例です。
117
+
118
+ workbook = WriteExcel.new(filename)
119
+ workbook = WriteExcel.new('/tmp/filename.xls')
120
+ workbook = WriteExcel.new("c:\\tmp\\filename.xls")
121
+ workbook = WriteExcel.new('c:\tmp\filename.xls')
122
+
123
+ 最後の2つの例は、DOSやWindowsでディレクトリの区切りの「\」をエスケープするか、シングルクォートで囲んでそのまま指定していするかの例です。
124
+
125
+ new() コンストラクタは、WriteExcelオブジェクト(ワークブックオブジェクト)を返し、これにワークシートを加えデータを書き込みます。
126
+
127
+ == add_worksheet([sheetname])
128
+
129
+ ワークブックには少なくとも一つのワークシートを加える必要があります。ワークシートはセルにデータを記述するのに用いられます。
130
+
131
+ worksheet1 = workbook.add_worksheet # Sheet1
132
+ worksheet2 = workbook.add_worksheet('Foglio2') # Foglio2
133
+ worksheet3 = workbook.add_worksheet('Data') # Data
134
+ worksheet4 = workbook.add_worksheet # Sheet4
135
+
136
+ sheetname が指定されなければ、Sheet1, Sheet2といったデフォルトのエクセルの慣習に従います。
137
+
138
+ ワークシート名はエクセルのワークシート名として正しいものである必要があります。すなわち、[ ] : * ? / \ といった文字は使用できませんし、32文字以内でなければなりません。加えて、大文字小文字の別なく、同じシート名は使うことが出来ません。
139
+
140
+ シート名sheetnameには、UTF8文字列も使用することが出来ます。
141
+
142
+ worksheet = workbook.add_format('シート1') # UTF8でソースファイルを保存のこと
143
+
144
+ == add_format(properties)
145
+
146
+ add_format()メソッドは、セルに書式を設定するのに使用する新しいFormatオブジェクトを作成します。作成の際にpropertiesのハッシュ引数で指定することも出来ますし、後でメソッドを呼び出して指定することも出来ます。
147
+
148
+ format1 = workbook.add_format(props) # 作成時にプロパティをセットする
149
+ format2 = workbook.add_format # 後でプロパティをセットする
150
+
151
+ 書式プロパティの詳細及び指定方法については、CELL FORMATTING セクションをご覧ください。
152
+
153
+ == close()
154
+
155
+ ※ワークブックをエクセルファイルに書き出します。
156
+
157
+ == compatibility_mode()
158
+
159
+ ※未検証
160
+
161
+ == set_properties()
162
+
163
+ タイトル、作成者など文書のプロパティを設定する。これらプロパティは、エクセルで
164
+ メニューのファイル(F)-プロパティ(I)で見ることができ、他のアプリケーションから
165
+ 読んだり索引付けをすることもできる。
166
+
167
+ プロパティは、次のようにハッシュで渡す。
168
+
169
+ workbook.set_properties(
170
+ :title => 'This is an example spreadsheet',
171
+ :author => 'cxn03651',
172
+ :comments => 'Created with Ruby and WriteExcel'
173
+ )
174
+
175
+ 設定できるプロパティは、
176
+
177
+ * タイトル
178
+ * サブタイトル
179
+ * 作成者
180
+ * 管理者
181
+ * 会社名
182
+ * 分類
183
+ * キーワード
184
+ * コメント
185
+
186
+ ユーザー定義のプロパティはサポートしていません。
187
+
188
+ UTF-8文字列も渡すことができます。
189
+
190
+ workbook.set_properties(
191
+ :subject => "住所録"
192
+ )
193
+
194
+ 通常、WriteExcelはUTF-16の文字を使うことが出来るのですが、文書プロパティ
195
+ ではUTF-16文字はサポートされていません。
196
+
197
+ ルビーとWriteExcelの使い良さを広めるため、文書のプロパティをセットする時には、
198
+ 次のようにコメントをセットしましょう。
199
+
200
+ workbook.set_properties(
201
+ ...,
202
+ :comments => 'Created with Ruby and WriteExcel',
203
+ ...,
204
+ )
205
+
206
+ examples内のproperties.rbプログラムもご覧下さい。
207
+
208
+ == set_tempdir()
209
+
210
+ 速度と効率のため、ワークブックのデータを最後に組み立てる前に、WriteExcelはワークシートのデータをテンポラリファイルに置きます。テンポラリファイルを作ることが出来ない場合はメモリ上で作業します。この場合、大きなファイルになると遅くなることがあります。
211
+ この問題はWindows上でIISと併せて使っているときに主として発生しますが、UNIXシステムでも起こることがあります。
212
+ この問題は概して、既定の一時ファイルディレクトリがC:\やその他IISが書き込みを提供していないディレクトリに設定されているのが原因で発生します。
213
+ この問題を避けるために、set_tempdir()メソッドを使って一時ファイルを作成できるディレクトリを指定します。
214
+
215
+ お使いのシステムでどのディレクトリが使用されるかは、以下で知ることが出来ます。
216
+
217
+ ruby -e "print ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'"
218
+
219
+ デフォルトの一時ファイルディレクトリは使用できる場合でも、セキュリティやメンテナンスの理由から別の場所を指定することもできます。
220
+
221
+ workbook.set_tempdir('/tmp/writeexcel')
222
+ workbook.set_tempdir('c:\windows\temp\writeexcel')
223
+
224
+ この一時ファイル用のディレクトリは実在しなければなりません。set_tempdir()が新たにディレクトリを作成することはしません。
225
+
226
+ set_tempdir()を使う一つの欠点は、Windowsシステムの中にはおおよそ800のコンカレント一時ファイルを限度としているのがあることです。これらのシステムで動かす単一のプログラムは総計で800のワークブックとワークシートオブジェクトを作成するのが上限となります。必要なら複数の、ノン・コンカレントなプログラムを実行してください。
227
+
228
+ == set_custom_color(index, red, green, ble)
229
+
230
+ set_custom_color()メソッドは、ビルトインされているパレットの値に、もう少し好みの色を加えるのに使用します。
231
+ index の値は、8から63の間でなければなりません。See "COLOURS IN EXCEL"
232
+ デフォルトの名前付きカラーは次のようになっています。
233
+
234
+ 8 => black
235
+ 9 => white
236
+ 10 => red
237
+ 11 => lime
238
+ 12 => blue
239
+ 13 => yellow
240
+ 14 => magenta
241
+ 15 => cyan
242
+ 16 => brown
243
+ 17 => green
244
+ 18 => navy
245
+ 20 => purple
246
+ 22 => silver
247
+ 23 => gray
248
+ 33 => pink
249
+ 53 => orange
250
+
251
+ RGB(red green blue)要素を用いて新しい色をセットすることも出来ます。red, green, blue の各値は0から255までの間でなければなりません。エクセルを使ってTools(ツール)->Options(オプション)->Colors(色)->Modify(変更)で必要な値を決めることが出来ます。
252
+
253
+ set_custom_color()メソッドでは、HTMLで用いられる#rrggbb形式の16進数値も使用できます。
254
+
255
+ workbook.set_custom_color(40, 255, 102, 0) # orange
256
+ workbook.set_custom_color(40, 0xFF, 0x66, 0x00) # same thing
257
+ workbook.set_custom_color(40, '#FF6600') # same thing
258
+
259
+ font = workbook.add_format(:color => 40) # use the modified color
260
+
261
+ set_custom_color()は作成された色のindexを返します。
262
+
263
+ ferrari = workbook.set_custom_color(40, 216, 12, 12)
264
+ format = workbook.add_format(
265
+ :bg_color => ferrari,
266
+ :pattern => 1,
267
+ :border => 1
268
+ )
269
+
270
+ == sheets([0, 1, ...])
271
+
272
+ sheets()メソッドはワークブック内のワークシートの全リストあるいは指定されたシートのリストを返します。
273
+ 引数を指定しなければ全てのシートのリストを返します。これはそれぞれのシートに、ある操作を繰り返して行いたいときに便利です。
274
+
275
+ workbook.sheets.each do |worksheet|
276
+ print $worksheet.get_name
277
+ end
278
+
279
+ 一つあるいは複数のワークシートオブジェクトを指定することもできます。
280
+
281
+ worksheet = workbook.sheets(0)
282
+ worksheet.write('A1', 'Hello')
283
+
284
+ workbook.sheets(0).write('A1', 'Hello') # same thing
285
+
286
+ 次の例は、ワークブック内の最初と最後のワークシートを返し、操作します。
287
+
288
+ workbook.sheets(0, -1).each do |worksheet|
289
+ # Do something
290
+ end
291
+
292
+ == set_1904()
293
+
294
+ エクセルは日付を実数で格納しています。その整数部分は「epoch」からの日数を、小数部分は1日のうちのパーセンテージを格納しています。「epoch」は、Windowsのエクセルでは1900年、マッキントッシュのエクセルでは1904年です。ですが、どちらのプラットフォームでもエクセルは自動的にシステム間の相違をコンバートして扱います。
295
+
296
+ WriteExcelではデフォルトで1900年を用います。もしも変更したいのであれば、workbookに対してset_1904()メソッドを呼んでください。現在の値を問い合わせるにはget_1904()を呼びます。これは、1900ならば0を、1904ならば1を返します。
297
+
298
+ エクセルの日付の取り扱いについては、"DATES AND TIME IN EXCEL"も見てください。
299
+
300
+ 通常であれば、set_1904()を使う必要はありません。
301
+
302
+ == set_codepage(codepage)
303
+
304
+ WriteExcelで使われるデフォルトのコードページ、文字セットはANSIです。これはWindowsのエクセルの既定値でもあります。しかしながら、たまにコードページを変更する必要が生じたときは、set_codepage()メソッドを使って変更します。
305
+
306
+ コードページの変更は、マッキントッシュ上でWriteExcelを使用していて、ASCII 128以外の文字セットを使いたい場合に必要になることがあります。
307
+
308
+ workbook.set_codepage(1) # ANSI, MS Windows
309
+ workbook.set_codepage(2) # Apple Macintosh
310
+
311
+ set_codepage()はめったに必要にはなりません。
312
+
313
+ = Worksheet メソッド
314
+
315
+ ワークブックオブジェクトnのadd_worksheet()メソッドを呼ぶことで、新しいワークシートが作成されます。
316
+
317
+ worksheet1 = workbook.add_worksheet
318
+ worksheet2 = workbook.add_worksheet
319
+
320
+ このワークシートに対して、次のメソッドを使うことが出来ます。
321
+
322
+ write
323
+ write_number
324
+ write_string
325
+ write_utf16be_string
326
+ write_utf16le_string
327
+ keep_leading_zeros
328
+ write_blank
329
+ write_row
330
+ write_col
331
+ write_date_time
332
+ write_url
333
+ write_url_range
334
+ write_formula
335
+ store_formula
336
+ repeat_formula
337
+ write_comment
338
+ show_comments
339
+ add_write_handler
340
+ insert_image
341
+ insert_chart
342
+ data_validation
343
+ get_name
344
+ activate
345
+ select
346
+ hide
347
+ set_first_sheet
348
+ protect
349
+ set_selection
350
+ set_row
351
+ set_column
352
+ outline_settings
353
+ freeze_panes
354
+ split_panes
355
+ merge_range
356
+ set_zoom
357
+ right_to_left
358
+ hide_zero
359
+ set_tab_color
360
+ autofilter
361
+
362
+ == セル・ノーテーション
363
+
364
+ WriteExcelはセルの位置を指定するのに2つの表記法、Row-Column法とA1法をサポートしています。
365
+
366
+ Row-Column法は行、桁ともに0から始まるインデックスですが、A1法はエクセルで標準的に
367
+ 用いられる桁を示す英字と行を示す1から始まる数字からなる英数字の並びです。例えば、
368
+
369
+ (0, 0) # Row-Column 法
370
+ ('A1') # A1 法
371
+
372
+ (1999,29) # Row-Column 法
373
+ ('AD2000') # 同じセルを A1 法で
374
+
375
+ Row-column法はセルをプログラムで扱うのに便利です。
376
+
377
+ (0..10).each do |i|
378
+ worksheet.write(i, 0, 'Hello') # Cells A1 to A10
379
+ end
380
+
381
+ A1法はワークシートを手動で設定したりエクセルの数式で用いるときに便利です。
382
+
383
+ worksheet.write('H1', 200)
384
+ worksheet.write('H2', '=H1+1') # 201
385
+
386
+ 数式中やいくつかのメソッドでは、A:Aカラム法も使用できます。
387
+
388
+ worksheet.write('A1', '=SUM(B:B)')
389
+
390
+ 簡便さのために、以下のワークシートのメソッドではrow-column法で記述していますが、全てA1法も用いることができます。
391
+
392
+ 注:エクセルではR1C1法も使うことができますが、WriteExcelではサポートしていません。
393
+
394
+ == write(row, column, [token, format])
395
+
396
+ エクセルは、データのタイプ(文字列、数値、ブランク、数式、ハイパーリンク)によって区別して扱います。データの書き込みを簡単に扱うため、write()メソッドはいくつかのメソッドのエイリアスとして振る舞います。
397
+
398
+ write_string
399
+ write_number
400
+ write_blank
401
+ write_formula
402
+ write_url
403
+ write_row
404
+ write_col
405
+
406
+ 全般的な規則は、データが何かを見て、何を書き込むかを決めます。row-column法とA1法それぞれの例を示します。オリジナルのパール版では'1'や'2.5E-4'といった数値風
407
+ の文字列を書き込むと数値として扱われますが、ruby版では異なるので注意。
408
+
409
+ # same as
410
+ worksheet.write(0, 0, 'Hello' ) # write_string
411
+ worksheet.write(1, 0, '1' ) # write_string
412
+ worksheet.write(2, 0, 2 ) # write_number
413
+ worksheet.write(3, 0, 3.00001 ) # write_number
414
+ worksheet.write(4, 0, "" ) # write_blank
415
+ worksheet.write(5, 0, '' ) # write_blank
416
+ worksheet.write(6, 0, nil ) # write_blank
417
+ worksheet.write(7, 0 ) # write_blank
418
+ worksheet.write(8, 0, 'http://www.ruby-lang.org/') # write_url
419
+ worksheet.write('A9', 'ftp://ftp.ruby-lang.org/' ) # write_url
420
+ worksheet.write('A10', 'internal:Sheet1!A1' ) # write_url
421
+ worksheet.write('A11', 'external:c:\foo.xls' ) # write_url
422
+ worksheet.write('A12', '=A3 + 3*A4' ) # write_formula
423
+ worksheet.write('A13', '=SIN(PI()/4)' ) # write_formula
424
+ worksheet.write('A14', Array ) # write_row
425
+ worksheet.write('A15', [ Array ] ) # write_col
426
+
427
+ オリジナルのパール版にあるkeep_leading_zeros プロパティは無効です。
428
+ 0で始まる数字列を書き込むには、文字列にしてください。
429
+ 数値リテラルで0で始まる数値を書き込むときは、8進数に解釈される
430
+ ので気を付けてください。
431
+
432
+ worksheet.write('A16', 010 ) # write_number 8
433
+ worksheet.write('A17', '010' ) # write_string '010'
434
+ worksheet.write('A18', 000020 ) # write_number 16
435
+
436
+ Arrayを渡すときの挙動は以下の通り。
437
+
438
+ TODO 記述すること
439
+
440
+ 引数formatはオプションです。有効なFormatオブジェクトである必要があります。
441
+ "CELL FORMATTING"を参照。
442
+
443
+ format = workbook.add_format
444
+ format.set_bold
445
+ format.set_color('red')
446
+ format.set_align('center')
447
+ worksheet.write(4, 0, 'Hello', format) # formatted string
448
+
449
+ write()メソッドは空文字列''やnilがtokenとして渡された場合、formatが渡されなければ何もしません。つまり、上記の例では何もしない(無視する)ということです。ですから、空データやnilを扱うのに特別のことを気にする必要はありません。write_blank()メソッドも見てください。
450
+
451
+ add_write_handler()を使って、あなた独自のwrite()メソッドのデータ処理を加えることもできます。(※未検証)
452
+
453
+ UTF8文字列も扱うことが出来ます(※暫定実装)
454
+
455
+ write()メソッドは、次の値を返します。
456
+
457
+ 0 : 成功
458
+ -1 : 引数の数が不足
459
+ -2 : 行や桁が範囲外
460
+ -3 : 文字列が長すぎる(32767バイト以上)
461
+
462
+ == write_number(row, column, number[, format])
463
+
464
+ 指定されたセルに整数又は実数を書き込む。
465
+
466
+ worksheet.write_number(0, 0, 1234556)
467
+ worksheet.write_number('A2', 2.3456)
468
+
469
+ "Cell notation"も参照。formatはオプション。
470
+
471
+ 一般的にはwrite()メソッドを使えばこと足りる。
472
+
473
+ == write_string(row, column, string[, format])
474
+
475
+ 指定されたセルに文字列を書き込む。
476
+
477
+ worksheet.write_string(0, 0, 'Your text here')
478
+ worksheet.write_string('A2', 'or here')
479
+
480
+ 文字列の最大サイズは32767文字。
481
+
482
+ == write_blank(row, column, format)
483
+
484
+ 指定されたセルにブランクを書き込む。
485
+
486
+ worksheet.write_brank(0, 0, format)
487
+
488
+ このメソッドは、文字列も数値もないセルに書式を書き込むのに用いる。
489
+ エクセルでは空(Empty)セルとブランクセルとは異なる。空セルは何のデータも持たないが、ブランクセルは書式情報を持つ。
490
+
491
+ 書式情報を持たない書き込みは無視される。
492
+
493
+ worksheet.write('A1', nil, format) # write_blank('A1', format)
494
+ worksheet.write('A1', nil ) # ignored
495
+
496
+ すなわち、配列にある一連のデータを書き込む際に、nilあるいは空白のセルについて特別の扱いをしなくても良いと言うことである。
497
+
498
+ "Cell notation"も参照。
499
+
500
+ == write_row(row, column, array[, format])
501
+
502
+ write_row()メソッドは、1次元あるいは2次元配列を一度に書き込む際に使用できます。データベースからのクエリ結果をエクセルに書き込む際に便利です。
503
+ 実際は配列の各要素に対してwrite()メソッドを呼び出します。
504
+
505
+ array = ['awk', 'gawk', 'mawk']
506
+ worksheet.write_row(0, 0, array)
507
+
508
+ # この例は次と同じ
509
+ worksheet.write(0, 0, array[0])
510
+ worksheet.write(0, 1, array[1])
511
+ worksheet.write(0, 2, array[2])
512
+
513
+ 注記:利便さのため、配列を渡されたときはwrite()はwrite_row()と同様に振る舞います。ですから、次の二つの例は同じことです。
514
+
515
+ worksheet.write_row('A1', array) # write a row of data
516
+ worksheet.write( 'A1', array) # same thing
517
+
518
+ format引数はオプションです。指定された場合、全ての配列要素の書き込みに際し適用されます。
519
+
520
+ 2次元配列を渡すとこんな感じになります。
521
+
522
+ eec = [
523
+ ['maggie', 'milly', 'molly', 'may' ],
524
+ [13, 14, 15, 16 ],
525
+ ['shell', 'star', 'crab', 'stone']
526
+ ]
527
+
528
+ worksheet.write_row('A1', eec)
529
+
530
+ 以下のワークシートが作成されます。
531
+
532
+ -----------------------------------------------------------
533
+ | | A | B | C | D | E | ...
534
+ -----------------------------------------------------------
535
+ | 1 | maggie | 13 | shell | ... | ... | ...
536
+ | 2 | milly | 14 | star | ... | ... | ...
537
+ | 3 | molly | 15 | crab | ... | ... | ...
538
+ | 4 | may | 16 | stone | ... | ... | ...
539
+ | 5 | ... | ... | ... | ... | ... | ...
540
+ | 6 | ... | ... | ... | ... | ... | ...
541
+
542
+ 縦横を反転して作成するには、下のwrite_col()メソッドを使うか、write()メソッドで2次元配列の配列、[ eec ] を渡してください。
543
+
544
+ nil要素は、formatが指定されていなければ無視されますし、指定されていればブランクセルとして書き込まれます。
545
+
546
+ write_row()メソッドの返値は、無事に終われば0、何か問題があれば最初に発生したエラーコードを返します。上のwrite()に記載された返値を見てください。
547
+
548
+ examplesディレクトリにあるwrite_arrays.rbもご覧ください。
549
+
550
+ == write_col(row, column, array[, format])
551
+
552
+ write_col()メソッドは、1次元あるいは2次元配列を一度に書き込む際に使用できます。データベースからのクエリ結果をエクセルに書き込む際に便利です。
553
+ 実際は配列の各要素に対してwrite()メソッドを呼び出します。
554
+
555
+ array = ['awk', 'gawk', 'mawk']
556
+ worksheet.write_col(0, 0, array)
557
+
558
+ # この例は次と同じ
559
+ worksheet.write(0, 0, array[0])
560
+ worksheet.write(1, 0, array[1])
561
+ worksheet.write(2, 0, array[2])
562
+
563
+ format引数はオプションです。指定された場合、全ての配列要素の書き込みに際し適用されます。
564
+
565
+ 2次元配列を渡すとこんな感じになります。
566
+
567
+ eec = [
568
+ ['maggie', 'milly', 'molly', 'may' ],
569
+ [13, 14, 15, 16 ],
570
+ ['shell', 'star', 'crab', 'stone']
571
+ ]
572
+
573
+ worksheet.write_row('A1', eec)
574
+
575
+ 以下のワークシートが作成されます。
576
+
577
+ -----------------------------------------------------------
578
+ | | A | B | C | D | E | ...
579
+ -----------------------------------------------------------
580
+ | 1 | maggie | milly | molly | may | ... | ...
581
+ | 2 | 13 | 14 | 15 | 16 | ... | ...
582
+ | 3 | shell | star | crab | stone | ... | ...
583
+ | 4 | ... | ... | ... | ... | ... | ...
584
+ | 5 | ... | ... | ... | ... | ... | ...
585
+ | 6 | ... | ... | ... | ... | ... | ...
586
+
587
+ 縦横を反転して作成するには、上のwrite_col()メソッドを使うか、write()メソッドで2次元配列、eec を渡してください。
588
+
589
+ nil要素は、formatが指定されていなければ無視されますし、指定されていればブランクセルとして書き込まれます。
590
+
591
+ write_col()メソッドの返値は、無事に終われば0、何か問題があれば最初に発生したエラーコードを返します。上のwrite()に記載された返値を見てください。
592
+
593
+ examplesディレクトリにあるwrite_arrays.rbもご覧ください。
594
+
595
+ == write_date_time(row, column, date_string, format)
596
+
597
+ write_date_time()メソッドは、指定したセルに日付あるいは時刻を書き込みます。
598
+
599
+ worksheet.write_date_time('A1', '2009-03-25T12:30', date_format)
600
+
601
+ date_stringは次の形式です。
602
+
603
+ yyyy-mm-ddThh:mm:ss.sss
604
+
605
+ これはISO8601に適合していますが、ISO8601全てのフォーマットには適合していないことに留意してください。
606
+
607
+ date_stirngでは、次のバリエーションも使用できます。どの場合でも'T'は必要です。
608
+
609
+ yyyy-mm-ddThh:mm:ss.sss # standard format
610
+ yyyy-mm-ddT # No time
611
+ Thh:mm:ss.sss # No Date
612
+ yyyy-mm-ddThh:mm:ss.sssZ # Additional Z ( but not time zone)
613
+ yyyy-mm-ddThh:mm:ss # No fractal seconds
614
+ yyyy-mm-ddThh:mm # No seconds.
615
+
616
+ 日時には書式(format)が必要です。指定しなければ数値として書き込まれます。"DATES AND TIME IN EXCEL"及び"CELL FORMATTING"を参照ください。
617
+ 典型的な例です。
618
+
619
+ date_format = workbook.add_format(:num_format => 'mm/dd/yy')
620
+ worksheet.write_date_time('A1', '2009-03-25T12:30', date_format) # date
621
+ worksheet.write_date_time('A1', '2009-03-25T12:30' ) # number
622
+
623
+ 日付としては、epochが1900の場合は1900-01-01から9999-12-31まで、epochが1904の場合は1904-01-01から9999-12-31までです。この範囲外の時は文字列が書き込まれます。
624
+
625
+ examplesディレクトリにあるdate_time.rbもご覧ください。
626
+
627
+ == write_url(row, column, url[, label, format])
628
+
629
+ 指定されたセルにURLへのハイパーリンクを書き込みます。ハイパーリンクは、表示されるlabelと表示はされない実際のurlの2つからなります。labelが指定されない場合、urlが表示されます。labelとformatはオプションですし、その順番が入れ替わってもかまいません。
630
+
631
+ labelはwrite()メソッドで書き込まれます。ですから、書き込み可能な文字列、数値または数式でなければなりません。
632
+
633
+ URLの形式は4つ(http://, https://, ftp://, mailto:)をサポートしています。
634
+
635
+ worksheet.write_url(0, 0, 'ftp://www.ruby-lang.org/' )
636
+ worksheet.write_url(1, 0, 'http://www.ruby-lang.org/', 'Ruby home' )
637
+ worksheet.write_url('A3', 'http://www.ruby-lang.org/', format )
638
+ worksheet.write_url('A4', 'http://www.ruby-lang.org/', 'Perl', format)
639
+ worksheet.write_url('A5', 'mailto:foo@bar.com' )
640
+
641
+ このほか、ローカルリンクの2つ(internal:, external:)もサポートしています。これらは同じワークブック内のワークシートへ、あるいは他のワークブックへの参照に用います。
642
+
643
+ worksheet.write_url('A6', 'internal:Sheet2!A1' )
644
+ worksheet.write_url('A7', 'internal:Sheet2!A1', format )
645
+ worksheet.write_url('A8', 'internal:Sheet2!A1:B2' )
646
+ worksheet.write_url('A9', %q{internal:'Sales Data'!A1} )
647
+ worksheet.write_url('A10', 'external:c:\temp\foo.xls' )
648
+ worksheet.write_url('A11', 'external:c:\temp\foo.xls#Sheet2!A1' )
649
+ worksheet.write_url('A12', 'external:..\..\..\foo.xls' )
650
+ worksheet.write_url('A13', 'external:..\..\..\foo.xls#Sheet2!A1' )
651
+ worksheet.write_url('A14', 'external:\\\\NETWORK\share\foo.xls' )
652
+
653
+ これらのURLの形式はwrite()メソッドで自動的に認識されます。
654
+
655
+ ワークシートへの参照はSheet1!A1といった形式です。Sheet1!A1:B2といった範囲指定も使用できます。
656
+ 外部の参照の際、ワークブック名とワークシート名の間は#で区切る必要があります。 external:workbook.xls#Sheet1!A1
657
+
658
+ ※以下の名前付け範囲への対応は、未検証
659
+ 名前付けされた範囲へのリンクも張ることができます。例えば、外部のc:\temp\foo.xlsにあるmy_nameという名前の範囲へのリンクは、
660
+
661
+ worksheet.write_url('A15', 'external:c;\temp\foo.xls#my_name')
662
+
663
+ 注:現在のWriteExcelでは、名前付け範囲の設定は対応していません。
664
+
665
+ エクセルでは、シート名に空白や非英数字が含まれる場合、'Sales Data'!A1のようにクォートで囲む必要があります。この場合、シート名に含まれる文字は必要であればエスケープしてください。 'c:\temp' はダブルクォートでは"c:\\temp"とします。
666
+
667
+ DOSやWindowsであっても、ファイル名の区切りには'/'を使用することが出来ます。これで先ほどのエスケープの問題は回避することができます。
668
+
669
+ worksheet.write_url('A16', 'external:c:/temp/foo.xls')
670
+ worksheet.write_url('A16', 'external:c://NETWORK/share/foo.xls')
671
+
672
+ "Cell notation"も参照。
673
+
674
+ == write_formula(row, column, formula[, format, value])
675
+
676
+ 指定されたセルに数式あるいは関数を書き込みます。
677
+
678
+ worksheet.write_formula(0, 0, '=$B$3 + B4' )
679
+ worksheet.write_formula(1, 0, '=SIN(PI()/4)')
680
+ worksheet.write_formula(2, 0, '=SUM(B1:B5)' )
681
+ worksheet.write_formula('A4', '=IF(A3>1,"Yes","No")' )
682
+ worksheet.write_formula('A5', '=AVERAGE(1, 2, 3, 4)' )
683
+ worksheet.write_formula('A6', '=DATEVALUE("1-Jan-2001")')
684
+
685
+
686
+ == ページセットアップメソッド
687
+
688
+ 印刷されたときの書式設定ですね。ヘッダ・フッタやマージンなど。
689
+ 次のメソッドが用意されています。
690
+
691
+ set_landscape
692
+ set_portrait
693
+ set_page_view
694
+ set_paper
695
+ center_horizontally
696
+ center_vertically
697
+ set_margins
698
+ set_header
699
+ set_footer
700
+ repeat_rows
701
+ repeat_columns
702
+ hide_gridlines
703
+ print_row_col_headers
704
+ print_area
705
+ print_across
706
+ fit_to_pages
707
+ set_start_page
708
+ set_print_scale
709
+ set_h_pagebreaks
710
+ set_v_pagebreaks
711
+
712
+ すべてのワークシートに同じ印刷書式を設定する場合は、ワークシートの sheet メソッドを使って
713
+ 行うのが簡単です。
714
+
715
+ workbook.sheets.each do |worksheet|
716
+ worksheet.set_landscape
717
+ end
718
+
719
+ == セルフォーマッティング
720
+
721
+ ここではセルの書式設定について説明します。フォント、色、(塗りつぶし)パターン、枠線、配置、
722
+ 数値書式などなどです。
723
+
724
+ === フォーマットオブジェクトの作成と利用
725
+
726
+ セル書式はフォーマットオブジェクトを通して定義される。フォーマットオブジェクトは、workbook
727
+ の add_format メソッドで作成する。
728
+
729
+ format1 = workbook.add_format # プロパティは後で設定
730
+ format2 = workbook.add_format(property hash..) # 作成時にプロパティを設定
731
+
732
+ フォーマットオブジェクトはセルや行、桁に適用できる書式プロパティをすべて保持する。これらの
733
+ プロパティを設定するプロセスについては次節で述べられている。
734
+
735
+ フォーマットオブジェクトが作成されプロパティがセットされれば、worksheet の write メソッド
736
+ にパラメータとして渡して使う。
737
+
738
+ worksheet.write(0, 0, 'One', format)
739
+ worksheet.wirte_string(1, 0, 'Two', format)
740
+ worksheet.write_number(2, 0, 3, format)
741
+ worksheet.write_blank(3, 0, format)
742
+
743
+ フォーマットオブジェクトは、worksheet の set_row や set_column メソッドに渡され、行や
744
+ 桁のデフォルトプロパティを設定するのにも用いられる。
745
+
746
+ worksheet.set_row(0, 15, format)
747
+ worksheet.set_column(0, 0, 15, format)
748
+
749
+ === Format メソッドとプロパティ
750
+
751
+ Category Description Property Method Name
752
+ -------- ----------- -------- -----------
753
+ Font Font type font set_font()
754
+ Font size size set_size()
755
+ Font color color set_color()
756
+ Bold bold set_bold()
757
+ Italic italic set_italic()
758
+ Underline underline set_underline()
759
+ Strikeout font_strikeout set_font_strikeout()
760
+ Super/Subscript font_script set_font_script()
761
+ Outline font_outline set_font_outline()
762
+ Shadow font_shadow set_font_shadow()
763
+
764
+ Number Numeric format num_format set_num_format()
765
+
766
+ Protection Lock cells locked set_locked()
767
+ Hide formulas hidden set_hidden()
768
+
769
+ Alignment Horizontal align align set_align()
770
+ Vertical align valign set_align()
771
+ Rotation rotation set_rotation()
772
+ Text wrap text_wrap set_text_wrap()
773
+ Justify last text_justlast set_text_justlast()
774
+ Center across center_across set_center_across()
775
+ Indentation indent set_indent()
776
+ Shrink to fit shrink set_shrink()
777
+
778
+ Pattern Cell pattern pattern set_pattern()
779
+ Background color bg_color set_bg_color()
780
+ Foreground color fg_color set_fg_color()
781
+
782
+ Border Cell border border set_border()
783
+ Bottom border bottom set_bottom()
784
+ Top border top set_top()
785
+ Left border left set_left()
786
+ Right border right set_right()
787
+ Border color border_color set_border_color()
788
+ Bottom color bottom_color set_bottom_color()
789
+ Top color top_color set_top_color()
790
+ Left color left_color set_left_color()
791
+ Right color right_color set_right_color()
792
+
793
+ 書式プロパティを設定するには2つの方法がある。すなわち、オブジェクトメソッドインターフェースを用いる
794
+ 方法と、プロパティを直接設定する方法である。たとえば、メソッドインターフェースを用いる典型的な例は
795
+ 次のようなものである。
796
+
797
+ format = workbook.add_format
798
+ format.set_bold
799
+ format.set_color('red')
800
+
801
+ フォーマットオブジェクトを作成する際に、直接プロパティを hash で渡して指定する方法と比較する。
802
+
803
+ format = workbook.add_format(:bold => 1, :color => 'red')
804
+
805
+ あるいは、フォーマットオブジェクトを作成した後に set_format_properties メソッドで指定する
806
+ やり方は次の通りとなる。
807
+
808
+ format = workbook.add_format
809
+ format.set_format_properties(:bold => 1, :color => 'red')
810
+
811
+ プロパティを1つあるいはいくつかのハッシュに格納してメソッドに渡すこともできる。
812
+
813
+ font = {
814
+ :font => 'MS 明朝',
815
+ :size => 12,
816
+ :color => 'blue',
817
+ :bold => 1
818
+ }
819
+
820
+ shading = {
821
+ :bg_color => 'green',
822
+ :pattern => 1
823
+ }
824
+
825
+ format1 = workbook.add_format(font) # フォントだけ設定
826
+ format2 = workbook.add_format(font, shading) # 両方を設定
827
+
828
+ ===FORMATメソッド
829
+
830
+ Formatクラスのメソッドの詳細は改めて説明がある。加えて、gem の examples
831
+ ディレクトリの formats.rb を実行して得られる formats.xls には、ほとんど
832
+ すべての書式設定例があるので見ていただきたい。
833
+
834
+ 以下のメソッドがあります。
835
+
836
+ set_font
837
+ set_size
838
+ set_color
839
+ set_bold
840
+ set_italic
841
+ set_underline
842
+ set_font_strikeout
843
+ set_font_script
844
+ set_font_outline
845
+ set_font_shadow
846
+ set_num_format
847
+ set_locked
848
+ set_hidden
849
+ set_align
850
+ set_rotation
851
+ set_text_wrap
852
+ set_text_justlast
853
+ set_center_across
854
+ set_indent
855
+ set_shrink
856
+ set_pattern
857
+ set_bg_color
858
+ set_fg_color
859
+ set_border
860
+ set_bottom
861
+ set_top
862
+ set_left
863
+ set_right
864
+ set_border_color
865
+ set_bottom_color
866
+ set_top_color
867
+ set_left_color
868
+ set_right_color
869
+
870
+ これらは、プロパティとして直接指定することもできます。例えば、
871
+
872
+ format = workbook.add_format
873
+ format.set_bold
874
+
875
+ は、
876
+
877
+ format = workbook.add_format(:bold => 1)
878
+
879
+ と同じことになります。
880
+
881
+ ===色の扱い
882
+
883
+ エクセルは56色のカラーパレットを提供しています。WriteExcelでは、8から63までの
884
+ パレットインデックスを通じてアクセスできます。このインデックスは、フォント、背景色、
885
+ 枠線などの色の設定に用いられます。
886
+
887
+ format = workbook.add_format(
888
+ :color => 12, # index for blue
889
+ :font => 'MS 明朝',
890
+ :size => 12,
891
+ :bold => 1
892
+ )
893
+
894
+ よく用いられる色は、色の名前の文字列でも指定できます。文字列の大文字小文字は問いません。
895
+
896
+ 'black' => 8
897
+ 'blue' => 12
898
+ 'brown' => 16
899
+ 'cyan' => 15
900
+ 'gray' => 23
901
+ 'green' => 17
902
+ 'lime' => 11
903
+ 'magenta' => 14
904
+ 'navy' => 18
905
+ 'orange' => 53
906
+ 'pink' => 33
907
+ 'purple' => 20
908
+ 'red' => 10
909
+ 'silver' => 22
910
+ 'white' => 9
911
+ 'yellow' => 13
912
+
913
+ 使用例:
914
+
915
+ font = workbook.add_format(:color => 'red')
916
+
917
+ 求める色が既定色にない場合は、Workbook#set_custom_colorによりRGB(red green blue)を指定
918
+ してオーバーライドすることができます。
919
+
920
+ ferrari = workbook.set_custom_color(40, 216, 12, 12)
921
+
922
+ format = workbook.add_format(
923
+ :bg_color => ferrari,
924
+ :pattern => 1,
925
+ :border => 1
926
+ )
927
+
928
+ worksheet.write_blank('A1', format)
929
+
930
+ 以下のリンクが参考になるでしょう。
931
+
932
+ エクセルのカラーパレットについて詳しく見る。
933
+ http://www.mvps.org/dmcritchie/excel/colors.htm
934
+
935
+ A decimal RGB chart: http://www.hypersolutions.org/pages/rgbdec.html
936
+
937
+ A hex RGB chart: : http://www.hypersolutions.org/pages/rgbhex.html
938
+
939
+ ===DATES AND TIME IN EXCEL
940
+
941
+ エクセルでの日付・時刻について2つの重要なことがあります。
942
+
943
+ 1. エクセルの日付・時刻は正の実数形式である。
944
+
945
+ 2. WriteExcel は、Worksheet#write によって与えられた日付・時刻を表す文字列を
946
+ 自動的には日付・時刻データとして変換しない。
947
+
948
+ この2点について、どのように求められる書式で日付・時刻として表示するのか、
949
+ いくつかのサジェスチョンを以下に示します。
950
+
951
+ ====エクセルの日付・時刻は数値と書式
952
+
953
+ 文字列をWorksheet#writeで書き込んだ場合、それはあくまで文字列です。
954
+
955
+ worksheet.write('A1', '02/03/04') # !! Writes a string not a date. !!
956
+
957
+ エクセルでの日付・時刻にあたるのは実数です。
958
+ "Jan 1 2001 12:30 AM" は、36892.521です。
959
+
960
+ 整数部分はエポックからの日数であり、小数部分は一日のうち経過した時間のパーセンテージ
961
+ です。
962
+ いくつか例を載せます。
963
+
964
+ #!/usr/bin/ruby -w
965
+
966
+ require 'writeexcel'
967
+
968
+ workbook = WriteExcel.new('date_examples.xls')
969
+ worksheet = workbook.add_worksheet
970
+
971
+ worksheet.set_column('A:A', 30) # For extra visibility.
972
+
973
+ number = 39506.5
974
+
975
+ worksheet.write('A1', number) # 39506.5
976
+
977
+ format2 = workbook.add_format(:num_format => 'dd/mm/yy')
978
+ worksheet.write('A2', number , format2); # 28/02/08
979
+
980
+ format3 = workbook.add_format(:num_format => 'mm/dd/yy')
981
+ worksheet.write('A3', number , format3); # 02/28/08
982
+
983
+ format4 = workbook.add_format(:num_format => 'd-m-yyyy')
984
+ worksheet.write('A4', .number , format4) # 28-2-2008
985
+
986
+ format5 = workbook.add_format(:num_format => 'dd/mm/yy hh:mm')
987
+ worksheet.write('A5', number , format5) # 28/02/08 12:00
988
+
989
+ format6 = workbook.add_format(:num_format => 'd mmm yyyy')
990
+ worksheet.write('A6', number , format6) # 28 Feb 2008
991
+
992
+ format7 = workbook.add_format(:num_format => 'mmm d yyyy hh:mm AM/PM')
993
+ worksheet.write('A7', number , format7) # Feb 28 2008 12:00 PM
994
+
995
+ ====WriteExcel は日付・時刻風の文字列を自動的に日付・時刻には変換しない
996
+
997
+ WriteExcel は、日付・時刻風の文字列から日付・時刻の実数への変換を自動的には
998
+ 行いません。多くの書式があるため、また、解釈ミスを行う可能性があるためです。
999
+
1000
+ 例えば、02/03/04 は 2002年3月4日/2004年2月3日/2004年3月2日いずれか判別できません。
1001
+
1002
+ ですから、日付を扱うためには本来であれば数値に変換し、書式を指定して渡す必要があります。
1003
+
1004
+ しかし、数値に変換するのも大変ですから、ISO8601の形式(yyyy-mm=ddThh:mm:ss.sss)の文字列で
1005
+ 表し、Worksheet#write_date_timeで書き込む方法が用意されています。
1006
+
1007
+ worksheet.write_date_time('A2', '2001-01-01T12:20', format)
1008
+
1009
+ 詳しくはWorksheet#write_date_time のドキュメントを参照ください。
1010
+
1011
+ #!/usr/bin/ruby -w
1012
+
1013
+ require 'writeexcel'
1014
+
1015
+ workbook = WriteExcel.new('example.xls')
1016
+ worksheet = workbook.add_worksheet
1017
+
1018
+ # Set the default format for dates.
1019
+ date_format = workbook.add_format(:num_format => 'mmm d yyyy')
1020
+
1021
+ # Increase column width to improve visibility of data.
1022
+ worksheet.set_column('A:C', 20)
1023
+
1024
+ data = [
1025
+ %w(Item Cost Date),
1026
+ %w(Book 10 1/9/2007),
1027
+ %w(Beer 4 12/9/2007),
1028
+ %w(Bed 500 5/10/2007)
1029
+ ]
1030
+
1031
+ # Simulate reading from a data source.
1032
+ row = 0
1033
+
1034
+ data.each do |row_data|
1035
+ col = 0
1036
+ row_data.each do |item|
1037
+
1038
+ # Match dates in the following formats: d/m/yy, d/m/yyyy
1039
+ if item =~ %r[^(\d{1,2})/(\d{1,2})/(\d{4})$]
1040
+ # Change to the date format required by write_date_time().
1041
+ date = sprintf "%4d-%02d-%02dT", $3, $2, $1
1042
+ worksheet.write_date_time(row, col, date, date_format)
1043
+ else
1044
+ # Just plain data
1045
+ worksheet.write(row, col, item)
1046
+ end
1047
+ col += 1
1048
+ end
1049
+ row += 1
1050
+ end
1051
+
1052
+ ===エクセルにおけるグループとアウトライン
1053
+
1054
+ エクセルでは、行や桁をグループ化し、ワンクリックで表示・非表示を行うことができます。
1055
+ この昨日はアウトラインと関係があります。
1056
+
1057
+ ------------------------------------------
1058
+ 1 2 3 | | A | B | C | D | ...
1059
+ ------------------------------------------
1060
+ _ | 1 | A | | | | ...
1061
+ | _ | 2 | B | | | | ...
1062
+ | | | 3 | (C) | | | | ...
1063
+ | | | 4 | (D) | | | | ...
1064
+ | - | 5 | E | | | | ...
1065
+ | _ | 6 | F | | | | ...
1066
+ | | | 7 | (G) | | | | ...
1067
+ | | | 8 | (H) | | | | ...
1068
+ | - | 9 | I | | | | ...
1069
+ - | . | ... | ... | ... | ... | ...
1070
+
1071
+ レベル2のマイナス記号をクリックすると次のようになります。
1072
+
1073
+ ------------------------------------------
1074
+ 1 2 3 | | A | B | C | D | ...
1075
+ ------------------------------------------
1076
+ _ | 1 | A | | | | ...
1077
+ | | 2 | B | | | | ...
1078
+ | + | 5 | E | | | | ...
1079
+ | | 6 | F | | | | ...
1080
+ | + | 9 | I | | | | ...
1081
+ - | . | ... | ... | ... | ... | ...
1082
+
1083
+ さらにレベル1のマイナス記号をクリックすると次のようになります。
1084
+
1085
+ ------------------------------------------
1086
+ 1 2 3 | | A | B | C | D | ...
1087
+ ------------------------------------------
1088
+ | 1 | A | | | | ...
1089
+ + | . | ... | ... | ... | ... | ...
1090
+
1091
+ WriteExcel におけるグループ化は、Worksheet#set_row や Worksheet#set_column
1092
+ を通じて行うことができます。
1093
+
1094
+ set_row(row, height, format, hidden, level, collapsed)
1095
+ set_column(first_col, last_col, width, format, hidden, level, collapsed)
1096
+
1097
+ 次の例では、行1と行2、桁BからGまでににアウトラインレベル1を設定しています。
1098
+ hidden や format が nil の時は、デフォルトの値が用いられます。
1099
+
1100
+ worksheet.set_row(1, nil, nil, 0, 1)
1101
+ worksheet.set_row(2, nil, nil, 0, 1)
1102
+ worksheet.set_column('B:G', nil, nil, 0, 1)
1103
+
1104
+ エクセルではアウトラインレベル7まで用いることができます。ですから、パラメータ level は
1105
+ 0以上7以下でなければなりません。
1106
+
1107
+ 行、桁は hidden フラグをセットすることで折りたたむことができます。その場合、
1108
+ フラグをセットした行、桁は+記号が付いて折りたたまれます。
1109
+
1110
+ worksheet.set_row(1, nil, nil, 1, 1)
1111
+ worksheet.set_row(2, nil, nil, 1, 1)
1112
+ worksheet.set_row(3, nil, nil, 0, 0, 1) # Collapsed flag.
1113
+
1114
+ worksheet.set_column('B:G', nil, nil, 1, 1)
1115
+ worksheet.set_column('H:H', nil, nil, 0, 0, 1) # Collapsed flag.
1116
+
1117
+ Note: collapsed フラグをセットすることは、OpenOffice.orgやGnumeric との互換性上
1118
+ 特に重要です。
1119
+
1120
+ examplesディレクトリの outline.rb 及び outline_collapsed.rb をご覧ください。
1121
+
1122
+ ===エクセルのデータ検証(データ-入力規則)
1123
+
1124
+ データ検証は、ユーザのセルへの入力データを制限し、ヘルプやワーニングを
1125
+ 表示するエクセルの機能です。ドロップダウンリストで入力値を制限することもできます。
1126
+
1127
+ 一定の範囲内の整数に入力値を制限する際に、必要な値についてメッセージを表示し、
1128
+ 範囲外の時はワーニングを表示するなどの使い方が典型的な使用例でしょう。
1129
+ WriteExcel では次のようにします。
1130
+
1131
+ worksheet.data_validation('B3',
1132
+ {
1133
+ :validate => 'integer',
1134
+ :criteria => 'between',
1135
+ :minimum => 1,
1136
+ :maximum => 100,
1137
+ :input_title => '整数値を入力:',
1138
+ :input_message => '1以上100以下',
1139
+ :error_message => 'すいません、もう一度お願いします。'
1140
+ })
1141
+
1142
+ データ検証についてさらなる情報は、以下を参照のこと。
1143
+ "Description and examples of data validation in Excel":
1144
+ http://support.microsoft.com/kb/211485.
1145
+
1146
+ ===エクセルの数式と関数
1147
+
1148
+ ====注意
1149
+
1150
+ 数式及び関数の実装に際して、いくつか未解決の問題があります。
1151
+
1152
+ 1.数式を書き込むのは、文字列を書き込むのと比べ非常に遅いです。
1153
+ 2.関数内で{1;2;3}といった配列形式の定数は使えません。
1154
+ 3.単項演算子の「-」(マイナス)は、「-1*」と解釈されます。例:-SIN(PI()) => -1*SIN(PI())
1155
+ 4.演算子前後に空白は入れないでください。
1156
+ 5.名前付きレンジは未サポートです。
1157
+ 6.配列数式は未サポートです。
1158
+
1159
+ ====イントロダクション
1160
+
1161
+ 数式は、等号で始まる文字列です。
1162
+
1163
+ '=A1+B1'
1164
+ '=AVERAGE(1, 2, 3)'
1165
+
1166
+ 数式には、数値、文字列、真偽値、セル参照、セル範囲、関数を含むことができます。
1167
+ 名前付き範囲はまだサポートされていません。
1168
+ 数式はエクセルで記載するときと同様、セルや関数は大文字にする必要があります。
1169
+
1170
+ セルはA1形式で表します。桁はAからIVまで(0から255まで)。行は1から
1171
+ 65536までです。
1172
+
1173
+ 「$」による絶対指定もサポートしています。
1174
+
1175
+ '=A1' # Column and row are relative
1176
+ '=$A1' # Column is absolute and row is relative
1177
+ '=A$1' # Column is relative and row is absolute
1178
+ '=$A$1' # Column and row are absolute
1179
+
1180
+ 数式では他のシートのセルを参照することもできます。
1181
+
1182
+ '=Sheet2!A1'
1183
+ '=Sheet2!A1:A5'
1184
+ '=Sheet2:Sheet3!A1'
1185
+ '=Sheet2:Sheet3!A1:A5'
1186
+ q{='Test Data'!A1}
1187
+ q{='Test Data1:Test Data2'!A1}
1188
+
1189
+ シート参照とセル参照は「!」で区切られます。ワークシート名に空白やコンマ、括弧
1190
+ が含まれる場合、シングルクオートで囲う必要があります(上記例の末尾2例参照)。
1191
+ 他のワークブックに含まれるシートを参照することはできません。
1192
+
1193
+ 以下にエクセルの数式で使うことができる演算子を示します。
1194
+ ほとんど Ruby と同様ですが、異なるものには注記してあります。
1195
+ Arithmetic operators:
1196
+ =====================
1197
+ Operator Meaning Example
1198
+ + Addition 1+2
1199
+ - Subtraction 2-1
1200
+ * Multiplication 2*3
1201
+ / Division 1/4
1202
+ ^ Exponentiation 2^3 # べき乗
1203
+ - Unary minus -(1+2) # -1*(1+2)を解釈される。
1204
+ % Percent (Not modulus) 13% # パーセント。サポートしていない。
1205
+
1206
+ Comparison operators:
1207
+ =====================
1208
+ Operator Meaning Example
1209
+ = Equal to A1 = B1 # ==
1210
+ <> Not equal to A1 <> B1 # !=
1211
+ > Greater than A1 > B1
1212
+ < Less than A1 < B1
1213
+ >= Greater than or equal to A1 >= B1
1214
+ <= Less than or equal to A1 <= B1
1215
+
1216
+ String operator:
1217
+ ================
1218
+ Operator Meaning Example
1219
+ & Concatenation "Hello " & "World!" # 文字列の連結。
1220
+
1221
+ Reference operators:
1222
+ ====================
1223
+ Operator Meaning Example
1224
+ : Range operator A1:A4
1225
+ , Union operator SUM(1, 2+2, B3)
1226
+
1227
+ The range and comma operators can have different symbols in non-English
1228
+ versions of Excel. These will be supported in a later version of WriteExcel.
1229
+ European users of Excel take note:
1230
+
1231
+ worksheet.write('A1', '=SUM(1; 2; 3)') # Wrong!!
1232
+ worksheet.write('A1', '=SUM(1, 2, 3)') # Okay
1233
+
1234
+ 以下にはExcel5及びWriteExcelでサポートされている関数を示します。
1235
+
1236
+ ABS DB INDIRECT NORMINV SLN
1237
+ ACOS DCOUNT INFO NORMSDIST SLOPE
1238
+ ACOSH DCOUNTA INT NORMSINV SMALL
1239
+ ADDRESS DDB INTERCEPT NOT SQRT
1240
+ AND DEGREES IPMT NOW STANDARDIZE
1241
+ AREAS DEVSQ IRR NPER STDEV
1242
+ ASIN DGET ISBLANK NPV STDEVP
1243
+ ASINH DMAX ISERR ODD STEYX
1244
+ ATAN DMIN ISERROR OFFSET SUBSTITUTE
1245
+ ATAN2 DOLLAR ISLOGICAL OR SUBTOTAL
1246
+ ATANH DPRODUCT ISNA PEARSON SUM
1247
+ AVEDEV DSTDEV ISNONTEXT PERCENTILE SUMIF
1248
+ AVERAGE DSTDEVP ISNUMBER PERCENTRANK SUMPRODUCT
1249
+ BETADIST DSUM ISREF PERMUT SUMSQ
1250
+ BETAINV DVAR ISTEXT PI SUMX2MY2
1251
+ BINOMDIST DVARP KURT PMT SUMX2PY2
1252
+ CALL ERROR.TYPE LARGE POISSON SUMXMY2
1253
+ CEILING EVEN LEFT POWER SYD
1254
+ CELL EXACT LEN PPMT T
1255
+ CHAR EXP LINEST PROB TAN
1256
+ CHIDIST EXPONDIST LN PRODUCT TANH
1257
+ CHIINV FACT LOG PROPER TDIST
1258
+ CHITEST FALSE LOG10 PV TEXT
1259
+ CHOOSE FDIST LOGEST QUARTILE TIME
1260
+ CLEAN FIND LOGINV RADIANS TIMEVALUE
1261
+ CODE FINV LOGNORMDIST RAND TINV
1262
+ COLUMN FISHER LOOKUP RANK TODAY
1263
+ COLUMNS FISHERINV LOWER RATE TRANSPOSE
1264
+ COMBIN FIXED MATCH REGISTER.ID TREND
1265
+ CONCATENATE FLOOR MAX REPLACE TRIM
1266
+ CONFIDENCE FORECAST MDETERM REPT TRIMMEAN
1267
+ CORREL FREQUENCY MEDIAN RIGHT TRUE
1268
+ COS FTEST MID ROMAN TRUNC
1269
+ COSH FV MIN ROUND TTEST
1270
+ COUNT GAMMADIST MINUTE ROUNDDOWN TYPE
1271
+ COUNTA GAMMAINV MINVERSE ROUNDUP UPPER
1272
+ COUNTBLANK GAMMALN MIRR ROW VALUE
1273
+ COUNTIF GEOMEAN MMULT ROWS VAR
1274
+ COVAR GROWTH MOD RSQ VARP
1275
+ CRITBINOM HARMEAN MODE SEARCH VDB
1276
+ DATE HLOOKUP MONTH SECOND VLOOKUP
1277
+ DATEVALUE HOUR N SIGN WEEKDAY
1278
+ DAVERAGE HYPGEOMDIST NA SIN WEIBULL
1279
+ DAY IF NEGBINOMDIST SINH YEAR
1280
+ DAYS360 INDEX NORMDIST SKEW ZTEST
1281
+
1282
+ 上記数式や関数についての文法はエクセルのヘルプなどを参照ください。
1283
+
1284
+ WriteExcel で数式がうまく機能しない場合、以下を確認ください。
1285
+
1286
+ 1.エクセルやGnumeric, OpenOffice.orgでその数式が動くこと。
1287
+ 2.注意の項で示した制限に該当しないこと
1288
+ 3.セル参照や関数名が大文字で記述されていること
1289
+ 4.範囲にはコロンが使われていること A1:A4.
1290
+ 5.引数区切りにはコンマが使われていること SUM(1,2,3).
1291
+ 6.上記で示した関数であること
1292
+
1293
+ 上記を満たしていて、なおかつ問題がある場合は、
1294
+ cxn03651@msj.biglobe.ne.jp にお知らせください。
1295
+
1296
+ ====数式を使う際のパフォーマンス改善
1297
+
1298
+ WriteExcel でたくさんの数式を書き込む場合、とても時間がかかります。
1299
+ これは、現在の実装ではそれぞれの数式ごとに解釈されるためです。
1300
+
1301
+ しかしながら、以下のように同じような式を書き込んでいるのであれば改善策は
1302
+ あります。
1303
+
1304
+ worksheet.write_formula('B1', '=A1 * 3 + 50', format)
1305
+ worksheet.write_formula('B2', '=A2 * 3 + 50', format)
1306
+ ...
1307
+ ...
1308
+ worksheet.write_formula('B99', '=A999 * 3 + 50', format)
1309
+ worksheet.write_formula('B1000', '=A1000 * 3 + 50', format)
1310
+
1311
+ この例では、セル参照がA1からA1000まで順に変化しています。
1312
+ こういうときは、Wordsheet#store_formulaとWorksheet#repeat_formulaを使って、
1313
+ 一度解釈したものを再利用することができます。
1314
+
1315
+ formula = worksheet.store_formula('=A1 * 3 + 50')
1316
+
1317
+ (0...1000).each do |row|
1318
+ worksheet.repeat_formula(row, 1, formula, format, 'A1', 'A' + (row +1).to_s)
1319
+ end
1320
+
1321
+ とあるマシン上では、これで10倍早くなりました。
1322
+
1323
+ ===チャート
1324
+
1325
+ ====概要(チャート)
1326
+
1327
+ WriteExcelでチャートを含むエクセルファイルを作る例です。
1328
+
1329
+ #!/usr/bin/ruby -w
1330
+
1331
+ require 'writeexcel'
1332
+
1333
+ workbook = WriteExcel.new('chart.xls')
1334
+ worksheet = workbook.add_worksheet
1335
+
1336
+ chart = workbook.add_chart(:type => 'Chart::Column')
1337
+
1338
+ # Configure the chart.
1339
+ chart.add_series(
1340
+ :categories => '=Sheet1!$A$2:$A$7',
1341
+ :values => '=Sheet1!$B$2:$B$7'
1342
+ )
1343
+
1344
+ # Add the data to the worksheet the chart refers to.
1345
+ data = [
1346
+ [ 'Category', 2, 3, 4, 5, 6, 7 ],
1347
+ [ 'Value', 1, 4, 5, 2, 1, 5 ]
1348
+ ]
1349
+
1350
+ worksheet.write('A1', data)
1351
+
1352
+ workbook.close
1353
+
1354
+ ====説明(チャート)
1355
+
1356
+ チャートを使う場合、チャートのタイプを指定してWorkbook#add_chartを呼びます。
1357
+
1358
+ chart = workbook.add_chart(:type => 'Chart::Column')
1359
+
1360
+ 現在サポートされているのは、次の5つ。
1361
+
1362
+ * 'Chart::Column': Creates a column style (histogram) chart. See Column.
1363
+ * 'Chart::Bar': Creates a Bar style (transposed histogram) chart. See Bar.
1364
+ * 'Chart::Line': Creates a Line style chart. See Line.
1365
+ * 'Chart::Area': Creates an Area (filled line) style chart. See Area.
1366
+ * 'Chart::Scatter': Creates an Scatter style chart. See Scatter.
1367
+ * 'Chart::Stock': Creates an Stock style chart. See Stock.
1368
+
1369
+ More chart types will be supported in time. See the "TODO" section.
1370
+
1371
+ === チャート名とリンク
1372
+
1373
+ Chart#add_series, Chart#set_x_axis, Chart#set_y_axis, Chart#set_title メソッドは
1374
+ methods all
1375
+ support a name property. In general these names can be either a static
1376
+ string or a link to a worksheet cell. If you choose to use the name_formula
1377
+ property to specify a link then you should also the name property.
1378
+ This isn't strictly required by Excel but some third party applications
1379
+ expect it to be present.
1380
+
1381
+ chartl.set_title(
1382
+ :name => 'Year End Results',
1383
+ :name_formula => '=Sheet1!$C$1'
1384
+ )
1385
+
1386
+ These links should be used sparingly since they aren't commonly
1387
+ used in Excel charts.
1388
+
1389
+ === Chart names and Unicode
1390
+
1391
+ The add_series()), set_x_axis(), set_y_axis() and set_title() methods all
1392
+ support a name property. These names can be UTF8 strings.
1393
+
1394
+ This methodology is explained in the "UNICODE IN EXCEL" section of WriteExcel
1395
+ but is semi-deprecated. If you are using Unicode the easiest option is to
1396
+ just use UTF8.
1397
+
1398
+ === TODO(Chart)
1399
+
1400
+ Charts in WriteExcel are a work in progress. More chart types and
1401
+ features will be added in time. Please be patient. Even a small feature
1402
+ can take a week or more to implement, test and document.
1403
+
1404
+ Features that are on the TODO list and will be added are:
1405
+
1406
+ * Additional chart types. Stock, Pie and Scatter charts are next in line.
1407
+ Send an email if you are interested in other types and they will be
1408
+ added to the queue.
1409
+ * Colours and formatting options. For now you will have to make do
1410
+ with the default Excel colours and formats.
1411
+ * Axis controls, gridlines.
1412
+ * Embedded data in charts for third party application support.
1413
+
1414
+ == KNOWN ISSUES(Chart)
1415
+
1416
+ * Currently charts don't contain embedded data from which the charts
1417
+ can be rendered. Excel and most other third party applications ignore
1418
+ this and read the data via the links that have been specified. However,
1419
+ some applications may complain or not render charts correctly. The
1420
+ preview option in Mac OS X is an known example. This will be fixed
1421
+ in a later release.
1422
+ * When there are several charts with titles set in a workbook some of
1423
+ the titles may display at a font size of 10 instead of the default
1424
+ 12 until another chart with the title set is viewed.
1425
+