ricardoo27-writeexcel 0.6.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,1189 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+ require 'stringio'
4
+
5
+ class TC_Format < Test::Unit::TestCase
6
+
7
+ TEST_DIR = File.expand_path(File.dirname(__FILE__))
8
+ PERL_OUTDIR = File.join(TEST_DIR, 'perl_output')
9
+
10
+ def setup
11
+ @ruby_file = StringIO.new
12
+ @format = Writeexcel::Format.new
13
+ end
14
+
15
+ def test_set_format_properties
16
+ end
17
+
18
+ def test_format_properties_with_valid_value
19
+ # set_format_properties( propty => val )
20
+ valid_properties = get_valid_format_properties
21
+ valid_properties.each do |k,v|
22
+ fmt = Writeexcel::Format.new
23
+ before = get_format_property(fmt)
24
+ fmt.set_format_properties(k => v)
25
+ after = get_format_property(fmt)
26
+ after.delete_if {|key, val| before[key] == val }
27
+ assert_equal(1, after.size, "change 1 property[:#{k}] but #{after.size} was changed.#{after.inspect}")
28
+ assert_equal(v, after[k], "[:#{k}] doesn't match.")
29
+ end
30
+
31
+ # set_format_properties( propty_1 => val1, propty_2 => val2)
32
+ valid_properties.each do |k,v|
33
+ fmt = Writeexcel::Format.new
34
+ before = get_format_property(fmt)
35
+ fmt.set_format_properties(k => v, :bold => 1)
36
+ after = get_format_property(fmt)
37
+ after.delete_if {|key, val| before[key] == val }
38
+ assert_equal(2, after.size, "change 1 property[:#{k}] but #{after.size} was changed.#{after.inspect}")
39
+ assert_equal(v, after[k], "[:#{k}] doesn't match.")
40
+ assert_equal(700, after[:bold])
41
+ end
42
+
43
+ # set_format_properties( hash_variable )
44
+ valid_properties = get_valid_format_properties
45
+ valid_properties.each do |k,v|
46
+ arg = {k => v}
47
+ fmt = Writeexcel::Format.new
48
+ before = get_format_property(fmt)
49
+ fmt.set_format_properties(arg)
50
+ after = get_format_property(fmt)
51
+ after.delete_if {|key, val| before[key] == val }
52
+ assert_equal(1, after.size, "change 1 property[:#{k}] but #{after.size} was changed.#{after.inspect}")
53
+ assert_equal(v, after[k], "[:#{k}] doesn't match.")
54
+ end
55
+
56
+ # set_format_properties( hash_variable, hash_variable... )
57
+ valid_properties = get_valid_format_properties
58
+ valid_properties.each do |k,v|
59
+ arg = {k => v}
60
+ arg2 = {:bold => 1}
61
+ fmt = Writeexcel::Format.new
62
+ before = get_format_property(fmt)
63
+ fmt.set_format_properties(arg, arg2)
64
+ after = get_format_property(fmt)
65
+ after.delete_if {|key, val| before[key] == val }
66
+ assert_equal(2, after.size, "change 1 property[:#{k}] but #{after.size} was changed.#{after.inspect}")
67
+ assert_equal(v, after[k], "[:#{k}] doesn't match.")
68
+ assert_equal(700, after[:bold])
69
+ end
70
+
71
+ # set_color by string
72
+ valid_color_string_number = get_valid_color_string_number
73
+ [:color , :bg_color, :fg_color].each do |coltype|
74
+ valid_color_string_number.each do |str, num|
75
+ fmt = Writeexcel::Format.new
76
+ before = get_format_property(fmt)
77
+ fmt.set_format_properties(coltype => str)
78
+ after = get_format_property(fmt)
79
+ after.delete_if {|key, val| before[key] == val }
80
+ assert_equal(1, after.size, "change 1 property[:#{coltype}:#{str}] but #{after.size} was changed.#{after.inspect}")
81
+ assert_equal(num, after[:"#{coltype}"], "[:#{coltype}:#{str}] doesn't match.")
82
+ end
83
+ end
84
+
85
+
86
+ end
87
+
88
+ def test_format_properties_with_invalid_value
89
+ end
90
+
91
+ def test_set_font
92
+ end
93
+
94
+ =begin
95
+ set_size()
96
+ Default state: Font size is 10
97
+ Default action: Set font size to 1
98
+ Valid args: Integer values from 1 to as big as your screen.
99
+ Set the font size. Excel adjusts the height of a row to accommodate the largest font size in the row. You can also explicitly specify the height of a row using the set_row() worksheet method.
100
+ =end
101
+ def test_set_size
102
+ # default state
103
+ assert_equal(10, @format.size)
104
+
105
+ # valid size from low to high
106
+ [1, 100, 100**10].each do |size|
107
+ fmt = Writeexcel::Format.new
108
+ fmt.set_size(size)
109
+ assert_equal(size, fmt.size, "valid size:#{size} - doesn't match.")
110
+ end
111
+
112
+ # invalid size -- size doesn't change
113
+ [-1, 0, 1/2.0, 'hello', true, false, nil, [0,0], {:invalid => "val"}].each do |size|
114
+ fmt = Writeexcel::Format.new
115
+ default = fmt.size
116
+ fmt.set_size(size)
117
+ assert_equal(default, fmt.size, "size:#{size.inspect} doesn't match.")
118
+ end
119
+ end
120
+
121
+ =begin
122
+ set_color()
123
+
124
+ Default state: Excels default color, usually black
125
+ Default action: Set the default color
126
+ Valid args: Integers from 8..63 or the following strings:
127
+ 'black'
128
+ 'blue'
129
+ 'brown'
130
+ 'cyan'
131
+ 'gray'
132
+ 'green'
133
+ 'lime'
134
+ 'magenta'
135
+ 'navy'
136
+ 'orange'
137
+ 'pink'
138
+ 'purple'
139
+ 'red'
140
+ 'silver'
141
+ 'white'
142
+ 'yellow'
143
+
144
+ Set the font colour. The set_color() method is used as follows:
145
+
146
+ format = workbook.add_format()
147
+ format.set_color('red')
148
+ worksheet.write(0, 0, 'wheelbarrow', format)
149
+
150
+ Note: The set_color() method is used to set the colour of the font in a cell.
151
+ To set the colour of a cell use the set_bg_color() and set_pattern() methods.
152
+ =end
153
+ def test_set_color
154
+ # default state
155
+ default_col = 0x7FFF
156
+ assert_equal(default_col, @format.color)
157
+
158
+ # valid color
159
+ # set by string
160
+ str_num = get_valid_color_string_number
161
+ str_num.each do |str,num|
162
+ fmt = Writeexcel::Format.new
163
+ fmt.set_color(str)
164
+ assert_equal(num, fmt.color)
165
+ end
166
+
167
+ # valid color
168
+ # set by number
169
+ [8, 36, 63].each do |color|
170
+ fmt = Writeexcel::Format.new
171
+ fmt.set_color(color)
172
+ assert_equal(color, fmt.color)
173
+ end
174
+
175
+ # invalid color
176
+ ['color', :col, -1, 63.5, 10*10].each do |color|
177
+ fmt = Writeexcel::Format.new
178
+ fmt.set_color(color)
179
+ assert_equal(default_col, fmt.color, "color : #{color}")
180
+ end
181
+
182
+ # invalid color ...but...
183
+ # 0 <= color < 8 then color += 8 in order to valid value
184
+ [0, 7.5].each do |color|
185
+ fmt = Writeexcel::Format.new
186
+ fmt.set_color(color)
187
+ assert_equal((color + 8).to_i, fmt.color, "color : #{color}")
188
+ end
189
+
190
+
191
+ end
192
+
193
+ =begin
194
+ set_bold()
195
+
196
+ Default state: bold is off (internal value = 400)
197
+ Default action: Turn bold on
198
+ Valid args: 0, 1 [1]
199
+
200
+ Set the bold property of the font:
201
+
202
+ $format->set_bold(); # Turn bold on
203
+
204
+ [1] Actually, values in the range 100..1000 are also valid.
205
+ 400 is normal, 700 is bold and 1000 is very bold indeed.
206
+ It is probably best to set the value to 1 and use normal bold.
207
+ =end
208
+
209
+ def test_set_bold
210
+ # default state
211
+ assert_equal(400, @format.bold)
212
+
213
+ # valid weight
214
+ fmt = Writeexcel::Format.new
215
+ fmt.set_bold
216
+ assert_equal(700, fmt.bold)
217
+ {0 => 400, 1 => 700, 100 => 100, 1000 => 1000}.each do |weight, value|
218
+ fmt = Writeexcel::Format.new
219
+ fmt.set_bold(weight)
220
+ assert_equal(value, fmt.bold)
221
+ end
222
+
223
+ # invalid weight
224
+ [-1, 99, 1001, 'bold'].each do |weight|
225
+ fmt = Writeexcel::Format.new
226
+ fmt.set_bold(weight)
227
+ assert_equal(400, fmt.bold, "weight : #{weight}")
228
+ end
229
+ end
230
+
231
+ =begin
232
+ set_italic()
233
+
234
+ Default state: Italic is off
235
+ Default action: Turn italic on
236
+ Valid args: 0, 1
237
+
238
+ Set the italic property of the font:
239
+
240
+ format.set_italic() # Turn italic on
241
+ =end
242
+ def test_set_italic
243
+ # default state
244
+ assert_equal(0, @format.italic)
245
+
246
+ # valid arg
247
+ fmt = Writeexcel::Format.new
248
+ fmt.set_italic
249
+ assert_equal(1, fmt.italic)
250
+ {0=>0, 1=>1}.each do |arg,value|
251
+ fmt = Writeexcel::Format.new
252
+ fmt.set_italic(arg)
253
+ assert_equal(value, fmt.italic, "arg : #{arg}")
254
+ end
255
+
256
+ # invalid arg
257
+ [-1, 0.2, 100, 'italic', true, false, nil].each do |arg|
258
+ assert_raise(ArgumentError,
259
+ "set_italic(#{arg}) : invalid arg. arg must be 0, 1 or none."){
260
+ fmt = Writeexcel::Format.new
261
+ fmt.set_italic(arg)
262
+ }
263
+ end
264
+ end
265
+
266
+ =begin
267
+ set_underline()
268
+
269
+ Default state: Underline is off
270
+ Default action: Turn on single underline
271
+ Valid args: 0 = No underline
272
+ 1 = Single underline
273
+ 2 = Double underline
274
+ 33 = Single accounting underline
275
+ 34 = Double accounting underline
276
+
277
+ Set the underline property of the font.
278
+
279
+ format.set_underline() # Single underline
280
+ =end
281
+ def test_set_underline
282
+ # default state
283
+ assert_equal(0, @format.underline, "default state")
284
+
285
+ # valid args
286
+ fmt = Writeexcel::Format.new
287
+ fmt.set_underline
288
+ assert_equal(1, fmt.underline, "No arg")
289
+
290
+ [0, 1, 2, 33, 34].each do |arg|
291
+ fmt = Writeexcel::Format.new
292
+ fmt.set_underline(arg)
293
+ assert_equal(arg, fmt.underline, "arg : #{arg}")
294
+ end
295
+
296
+ # invalid args
297
+ [-1, 0.2, 100, 'under', true, false, nil].each do |arg|
298
+ assert_raise(ArgumentError,
299
+ "set_underline(#{arg}) : arg must be 0, 1 or none, 2, 33, 34."){
300
+ fmt = Writeexcel::Format.new
301
+ fmt.set_underline(arg)
302
+ }
303
+ end
304
+ end
305
+
306
+ =begin
307
+ set_font_strikeout()
308
+
309
+ Default state: Strikeout is off
310
+ Default action: Turn strikeout on
311
+ Valid args: 0, 1
312
+
313
+ Set the strikeout property of the font.
314
+ =end
315
+ def test_set_font_strikeout
316
+ # default state
317
+ assert_equal(0, @format.font_strikeout, "default state")
318
+
319
+ # valid args
320
+ fmt = Writeexcel::Format.new
321
+ fmt.set_font_strikeout
322
+ assert_equal(1, fmt.font_strikeout, "No arg")
323
+
324
+ [0, 1].each do |arg|
325
+ fmt = Writeexcel::Format.new
326
+ fmt.set_font_strikeout(arg)
327
+ assert_equal(arg, fmt.font_strikeout, "arg : #{arg}")
328
+ end
329
+
330
+ # invalid args
331
+ [-1, 0.2, 100, 'strikeout', true, false, nil].each do |arg|
332
+ assert_raise(ArgumentError,
333
+ "set_font_strikeout(#{arg}) : arg must be 0, 1 or none."){
334
+ fmt = Writeexcel::Format.new
335
+ fmt.set_font_strikeout(arg)
336
+ }
337
+ end
338
+ end
339
+
340
+ =begin
341
+ set_font_script()
342
+
343
+ Default state: Super/Subscript is off
344
+ Default action: Turn Superscript on
345
+ Valid args: 0 = Normal
346
+ 1 = Superscript
347
+ 2 = Subscript
348
+
349
+ Set the superscript/subscript property of the font. This format is currently not very useful.
350
+ =end
351
+ def test_set_font_script
352
+ # default state
353
+ assert_equal(0, @format.font_script, "default state")
354
+
355
+ # valid args
356
+ fmt = Writeexcel::Format.new
357
+ fmt.set_font_script
358
+ assert_equal(1, fmt.font_script, "No arg")
359
+
360
+ [0, 1, 2].each do |arg|
361
+ fmt = Writeexcel::Format.new
362
+ fmt.set_font_script(arg)
363
+ assert_equal(arg, fmt.font_script, "arg : #{arg}")
364
+ end
365
+
366
+ # invalid args
367
+ [-1, 0.2, 100, 'script', true, false, nil].each do |arg|
368
+ assert_raise(ArgumentError,
369
+ "set_font_script(#{arg}) : arg must be 0, 1 or none, or 2."){
370
+ fmt = Writeexcel::Format.new
371
+ fmt.set_font_script(arg)
372
+ }
373
+ end
374
+
375
+ end
376
+
377
+ =begin
378
+ set_font_outline()
379
+
380
+ Default state: Outline is off
381
+ Default action: Turn outline on
382
+ Valid args: 0, 1
383
+
384
+ Macintosh only.
385
+ =end
386
+ def test_set_font_outline
387
+ # default state
388
+ assert_equal(0, @format.font_outline, "default state")
389
+
390
+ # valid args
391
+ fmt = Writeexcel::Format.new
392
+ fmt.set_font_outline
393
+ assert_equal(1, fmt.font_outline, "No arg")
394
+
395
+ [0, 1].each do |arg|
396
+ fmt = Writeexcel::Format.new
397
+ fmt.set_font_outline(arg)
398
+ assert_equal(arg, fmt.font_outline, "arg : #{arg}")
399
+ end
400
+
401
+ # invalid args
402
+ [-1, 0.2, 100, 'outline', true, false, nil].each do |arg|
403
+ assert_raise(ArgumentError,
404
+ "set_font_outline(#{arg}) : arg must be 0, 1 or none."){
405
+ fmt = Writeexcel::Format.new
406
+ fmt.set_font_outline(arg)
407
+ }
408
+ end
409
+ end
410
+
411
+ =begin
412
+ set_font_shadow()
413
+
414
+ Default state: Shadow is off
415
+ Default action: Turn shadow on
416
+ Valid args: 0, 1
417
+
418
+ Macintosh only.
419
+ =end
420
+ def test_set_font_shadow
421
+ # default state
422
+ assert_equal(0, @format.font_shadow, "default state")
423
+
424
+ # valid args
425
+ fmt = Writeexcel::Format.new
426
+ fmt.set_font_shadow
427
+ assert_equal(1, fmt.font_shadow, "No arg")
428
+
429
+ [0, 1].each do |arg|
430
+ fmt = Writeexcel::Format.new
431
+ fmt.set_font_shadow(arg)
432
+ assert_equal(arg, fmt.font_shadow, "arg : #{arg}")
433
+ end
434
+
435
+ # invalid args
436
+ [-1, 0.2, 100, 'shadow', true, false, nil].each do |arg|
437
+ assert_raise(ArgumentError,
438
+ "set_font_shadow(#{arg}) : arg must be 0, 1 or none."){
439
+ fmt = Writeexcel::Format.new
440
+ fmt.set_font_shadow(arg)
441
+ }
442
+ end
443
+ end
444
+
445
+ =begin
446
+ set_num_format()
447
+
448
+ Default state: General format
449
+ Default action: Format index 1
450
+ Valid args: See the following table
451
+
452
+ This method is used to define the numerical format of a number in Excel. It controls whether a number is displayed as an integer, a floating point number, a date, a currency value or some other user defined format.
453
+ =end
454
+ def test_set_num_format
455
+ # default state
456
+ assert_equal(0, @format.num_format)
457
+
458
+ # Excel built in Format Index (0 .. 49)
459
+ [0, 49].each do |n|
460
+ fmt = Writeexcel::Format.new
461
+ fmt.set_num_format(n)
462
+ assert_equal(n, fmt.num_format, "n: #{n}")
463
+ end
464
+
465
+ # Format string
466
+ ["#,##0", "m/d/yy", "hh:mm:ss"].each do |string|
467
+ fmt = Writeexcel::Format.new
468
+ fmt.set_num_format(string)
469
+ assert_equal(string, fmt.num_format, "string: #{string}")
470
+ end
471
+ end
472
+
473
+ =begin
474
+ set_locked()
475
+
476
+ Default state: Cell locking is on
477
+ Default action: Turn locking on
478
+ Valid args: 0, 1
479
+
480
+ This property can be used to prevent modification of a cells
481
+ contents. Following Excel's convention, cell locking is
482
+ turned on by default. However, it only has an effect if
483
+ the worksheet has been protected, see the worksheet protect()
484
+ method.
485
+
486
+ locked = workbook.add_format()
487
+ locked.set_locked(1) # A non-op
488
+
489
+ unlocked = workbook.add_format()
490
+ locked.set_locked(0)
491
+
492
+ # Enable worksheet protection
493
+ worksheet.protect()
494
+
495
+ # This cell cannot be edited.
496
+ worksheet.write('A1', '=1+2', locked)
497
+
498
+ # This cell can be edited.
499
+ worksheet->write('A2', '=1+2', unlocked)
500
+
501
+ Note: This offers weak protection even with a password,
502
+ see the note in relation to the protect() method.
503
+ =end
504
+ def test_set_locked
505
+ # default state
506
+ assert_equal(1, @format.locked, "default state")
507
+
508
+ # valid args
509
+ fmt = Writeexcel::Format.new
510
+ fmt.set_locked
511
+ assert_equal(1, fmt.locked, "No arg")
512
+
513
+ [0, 1].each do |arg|
514
+ fmt = Writeexcel::Format.new
515
+ fmt.set_locked(arg)
516
+ assert_equal(arg, fmt.locked, "arg : #{arg}")
517
+ end
518
+
519
+ # invalid args
520
+ [-1, 0.2, 100, 'locked', true, false, nil].each do |arg|
521
+ assert_raise(ArgumentError,
522
+ "set_font_shadow(#{arg}) : arg must be 0, 1 or none."){
523
+ fmt = Writeexcel::Format.new
524
+ fmt.set_locked(arg)
525
+ }
526
+ end
527
+ end
528
+ =begin
529
+ set_hidden()
530
+
531
+ Default state: Formula hiding is off
532
+ Default action: Turn hiding on
533
+ Valid args: 0, 1
534
+
535
+ This property is used to hide a formula while still displaying
536
+ its result. This is generally used to hide complex calculations
537
+ from end users who are only interested in the result.
538
+ It only has an effect if the worksheet has been protected,
539
+ see the worksheet protect() method.
540
+
541
+ my hidden = workbook.add_format()
542
+ hidden.set_hidden()
543
+
544
+ # Enable worksheet protection
545
+ worksheet.protect()
546
+
547
+ # The formula in this cell isn't visible
548
+ worksheet.write('A1', '=1+2', hidden)
549
+
550
+ Note: This offers weak protection even with a password,
551
+ see the note in relation to the protect() method.
552
+ =end
553
+ def test_set_hidden
554
+ # default state
555
+ assert_equal(0, @format.hidden, "default state")
556
+
557
+ # valid args
558
+ fmt = Writeexcel::Format.new
559
+ fmt.set_hidden
560
+ assert_equal(1, fmt.hidden, "No arg")
561
+
562
+ [0, 1].each do |arg|
563
+ fmt = Writeexcel::Format.new
564
+ fmt.set_hidden(arg)
565
+ assert_equal(arg, fmt.hidden, "arg : #{arg}")
566
+ end
567
+
568
+ # invalid args
569
+ [-1, 0.2, 100, 'hidden', true, false, nil].each do |arg|
570
+ assert_raise(ArgumentError,
571
+ "set_font_shadow(#{arg}) : arg must be 0, 1 or none."){
572
+ fmt = Writeexcel::Format.new
573
+ fmt.set_hidden(arg)
574
+ }
575
+ end
576
+ end
577
+
578
+ =begin
579
+ set_align()
580
+
581
+ Default state: Alignment is off
582
+ Default action: Left alignment
583
+ Valid args: 'left' Horizontal
584
+ 'center'
585
+ 'right'
586
+ 'fill'
587
+ 'justify'
588
+ 'center_across'
589
+
590
+ 'top' Vertical
591
+ 'vcenter'
592
+ 'bottom'
593
+ 'vjustify'
594
+
595
+ This method is used to set the horizontal and vertical text alignment
596
+ within a cell. Vertical and horizontal alignments can be combined.
597
+ The method is used as follows:
598
+
599
+ my $format = $workbook->add_format();
600
+ $format->set_align('center');
601
+ $format->set_align('vcenter');
602
+ $worksheet->set_row(0, 30);
603
+ $worksheet->write(0, 0, 'X', $format);
604
+
605
+ Text can be aligned across two or more adjacent cells using
606
+ the center_across property. However, for genuine merged cells
607
+ it is better to use the merge_range() worksheet method.
608
+
609
+ The vjustify (vertical justify) option can be used to provide
610
+ automatic text wrapping in a cell. The height of the cell will be
611
+ adjusted to accommodate the wrapped text. To specify where the text
612
+ wraps use the set_text_wrap() method.
613
+ =end
614
+ def test_set_align
615
+ # default state
616
+ assert_equal(0, @format.text_h_align)
617
+ assert_equal(2, @format.text_v_align)
618
+
619
+ # valid arg
620
+ valid_args = {'left'=>1, 'center'=>2, 'centre'=>2, 'right'=>3,
621
+ 'fill'=>4, 'justify'=>5, 'center_across'=>6,
622
+ 'centre_across'=>6, 'merge'=>6,
623
+ 'top'=>0, 'vcenter'=>1, 'vcentre'=>1, 'bottom'=>2,
624
+ 'vjustify'=>3 }
625
+ valid_args.each do |arg, value|
626
+ fmt = Writeexcel::Format.new
627
+ fmt.set_align(arg)
628
+ case arg
629
+ when 'left', 'center', 'centre', 'right', 'fill', 'justify',
630
+ 'center_across', 'centre_across', 'merge'
631
+ assert_equal(value, fmt.text_h_align, "arg: #{arg}")
632
+ when 'top', 'vcenter', 'vcentre', 'bottom', 'vjustify'
633
+ assert_equal(value, fmt.text_v_align, "arg: #{arg}")
634
+ end
635
+ end
636
+
637
+ # invalid arg
638
+ [-1, 0, 1.5, nil, true, false, ['left','top'], {'top'=>0}].each do |arg|
639
+ fmt = Writeexcel::Format.new
640
+ val = get_format_property(fmt)
641
+ #print val.inspect
642
+ #exit
643
+ fmt.set_align(arg)
644
+ assert_equal(val[:align], fmt.text_h_align, "arg: #{arg} - text_h_align changed.")
645
+ assert_equal(val[:valign], fmt.text_v_align, "arg: #{arg} - text_v_align changed.")
646
+ end
647
+ end
648
+
649
+ =begin
650
+ set_center_across()
651
+
652
+ Default state: Center across selection is off
653
+ Default action: Turn center across on
654
+ Valid args: 1
655
+
656
+ Text can be aligned across two or more adjacent cells
657
+ using the set_center_across() method. This is an alias
658
+ for the set_align('center_across') method call.
659
+
660
+ Only one cell should contain the text,
661
+ the other cells should be blank:
662
+
663
+ format = workbook.add_format()
664
+ format.set_center_across()
665
+
666
+ worksheet.write(1, 1, 'Center across selection', format)
667
+ worksheet.write_blank(1, 2, format)
668
+ =end
669
+ def test_set_center_across
670
+ # default state
671
+ assert_equal(0, @format.text_h_align)
672
+
673
+ # method call then center_across is set. if arg is none, numeric, string, whatever.
674
+ @format.set_center_across
675
+ assert_equal(6, @format.text_h_align)
676
+ end
677
+
678
+ =begin
679
+ set_text_wrap()
680
+
681
+ Default state: Text wrap is off
682
+ Default action: Turn text wrap on
683
+ Valid args: 0, 1
684
+
685
+ Here is an example using the text wrap property, the escape
686
+ character \n is used to indicate the end of line:
687
+
688
+ format = workbook.add_format()
689
+ format.set_text_wrap()
690
+ worksheet.write(0, 0, "It's\na bum\nwrap", format)
691
+ =end
692
+ def test_set_text_wrap
693
+ # default state
694
+ assert_equal(0, @format.text_wrap, "default state")
695
+
696
+ # valid args
697
+ fmt = Writeexcel::Format.new
698
+ fmt.set_text_wrap
699
+ assert_equal(1, fmt.text_wrap, "No arg")
700
+
701
+ [0, 1].each do |arg|
702
+ fmt = Writeexcel::Format.new
703
+ fmt.set_text_wrap(arg)
704
+ assert_equal(arg, fmt.text_wrap, "arg : #{arg}")
705
+ end
706
+
707
+ # invalid args
708
+ [-1, 0.2, 100, 'text_wrap', true, false, nil].each do |arg|
709
+ assert_raise(ArgumentError,
710
+ "set_text_wrap(#{arg}) : arg must be 0, 1 or none."){
711
+ fmt = Writeexcel::Format.new
712
+ fmt.set_text_wrap(arg)
713
+ }
714
+ end
715
+ end
716
+
717
+ =begin
718
+ set_rotation()
719
+
720
+ Default state: Text rotation is off
721
+ Default action: None
722
+ Valid args: Integers in the range -90 to 90 and 270
723
+
724
+ Set the rotation of the text in a cell. The rotation can be
725
+ any angle in the range -90 to 90 degrees.
726
+
727
+ format = workbook.add_format()
728
+ format.set_rotation(30)
729
+ worksheet.write(0, 0, 'This text is rotated', format)
730
+
731
+ The angle 270 is also supported. This indicates text where
732
+ the letters run from top to bottom.
733
+ =end
734
+ def test_set_rotation
735
+ # default state
736
+ assert_equal(0, @format.rotation)
737
+
738
+ # # valid args -90 <= angle <= 90, 270 angle can be float or double
739
+ # [-90.0, 89, 0, 89, 90, 270].each do |angle|
740
+ # fmt = Writeexcel::Format.new
741
+ # fmt.set_rotation(angle)
742
+ # assert_equal(angle, fmt.rotation, "angle: #{angle}")
743
+ # end
744
+ end
745
+
746
+ =begin
747
+ set_indent()
748
+
749
+ Default state: Text indentation is off
750
+ Default action: Indent text 1 level
751
+ Valid args: Positive integers
752
+
753
+ This method can be used to indent text. The argument, which should
754
+ be an integer, is taken as the level of indentation:
755
+
756
+ format = workbook.add_format()
757
+ format.set_indent(2)
758
+ worksheet.write(0, 0, 'This text is indented', format)
759
+
760
+ Indentation is a horizontal alignment property. It will override
761
+ any other horizontal properties but it can be used in conjunction
762
+ with vertical properties.
763
+ =end
764
+ def test_set_indent
765
+ # default state
766
+ assert_equal(0, @format.indent)
767
+
768
+ # valid arg -- Positive integers
769
+ [1, 10000000].each do |indent|
770
+ fmt = Writeexcel::Format.new
771
+ fmt.set_indent(indent)
772
+ assert_equal(indent, fmt.indent, "indent: #{indent}")
773
+ end
774
+
775
+ # invalid arg
776
+ [].each do |indent|
777
+
778
+ end
779
+ end
780
+
781
+ =begin
782
+ set_shrink()
783
+
784
+ Default state: Text shrinking is off
785
+ Default action: Turn "shrink to fit" on
786
+ Valid args: 1
787
+
788
+ This method can be used to shrink text so that it fits in a cell.
789
+
790
+ format = workbook.add_format()
791
+ format.set_shrink()
792
+ worksheet.write(0, 0, 'Honey, I shrunk the text!', format)
793
+ =end
794
+ def test_set_shrink
795
+ # default state
796
+ assert_equal(0, @format.shrink)
797
+ end
798
+
799
+ =begin
800
+ set_text_justlast()
801
+
802
+ Default state: Justify last is off
803
+ Default action: Turn justify last on
804
+ Valid args: 0, 1
805
+
806
+ Only applies to Far Eastern versions of Excel.
807
+ =end
808
+ def test_set_text_justlast
809
+ # default state
810
+ assert_equal(0, @format.text_justlast)
811
+ end
812
+
813
+ =begin
814
+ set_pattern()
815
+
816
+ Default state: Pattern is off
817
+ Default action: Solid fill is on
818
+ Valid args: 0 .. 18
819
+
820
+ Set the background pattern of a cell.
821
+ =end
822
+ def test_set_pattern
823
+ # default state
824
+ assert_equal(0, @format.pattern)
825
+ end
826
+
827
+ =begin
828
+ set_bg_color()
829
+
830
+ Default state: Color is off
831
+ Default action: Solid fill.
832
+ Valid args: See set_color()
833
+
834
+ The set_bg_color() method can be used to set the background
835
+ colour of a pattern. Patterns are defined via the set_pattern()
836
+ method. If a pattern hasn't been defined then a solid fill
837
+ pattern is used as the default.
838
+
839
+ Here is an example of how to set up a solid fill in a cell:
840
+
841
+ format = workbook.add_format()
842
+ format.set_pattern() # This is optional when using a solid fill
843
+ format.set_bg_color('green')
844
+ worksheet.write('A1', 'Ray', format)
845
+ =end
846
+ def test_set_bg_color
847
+ end
848
+
849
+ =begin
850
+ set_fg_color()
851
+
852
+ Default state: Color is off
853
+ Default action: Solid fill.
854
+ Valid args: See set_color()
855
+
856
+ The set_fg_color() method can be used to set
857
+ the foreground colour of a pattern.
858
+ =end
859
+ def test_set_fg_color
860
+ end
861
+
862
+ =begin
863
+ set_border()
864
+
865
+ Also applies to: set_bottom()
866
+ set_top()
867
+ set_left()
868
+ set_right()
869
+
870
+ Default state: Border is off
871
+ Default action: Set border type 1
872
+ Valid args: 0-13, See below.
873
+
874
+ A cell border is comprised of a border on the bottom, top,
875
+ left and right. These can be set to the same value using
876
+ set_border() or individually using the relevant method
877
+ calls shown above.
878
+
879
+ The following shows the border styles sorted
880
+ by WriteExcel index number:
881
+
882
+ Index Name Weight Style
883
+ ===== ============= ====== ===========
884
+ 0 None 0
885
+ 1 Continuous 1 -----------
886
+ 2 Continuous 2 -----------
887
+ 3 Dash 1 - - - - - -
888
+ 4 Dot 1 . . . . . .
889
+ 5 Continuous 3 -----------
890
+ 6 Double 3 ===========
891
+ 7 Continuous 0 -----------
892
+ 8 Dash 2 - - - - - -
893
+ 9 Dash Dot 1 - . - . - .
894
+ 10 Dash Dot 2 - . - . - .
895
+ 11 Dash Dot Dot 1 - . . - . .
896
+ 12 Dash Dot Dot 2 - . . - . .
897
+ 13 SlantDash Dot 2 / - . / - .
898
+
899
+ The following shows the borders sorted by style:
900
+
901
+ Name Weight Style Index
902
+ ============= ====== =========== =====
903
+ Continuous 0 ----------- 7
904
+ Continuous 1 ----------- 1
905
+ Continuous 2 ----------- 2
906
+ Continuous 3 ----------- 5
907
+ Dash 1 - - - - - - 3
908
+ Dash 2 - - - - - - 8
909
+ Dash Dot 1 - . - . - . 9
910
+ Dash Dot 2 - . - . - . 10
911
+ Dash Dot Dot 1 - . . - . . 11
912
+ Dash Dot Dot 2 - . . - . . 12
913
+ Dot 1 . . . . . . 4
914
+ Double 3 =========== 6
915
+ None 0 0
916
+ SlantDash Dot 2 / - . / - . 13
917
+
918
+ The following shows the borders in the order shown in the Excel Dialog.
919
+
920
+ Index Style Index Style
921
+ ===== ===== ===== =====
922
+ 0 None 12 - . . - . .
923
+ 7 ----------- 13 / - . / - .
924
+ 4 . . . . . . 10 - . - . - .
925
+ 11 - . . - . . 8 - - - - - -
926
+ 9 - . - . - . 2 -----------
927
+ 3 - - - - - - 5 -----------
928
+ 1 ----------- 6 ===========
929
+ =end
930
+ def test_set_border
931
+ end
932
+
933
+ =begin
934
+ set_border_color()
935
+
936
+ Also applies to: set_bottom_color()
937
+ set_top_color()
938
+ set_left_color()
939
+ set_right_color()
940
+
941
+ Default state: Color is off
942
+ Default action: Undefined
943
+ Valid args: See set_color()
944
+
945
+ Set the colour of the cell borders. A cell border is comprised of a border
946
+ on the bottom, top, left and right. These can be set to the same colour
947
+ using set_border_color() or individually using the relevant method
948
+ calls shown above.
949
+ =end
950
+ def test_set_border_color
951
+ end
952
+
953
+ =begin
954
+ copy($format)
955
+
956
+ This method is used to copy all of the properties
957
+ from one Format object to another:
958
+
959
+ lorry1 = workbook.add_format()
960
+ lorry1.set_bold()
961
+ lorry1.set_italic()
962
+ lorry1.set_color('red') # lorry1 is bold, italic and red
963
+
964
+ my lorry2 = workbook.add_format()
965
+ lorry2.copy(lorry1)
966
+ lorry2.set_color('yellow') # lorry2 is bold, italic and yellow
967
+
968
+ The copy() method is only useful if you are using the method interface
969
+ to Format properties. It generally isn't required if you are setting
970
+ Format properties directly using hashes.
971
+
972
+ Note: this is not a copy constructor, both objects must exist prior to copying.
973
+ =end
974
+
975
+ def test_xf_biff_size
976
+ perl_file = "#{PERL_OUTDIR}/file_xf_biff"
977
+ size = File.size(perl_file)
978
+ @ruby_file.print(@format.get_xf)
979
+ rsize = @ruby_file.size
980
+ assert_equal(size, rsize, "File sizes not the same")
981
+ end
982
+
983
+ # Because of the modifications to bg_color and fg_color, I know this
984
+ # test will fail. This is ok.
985
+ #def test_xf_biff_contents
986
+ # perl_file = "perl_output/f_xf_biff"
987
+ # @fh = File.new(@ruby_file,"w+")
988
+ # @fh.print(@format.xf_biff)
989
+ # @fh.close
990
+ # contents = IO.readlines(perl_file)
991
+ # rcontents = IO.readlines(@ruby_file)
992
+ # assert_equal(contents,rcontents,"Contents not the same")
993
+ #end
994
+
995
+ def test_font_biff_size
996
+ perl_file = "#{PERL_OUTDIR}/file_font_biff"
997
+ @ruby_file.print(@format.get_font)
998
+ contents = IO.readlines(perl_file)
999
+ @ruby_file.rewind
1000
+ rcontents = @ruby_file.readlines
1001
+ assert_equal(contents, rcontents, "Contents not the same")
1002
+ end
1003
+
1004
+ def test_font_biff_contents
1005
+ perl_file = "#{PERL_OUTDIR}/file_font_biff"
1006
+ @ruby_file.print(@format.get_font)
1007
+ contents = IO.readlines(perl_file)
1008
+ @ruby_file.rewind
1009
+ rcontents = @ruby_file.readlines
1010
+ assert_equal(contents, rcontents, "Contents not the same")
1011
+ end
1012
+
1013
+ def test_get_font_key_size
1014
+ perl_file = "#{PERL_OUTDIR}/file_font_key"
1015
+ @ruby_file.print(@format.get_font_key)
1016
+ assert_equal(File.size(perl_file), @ruby_file.size, "Bad file size")
1017
+ end
1018
+
1019
+ def test_get_font_key_contents
1020
+ perl_file = "#{PERL_OUTDIR}/file_font_key"
1021
+ @ruby_file.print(@format.get_font_key)
1022
+ contents = IO.readlines(perl_file)
1023
+ @ruby_file.rewind
1024
+ rcontents = @ruby_file.readlines
1025
+ assert_equal(contents, rcontents, "Contents not the same")
1026
+ end
1027
+
1028
+ def test_initialize
1029
+ assert_nothing_raised {
1030
+ Writeexcel::Format.new(
1031
+ :bold => true,
1032
+ :size => 10,
1033
+ :color => 'black',
1034
+ :fg_color => 43,
1035
+ :align => 'top',
1036
+ :text_wrap => true,
1037
+ :border => 1
1038
+ )
1039
+ }
1040
+ end
1041
+
1042
+ # added by Nakamura
1043
+
1044
+ def test_get_xf
1045
+ perl_file = "#{PERL_OUTDIR}/file_xf_biff"
1046
+ size = File.size(perl_file)
1047
+ @ruby_file.print(@format.get_xf)
1048
+ rsize = @ruby_file.size
1049
+ assert_equal(size, rsize, "File sizes not the same")
1050
+
1051
+ compare_file(perl_file, @ruby_file)
1052
+ end
1053
+
1054
+ def test_get_font
1055
+ perl_file = "#{PERL_OUTDIR}/file_font_biff"
1056
+ size = File.size(perl_file)
1057
+ @ruby_file.print(@format.get_font)
1058
+ rsize = @ruby_file.size
1059
+ assert_equal(size, rsize, "File sizes not the same")
1060
+
1061
+ compare_file(perl_file, @ruby_file)
1062
+ end
1063
+
1064
+ def test_get_font_key
1065
+ perl_file = "#{PERL_OUTDIR}/file_font_key"
1066
+ size = File.size(perl_file)
1067
+ @ruby_file.print(@format.get_font_key)
1068
+ rsize = @ruby_file.size
1069
+ assert_equal(size, rsize, "File sizes not the same")
1070
+
1071
+ compare_file(perl_file, @ruby_file)
1072
+ end
1073
+
1074
+ def test_copy
1075
+ format1 = Writeexcel::Format.new
1076
+ format2 = Writeexcel::Format.new
1077
+
1078
+ format1.set_size(12)
1079
+
1080
+ format2.copy(format1)
1081
+
1082
+ assert_equal(format1.size, format2.size)
1083
+ end
1084
+
1085
+
1086
+ # -----------------------------------------------------------------------------
1087
+
1088
+ def get_valid_format_properties
1089
+ {
1090
+ :font => 'Times New Roman',
1091
+ :size => 30,
1092
+ :color => 8,
1093
+ :italic => 1,
1094
+ :underline => 1,
1095
+ :font_strikeout => 1,
1096
+ :font_script => 1,
1097
+ :font_outline => 1,
1098
+ :font_shadow => 1,
1099
+ :locked => 0,
1100
+ :hidden => 1,
1101
+ :text_wrap => 1,
1102
+ :text_justlast => 1,
1103
+ :indent => 2,
1104
+ :shrink => 1,
1105
+ :pattern => 18,
1106
+ :bg_color => 30,
1107
+ :fg_color => 63
1108
+ }
1109
+ end
1110
+
1111
+ def get_valid_color_string_number
1112
+ {
1113
+ :black => 8,
1114
+ :blue => 12,
1115
+ :brown => 16,
1116
+ :cyan => 15,
1117
+ :gray => 23,
1118
+ :green => 17,
1119
+ :lime => 11,
1120
+ :magenta => 14,
1121
+ :navy => 18,
1122
+ :orange => 53,
1123
+ :pink => 33,
1124
+ :purple => 20,
1125
+ :red => 10,
1126
+ :silver => 22,
1127
+ :white => 9,
1128
+ :yellow => 13
1129
+ }
1130
+ end
1131
+ # :rotation => -90,
1132
+ # :center_across => 1,
1133
+ # :align => 'left',
1134
+
1135
+ def get_format_property(format)
1136
+ text_h_align = {
1137
+ 1 => 'left',
1138
+ 2 => 'center/centre',
1139
+ 3 => 'right',
1140
+ 4 => 'fill',
1141
+ 5 => 'justiry',
1142
+ 6 => 'center_across/centre_across/merge',
1143
+ 7 => 'distributed/equal_space'
1144
+ }
1145
+
1146
+ text_v_align = {
1147
+ 0 => 'top',
1148
+ 1 => 'vcenter/vcentre',
1149
+ 2 => 'bottom',
1150
+ 3 => 'vjustify',
1151
+ 4 => 'vdistributed/vequal_space'
1152
+ }
1153
+
1154
+ return {
1155
+ :font => format.font,
1156
+ :size => format.size,
1157
+ :color => format.color,
1158
+ :bold => format.bold,
1159
+ :italic => format.italic,
1160
+ :underline => format.underline,
1161
+ :font_strikeout => format.font_strikeout,
1162
+ :font_script => format.font_script,
1163
+ :font_outline => format.font_outline,
1164
+ :font_shadow => format.font_shadow,
1165
+ :num_format => format.num_format,
1166
+ :locked => format.locked,
1167
+ :hidden => format.hidden,
1168
+ :align => format.text_h_align,
1169
+ :valign => format.text_v_align,
1170
+ :rotation => format.rotation,
1171
+ :text_wrap => format.text_wrap,
1172
+ :text_justlast => format.text_justlast,
1173
+ :center_across => format.text_h_align,
1174
+ :indent => format.indent,
1175
+ :shrink => format.shrink,
1176
+ :pattern => format.pattern,
1177
+ :bg_color => format.bg_color,
1178
+ :fg_color => format.fg_color,
1179
+ :bottom => format.bottom,
1180
+ :top => format.top,
1181
+ :left => format.left,
1182
+ :right => format.right,
1183
+ :bottom_color => format.bottom_color,
1184
+ :top_color => format.top_color,
1185
+ :left_color => format.left_color,
1186
+ :right_color => format.right_color
1187
+ }
1188
+ end
1189
+ end