writeexcel 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +1 -1
- data/.gitignore +24 -24
- data/README.rdoc +34 -55
- data/VERSION +1 -1
- data/charts/chartex.rb +316 -316
- data/charts/demo1.rb +46 -46
- data/charts/demo2.rb +65 -65
- data/charts/demo3.rb +117 -117
- data/charts/demo4.rb +119 -119
- data/charts/demo5.rb +48 -48
- data/examples/a_simple.rb +43 -43
- data/examples/autofilter.rb +265 -265
- data/examples/bigfile.rb +30 -30
- data/examples/chart_area.rb +121 -121
- data/examples/chart_bar.rb +120 -120
- data/examples/chart_column.rb +120 -120
- data/examples/chart_line.rb +120 -120
- data/examples/chart_pie.rb +108 -108
- data/examples/chart_scatter.rb +121 -121
- data/examples/chart_stock.rb +148 -148
- data/examples/chess.rb +142 -142
- data/examples/colors.rb +129 -129
- data/examples/comments1.rb +27 -27
- data/examples/comments2.rb +352 -352
- data/examples/copyformat.rb +52 -52
- data/examples/data_validate.rb +279 -279
- data/examples/date_time.rb +87 -87
- data/examples/defined_name.rb +32 -32
- data/examples/demo.rb +124 -124
- data/examples/diag_border.rb +36 -36
- data/examples/formats.rb +490 -490
- data/examples/formula_result.rb +30 -30
- data/examples/header.rb +137 -137
- data/examples/hide_sheet.rb +29 -29
- data/examples/hyperlink.rb +43 -43
- data/examples/images.rb +63 -63
- data/examples/indent.rb +31 -31
- data/examples/merge1.rb +40 -40
- data/examples/merge2.rb +45 -45
- data/examples/merge3.rb +66 -66
- data/examples/merge4.rb +83 -83
- data/examples/merge5.rb +80 -80
- data/examples/merge6.rb +67 -67
- data/examples/outline.rb +255 -255
- data/examples/outline_collapsed.rb +209 -209
- data/examples/panes.rb +113 -113
- data/examples/properties.rb +34 -34
- data/examples/properties_jp.rb +33 -33
- data/examples/protection.rb +47 -47
- data/examples/regions.rb +53 -53
- data/examples/repeat.rb +43 -43
- data/examples/right_to_left.rb +27 -27
- data/examples/row_wrap.rb +53 -53
- data/examples/stats.rb +74 -74
- data/examples/stocks.rb +81 -81
- data/examples/tab_colors.rb +31 -31
- data/examples/utf8.rb +15 -15
- data/examples/write_arrays.rb +83 -83
- data/lib/writeexcel/biffwriter.rb +232 -232
- data/lib/writeexcel/caller_info.rb +12 -12
- data/lib/writeexcel/chart.rb +2190 -2177
- data/lib/writeexcel/charts/area.rb +154 -154
- data/lib/writeexcel/charts/bar.rb +177 -177
- data/lib/writeexcel/charts/column.rb +156 -156
- data/lib/writeexcel/charts/external.rb +66 -66
- data/lib/writeexcel/charts/line.rb +154 -154
- data/lib/writeexcel/charts/pie.rb +169 -169
- data/lib/writeexcel/charts/scatter.rb +192 -192
- data/lib/writeexcel/charts/stock.rb +213 -213
- data/lib/writeexcel/colors.rb +64 -64
- data/lib/writeexcel/compatibility.rb +0 -255
- data/lib/writeexcel/debug_info.rb +37 -33
- data/lib/writeexcel/excelformulaparser.rb +587 -587
- data/lib/writeexcel/format.rb +13 -4
- data/lib/writeexcel/formula.rb +26 -9
- data/lib/writeexcel/helper.rb +68 -64
- data/lib/writeexcel/olewriter.rb +311 -311
- data/lib/writeexcel/properties.rb +242 -240
- data/lib/writeexcel/storage_lite.rb +984 -978
- data/lib/writeexcel/workbook.rb +3210 -3192
- data/lib/writeexcel/worksheet.rb +143 -51
- data/lib/writeexcel/write_file.rb +44 -40
- data/lib/writeexcel.rb +1159 -1159
- data/test/helper.rb +31 -28
- data/test/perl_output/README +31 -31
- data/test/test_00_IEEE_double.rb +13 -13
- data/test/test_01_add_worksheet.rb +10 -10
- data/test/test_02_merge_formats.rb +53 -53
- data/test/test_04_dimensions.rb +392 -392
- data/test/test_05_rows.rb +179 -179
- data/test/test_06_extsst.rb +77 -77
- data/test/test_11_date_time.rb +479 -479
- data/test/test_12_date_only.rb +501 -501
- data/test/test_13_date_seconds.rb +481 -481
- data/test/test_21_escher.rb +637 -637
- data/test/test_22_mso_drawing_group.rb +745 -745
- data/test/test_23_note.rb +73 -73
- data/test/test_24_txo.rb +75 -75
- data/test/test_25_position_object.rb +84 -84
- data/test/test_26_autofilter.rb +314 -314
- data/test/test_27_autofilter.rb +131 -131
- data/test/test_28_autofilter.rb +161 -161
- data/test/test_29_process_jpg.rb +683 -683
- data/test/test_30_validation_dval.rb +77 -77
- data/test/test_31_validation_dv_strings.rb +126 -126
- data/test/test_32_validation_dv_formula.rb +206 -206
- data/test/test_40_property_types.rb +188 -188
- data/test/test_41_properties.rb +235 -235
- data/test/test_42_set_properties.rb +437 -437
- data/test/test_50_name_stored.rb +299 -299
- data/test/test_51_name_print_area.rb +357 -357
- data/test/test_52_name_print_titles.rb +454 -454
- data/test/test_53_autofilter.rb +203 -203
- data/test/test_60_chart_generic.rb +578 -578
- data/test/test_61_chart_subclasses.rb +95 -95
- data/test/test_62_chart_formats.rb +272 -272
- data/test/test_63_chart_area_formats.rb +649 -649
- data/test/test_biff.rb +75 -75
- data/test/test_compatibility.rb +12 -627
- data/test/test_example_match.rb +3144 -3144
- data/test/test_formula.rb +61 -61
- data/test/test_ole.rb +106 -106
- data/test/test_storage_lite.rb +125 -125
- data/test/test_workbook.rb +139 -139
- data/test/test_worksheet.rb +110 -110
- data/utils/add_magic_comment.rb +80 -80
- data/writeexcel.gemspec +4 -6
- data/writeexcel.rdoc +58 -15
- metadata +9 -6
- data/test/test_new_encoding.rb +0 -205
data/examples/comments2.rb
CHANGED
@@ -1,352 +1,352 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
###############################################################################
|
5
|
-
#
|
6
|
-
# This example demonstrates writing cell comments.
|
7
|
-
#
|
8
|
-
# A cell comment is indicated in Excel by a small red triangle in the upper
|
9
|
-
# right-hand corner of the cell.
|
10
|
-
#
|
11
|
-
# Each of the worksheets demonstrates different features of cell comments.
|
12
|
-
#
|
13
|
-
# reverse('©'), November 2005, John McNamara, jmcnamara@cpan.org
|
14
|
-
#
|
15
|
-
# original written in Perl by John McNamara
|
16
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'writeexcel'
|
20
|
-
|
21
|
-
workbook = WriteExcel.new("comments2.xls")
|
22
|
-
text_wrap = workbook.add_format(:text_wrap => 1, :valign => 'top')
|
23
|
-
worksheet1 = workbook.add_worksheet
|
24
|
-
worksheet2 = workbook.add_worksheet
|
25
|
-
worksheet3 = workbook.add_worksheet
|
26
|
-
worksheet4 = workbook.add_worksheet
|
27
|
-
worksheet5 = workbook.add_worksheet
|
28
|
-
worksheet6 = workbook.add_worksheet
|
29
|
-
worksheet7 = workbook.add_worksheet
|
30
|
-
worksheet8 = workbook.add_worksheet
|
31
|
-
|
32
|
-
# Variables that we will use in each example.
|
33
|
-
cell_text = ''
|
34
|
-
comment = ''
|
35
|
-
|
36
|
-
###############################################################################
|
37
|
-
#
|
38
|
-
# Example 1. Demonstrates a simple cell comment without formatting and Unicode
|
39
|
-
# comments encoded as UTF-16 and as UTF-8.
|
40
|
-
#
|
41
|
-
|
42
|
-
# Set up some formatting.
|
43
|
-
worksheet1.set_column('C:C', 25)
|
44
|
-
worksheet1.set_row(2, 50)
|
45
|
-
worksheet1.set_row(5, 50)
|
46
|
-
|
47
|
-
# Simple ascii string.
|
48
|
-
cell_text = 'Hold the mouse over this cell to see the comment.'
|
49
|
-
|
50
|
-
comment = 'This is a comment.'
|
51
|
-
|
52
|
-
worksheet1.write('C3', cell_text, text_wrap)
|
53
|
-
worksheet1.write_comment('C3', comment)
|
54
|
-
|
55
|
-
# UTF-16 string.
|
56
|
-
cell_text = 'This is a UTF-16 comment.'
|
57
|
-
|
58
|
-
comment = [0x263a].pack("n")
|
59
|
-
|
60
|
-
worksheet1.write('C6', cell_text, text_wrap)
|
61
|
-
worksheet1.write_comment('C6', comment, :encoding => 1)
|
62
|
-
|
63
|
-
# UTF-8 string.
|
64
|
-
worksheet1.set_row(8, 50)
|
65
|
-
cell_text = 'This is a UTF-8 string.'
|
66
|
-
comment = '☺' # chr 0x263a in perl.
|
67
|
-
|
68
|
-
worksheet1.write('C9', cell_text, text_wrap)
|
69
|
-
worksheet1.write_comment('C9', comment)
|
70
|
-
|
71
|
-
###############################################################################
|
72
|
-
#
|
73
|
-
# Example 2. Demonstrates visible and hidden comments.
|
74
|
-
#
|
75
|
-
|
76
|
-
# Set up some formatting.
|
77
|
-
worksheet2.set_column('C:C', 25)
|
78
|
-
worksheet2.set_row(2, 50)
|
79
|
-
worksheet2.set_row(5, 50)
|
80
|
-
|
81
|
-
|
82
|
-
cell_text = 'This cell comment is visible.'
|
83
|
-
|
84
|
-
comment = 'Hello.'
|
85
|
-
|
86
|
-
worksheet2.write('C3', cell_text, text_wrap)
|
87
|
-
worksheet2.write_comment('C3', comment, :visible => 1)
|
88
|
-
|
89
|
-
|
90
|
-
cell_text = "This cell comment isn't visible (the default)."
|
91
|
-
|
92
|
-
comment = 'Hello.'
|
93
|
-
|
94
|
-
worksheet2.write('C6', cell_text, text_wrap)
|
95
|
-
worksheet2.write_comment('C6', comment)
|
96
|
-
|
97
|
-
###############################################################################
|
98
|
-
#
|
99
|
-
# Example 3. Demonstrates visible and hidden comments set at the worksheet
|
100
|
-
# level.
|
101
|
-
#
|
102
|
-
|
103
|
-
# Set up some formatting.
|
104
|
-
worksheet3.set_column('C:C', 25)
|
105
|
-
worksheet3.set_row(2, 50)
|
106
|
-
worksheet3.set_row(5, 50)
|
107
|
-
worksheet3.set_row(8, 50)
|
108
|
-
|
109
|
-
# Make all comments on the worksheet visible.
|
110
|
-
worksheet3.show_comments
|
111
|
-
|
112
|
-
cell_text = 'This cell comment is visible, explicitly.'
|
113
|
-
|
114
|
-
comment = 'Hello.'
|
115
|
-
|
116
|
-
worksheet3.write('C3', cell_text, text_wrap)
|
117
|
-
worksheet3.write_comment('C3', comment, :visible => 1)
|
118
|
-
|
119
|
-
|
120
|
-
cell_text = 'This cell comment is also visible because ' +
|
121
|
-
'we used show_comments().'
|
122
|
-
|
123
|
-
comment = 'Hello.'
|
124
|
-
|
125
|
-
worksheet3.write('C6', cell_text, text_wrap)
|
126
|
-
worksheet3.write_comment('C6', comment)
|
127
|
-
|
128
|
-
|
129
|
-
cell_text = 'However, we can still override it locally.'
|
130
|
-
|
131
|
-
comment = 'Hello.'
|
132
|
-
|
133
|
-
worksheet3.write('C9', cell_text, text_wrap)
|
134
|
-
worksheet3.write_comment('C9', comment, :visible => 0)
|
135
|
-
|
136
|
-
###############################################################################
|
137
|
-
#
|
138
|
-
# Example 4. Demonstrates changes to the comment box dimensions.
|
139
|
-
#
|
140
|
-
|
141
|
-
# Set up some formatting.
|
142
|
-
worksheet4.set_column('C:C', 25)
|
143
|
-
worksheet4.set_row(2, 50)
|
144
|
-
worksheet4.set_row(5, 50)
|
145
|
-
worksheet4.set_row(8, 50)
|
146
|
-
worksheet4.set_row(15, 50)
|
147
|
-
|
148
|
-
worksheet4.show_comments
|
149
|
-
|
150
|
-
cell_text = 'This cell comment is default size.'
|
151
|
-
|
152
|
-
comment = 'Hello.'
|
153
|
-
|
154
|
-
worksheet4.write('C3', cell_text, text_wrap)
|
155
|
-
worksheet4.write_comment('C3', comment)
|
156
|
-
|
157
|
-
|
158
|
-
cell_text = 'This cell comment is twice as wide.'
|
159
|
-
|
160
|
-
comment = 'Hello.'
|
161
|
-
|
162
|
-
worksheet4.write('C6', cell_text, text_wrap)
|
163
|
-
worksheet4.write_comment('C6', comment, :x_scale => 2)
|
164
|
-
|
165
|
-
|
166
|
-
cell_text = 'This cell comment is twice as high.'
|
167
|
-
|
168
|
-
comment = 'Hello.'
|
169
|
-
|
170
|
-
worksheet4.write('C9', cell_text, text_wrap)
|
171
|
-
worksheet4.write_comment('C9', comment, :y_scale => 2)
|
172
|
-
|
173
|
-
|
174
|
-
cell_text = 'This cell comment is scaled in both directions.'
|
175
|
-
|
176
|
-
comment = 'Hello.'
|
177
|
-
|
178
|
-
worksheet4.write('C16', cell_text, text_wrap)
|
179
|
-
worksheet4.write_comment('C16', comment, :x_scale => 1.2, :y_scale => 0.8)
|
180
|
-
|
181
|
-
|
182
|
-
cell_text = 'This cell comment has width and height specified in pixels.'
|
183
|
-
|
184
|
-
comment = 'Hello.'
|
185
|
-
|
186
|
-
worksheet4.write('C19', cell_text, text_wrap)
|
187
|
-
worksheet4.write_comment('C19', comment, :width => 200, :height => 20)
|
188
|
-
|
189
|
-
###############################################################################
|
190
|
-
#
|
191
|
-
# Example 5. Demonstrates changes to the cell comment position.
|
192
|
-
#
|
193
|
-
|
194
|
-
worksheet5.set_column('C:C', 25)
|
195
|
-
worksheet5.set_row(2, 50)
|
196
|
-
worksheet5.set_row(5, 50)
|
197
|
-
worksheet5.set_row(8, 50)
|
198
|
-
worksheet5.set_row(11, 50)
|
199
|
-
|
200
|
-
worksheet5.show_comments
|
201
|
-
|
202
|
-
cell_text = 'This cell comment is in the default position.'
|
203
|
-
|
204
|
-
comment = 'Hello.'
|
205
|
-
|
206
|
-
worksheet5.write('C3', cell_text, text_wrap)
|
207
|
-
worksheet5.write_comment('C3', comment)
|
208
|
-
|
209
|
-
|
210
|
-
cell_text = 'This cell comment has been moved to another cell.'
|
211
|
-
|
212
|
-
comment = 'Hello.'
|
213
|
-
|
214
|
-
worksheet5.write('C6', cell_text, text_wrap)
|
215
|
-
worksheet5.write_comment('C6', comment, :start_cell => 'E4')
|
216
|
-
|
217
|
-
|
218
|
-
cell_text = 'This cell comment has been moved to another cell.'
|
219
|
-
|
220
|
-
comment = 'Hello.'
|
221
|
-
|
222
|
-
worksheet5.write('C9', cell_text, text_wrap)
|
223
|
-
worksheet5.write_comment('C9', comment, :start_row => 8, :start_col => 4)
|
224
|
-
|
225
|
-
|
226
|
-
cell_text = 'This cell comment has been shifted within its default cell.'
|
227
|
-
|
228
|
-
comment = 'Hello.'
|
229
|
-
|
230
|
-
worksheet5.write('C12', cell_text, text_wrap)
|
231
|
-
worksheet5.write_comment('C12', comment, :x_offset => 30, :y_offset => 12)
|
232
|
-
|
233
|
-
###############################################################################
|
234
|
-
#
|
235
|
-
# Example 6. Demonstrates changes to the comment background colour.
|
236
|
-
#
|
237
|
-
|
238
|
-
worksheet6.set_column('C:C', 25)
|
239
|
-
worksheet6.set_row(2, 50)
|
240
|
-
worksheet6.set_row(5, 50)
|
241
|
-
worksheet6.set_row(8, 50)
|
242
|
-
|
243
|
-
worksheet6.show_comments
|
244
|
-
|
245
|
-
cell_text = 'This cell comment has a different colour.'
|
246
|
-
|
247
|
-
comment = 'Hello.'
|
248
|
-
|
249
|
-
worksheet6.write('C3', cell_text, text_wrap)
|
250
|
-
worksheet6.write_comment('C3', comment, :color => 'green')
|
251
|
-
|
252
|
-
|
253
|
-
cell_text = 'This cell comment has the default colour.'
|
254
|
-
|
255
|
-
comment = 'Hello.'
|
256
|
-
|
257
|
-
worksheet6.write('C6', cell_text, text_wrap)
|
258
|
-
worksheet6.write_comment('C6', comment)
|
259
|
-
|
260
|
-
cell_text = 'This cell comment has a different colour.'
|
261
|
-
|
262
|
-
comment = 'Hello.'
|
263
|
-
|
264
|
-
worksheet6.write('C9', cell_text, text_wrap)
|
265
|
-
worksheet6.write_comment('C9', comment, :color => 0x35)
|
266
|
-
|
267
|
-
###############################################################################
|
268
|
-
#
|
269
|
-
# Example 7. Demonstrates how to set the cell comment author.
|
270
|
-
#
|
271
|
-
|
272
|
-
worksheet7.set_column('C:C', 30)
|
273
|
-
worksheet7.set_row(2, 50)
|
274
|
-
worksheet7.set_row(5, 50)
|
275
|
-
worksheet7.set_row(8, 50)
|
276
|
-
worksheet7.set_row(11, 50)
|
277
|
-
|
278
|
-
author = ''
|
279
|
-
cell = 'C3'
|
280
|
-
|
281
|
-
cell_text = "Move the mouse over this cell and you will see 'Cell commented "+
|
282
|
-
"by #{author}' (blank) in the status bar at the bottom"
|
283
|
-
|
284
|
-
comment = 'Hello.'
|
285
|
-
|
286
|
-
worksheet7.write(cell, cell_text, text_wrap)
|
287
|
-
worksheet7.write_comment(cell, comment)
|
288
|
-
|
289
|
-
author = 'Perl'
|
290
|
-
cell = 'C6'
|
291
|
-
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
292
|
-
"by #{author}' in the status bar at the bottom"
|
293
|
-
|
294
|
-
comment = 'Hello.'
|
295
|
-
|
296
|
-
worksheet7.write(cell, cell_text, text_wrap)
|
297
|
-
worksheet7.write_comment(cell, comment, :author => author)
|
298
|
-
|
299
|
-
author = [0x20AC].pack("n") # UTF-16 Euro
|
300
|
-
cell = 'C9'
|
301
|
-
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
302
|
-
"by Euro' in the status bar at the bottom"
|
303
|
-
|
304
|
-
comment = 'Hello.'
|
305
|
-
|
306
|
-
worksheet7.write(cell, cell_text, text_wrap)
|
307
|
-
worksheet7.write_comment(cell, comment, :author => author,
|
308
|
-
:author_encoding => 1)
|
309
|
-
|
310
|
-
# UTF-8 string.
|
311
|
-
author = '☺' # smiley
|
312
|
-
cell = 'C12'
|
313
|
-
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
314
|
-
"by #{author}' in the status bar at the bottom"
|
315
|
-
comment = 'Hello.'
|
316
|
-
|
317
|
-
worksheet7.write(cell, cell_text, text_wrap)
|
318
|
-
worksheet7.write_comment(cell, comment, :author => author)
|
319
|
-
|
320
|
-
###############################################################################
|
321
|
-
#
|
322
|
-
# Example 8. Demonstrates the need to explicitly set the row height.
|
323
|
-
#
|
324
|
-
|
325
|
-
# Set up some formatting.
|
326
|
-
worksheet8.set_column('C:C', 25)
|
327
|
-
worksheet8.set_row(2, 80)
|
328
|
-
|
329
|
-
worksheet8.show_comments
|
330
|
-
|
331
|
-
cell_text = 'The height of this row has been adjusted explicitly using ' +
|
332
|
-
'set_row(). The size of the comment box is adjusted ' +
|
333
|
-
'accordingly by WriteExcel.'
|
334
|
-
|
335
|
-
comment = 'Hello.'
|
336
|
-
|
337
|
-
worksheet8.write('C3', cell_text, text_wrap)
|
338
|
-
worksheet8.write_comment('C3', comment)
|
339
|
-
|
340
|
-
cell_text = 'The height of this row has been adjusted by Excel due to the ' +
|
341
|
-
'text wrap property being set. Unfortunately this means that ' +
|
342
|
-
'the height of the row is unknown to WriteExcel at run time ' +
|
343
|
-
"and thus the comment box is stretched as well.\n\n" +
|
344
|
-
'Use set_row() to specify the row height explicitly to avoid ' +
|
345
|
-
'this problem.'
|
346
|
-
|
347
|
-
comment = 'Hello.'
|
348
|
-
|
349
|
-
worksheet8.write('C6', cell_text, text_wrap)
|
350
|
-
worksheet8.write_comment('C6', comment)
|
351
|
-
|
352
|
-
workbook.close
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
###############################################################################
|
5
|
+
#
|
6
|
+
# This example demonstrates writing cell comments.
|
7
|
+
#
|
8
|
+
# A cell comment is indicated in Excel by a small red triangle in the upper
|
9
|
+
# right-hand corner of the cell.
|
10
|
+
#
|
11
|
+
# Each of the worksheets demonstrates different features of cell comments.
|
12
|
+
#
|
13
|
+
# reverse('©'), November 2005, John McNamara, jmcnamara@cpan.org
|
14
|
+
#
|
15
|
+
# original written in Perl by John McNamara
|
16
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'writeexcel'
|
20
|
+
|
21
|
+
workbook = WriteExcel.new("comments2.xls")
|
22
|
+
text_wrap = workbook.add_format(:text_wrap => 1, :valign => 'top')
|
23
|
+
worksheet1 = workbook.add_worksheet
|
24
|
+
worksheet2 = workbook.add_worksheet
|
25
|
+
worksheet3 = workbook.add_worksheet
|
26
|
+
worksheet4 = workbook.add_worksheet
|
27
|
+
worksheet5 = workbook.add_worksheet
|
28
|
+
worksheet6 = workbook.add_worksheet
|
29
|
+
worksheet7 = workbook.add_worksheet
|
30
|
+
worksheet8 = workbook.add_worksheet
|
31
|
+
|
32
|
+
# Variables that we will use in each example.
|
33
|
+
cell_text = ''
|
34
|
+
comment = ''
|
35
|
+
|
36
|
+
###############################################################################
|
37
|
+
#
|
38
|
+
# Example 1. Demonstrates a simple cell comment without formatting and Unicode
|
39
|
+
# comments encoded as UTF-16 and as UTF-8.
|
40
|
+
#
|
41
|
+
|
42
|
+
# Set up some formatting.
|
43
|
+
worksheet1.set_column('C:C', 25)
|
44
|
+
worksheet1.set_row(2, 50)
|
45
|
+
worksheet1.set_row(5, 50)
|
46
|
+
|
47
|
+
# Simple ascii string.
|
48
|
+
cell_text = 'Hold the mouse over this cell to see the comment.'
|
49
|
+
|
50
|
+
comment = 'This is a comment.'
|
51
|
+
|
52
|
+
worksheet1.write('C3', cell_text, text_wrap)
|
53
|
+
worksheet1.write_comment('C3', comment)
|
54
|
+
|
55
|
+
# UTF-16 string.
|
56
|
+
cell_text = 'This is a UTF-16 comment.'
|
57
|
+
|
58
|
+
comment = [0x263a].pack("n")
|
59
|
+
|
60
|
+
worksheet1.write('C6', cell_text, text_wrap)
|
61
|
+
worksheet1.write_comment('C6', comment, :encoding => 1)
|
62
|
+
|
63
|
+
# UTF-8 string.
|
64
|
+
worksheet1.set_row(8, 50)
|
65
|
+
cell_text = 'This is a UTF-8 string.'
|
66
|
+
comment = '☺' # chr 0x263a in perl.
|
67
|
+
|
68
|
+
worksheet1.write('C9', cell_text, text_wrap)
|
69
|
+
worksheet1.write_comment('C9', comment)
|
70
|
+
|
71
|
+
###############################################################################
|
72
|
+
#
|
73
|
+
# Example 2. Demonstrates visible and hidden comments.
|
74
|
+
#
|
75
|
+
|
76
|
+
# Set up some formatting.
|
77
|
+
worksheet2.set_column('C:C', 25)
|
78
|
+
worksheet2.set_row(2, 50)
|
79
|
+
worksheet2.set_row(5, 50)
|
80
|
+
|
81
|
+
|
82
|
+
cell_text = 'This cell comment is visible.'
|
83
|
+
|
84
|
+
comment = 'Hello.'
|
85
|
+
|
86
|
+
worksheet2.write('C3', cell_text, text_wrap)
|
87
|
+
worksheet2.write_comment('C3', comment, :visible => 1)
|
88
|
+
|
89
|
+
|
90
|
+
cell_text = "This cell comment isn't visible (the default)."
|
91
|
+
|
92
|
+
comment = 'Hello.'
|
93
|
+
|
94
|
+
worksheet2.write('C6', cell_text, text_wrap)
|
95
|
+
worksheet2.write_comment('C6', comment)
|
96
|
+
|
97
|
+
###############################################################################
|
98
|
+
#
|
99
|
+
# Example 3. Demonstrates visible and hidden comments set at the worksheet
|
100
|
+
# level.
|
101
|
+
#
|
102
|
+
|
103
|
+
# Set up some formatting.
|
104
|
+
worksheet3.set_column('C:C', 25)
|
105
|
+
worksheet3.set_row(2, 50)
|
106
|
+
worksheet3.set_row(5, 50)
|
107
|
+
worksheet3.set_row(8, 50)
|
108
|
+
|
109
|
+
# Make all comments on the worksheet visible.
|
110
|
+
worksheet3.show_comments
|
111
|
+
|
112
|
+
cell_text = 'This cell comment is visible, explicitly.'
|
113
|
+
|
114
|
+
comment = 'Hello.'
|
115
|
+
|
116
|
+
worksheet3.write('C3', cell_text, text_wrap)
|
117
|
+
worksheet3.write_comment('C3', comment, :visible => 1)
|
118
|
+
|
119
|
+
|
120
|
+
cell_text = 'This cell comment is also visible because ' +
|
121
|
+
'we used show_comments().'
|
122
|
+
|
123
|
+
comment = 'Hello.'
|
124
|
+
|
125
|
+
worksheet3.write('C6', cell_text, text_wrap)
|
126
|
+
worksheet3.write_comment('C6', comment)
|
127
|
+
|
128
|
+
|
129
|
+
cell_text = 'However, we can still override it locally.'
|
130
|
+
|
131
|
+
comment = 'Hello.'
|
132
|
+
|
133
|
+
worksheet3.write('C9', cell_text, text_wrap)
|
134
|
+
worksheet3.write_comment('C9', comment, :visible => 0)
|
135
|
+
|
136
|
+
###############################################################################
|
137
|
+
#
|
138
|
+
# Example 4. Demonstrates changes to the comment box dimensions.
|
139
|
+
#
|
140
|
+
|
141
|
+
# Set up some formatting.
|
142
|
+
worksheet4.set_column('C:C', 25)
|
143
|
+
worksheet4.set_row(2, 50)
|
144
|
+
worksheet4.set_row(5, 50)
|
145
|
+
worksheet4.set_row(8, 50)
|
146
|
+
worksheet4.set_row(15, 50)
|
147
|
+
|
148
|
+
worksheet4.show_comments
|
149
|
+
|
150
|
+
cell_text = 'This cell comment is default size.'
|
151
|
+
|
152
|
+
comment = 'Hello.'
|
153
|
+
|
154
|
+
worksheet4.write('C3', cell_text, text_wrap)
|
155
|
+
worksheet4.write_comment('C3', comment)
|
156
|
+
|
157
|
+
|
158
|
+
cell_text = 'This cell comment is twice as wide.'
|
159
|
+
|
160
|
+
comment = 'Hello.'
|
161
|
+
|
162
|
+
worksheet4.write('C6', cell_text, text_wrap)
|
163
|
+
worksheet4.write_comment('C6', comment, :x_scale => 2)
|
164
|
+
|
165
|
+
|
166
|
+
cell_text = 'This cell comment is twice as high.'
|
167
|
+
|
168
|
+
comment = 'Hello.'
|
169
|
+
|
170
|
+
worksheet4.write('C9', cell_text, text_wrap)
|
171
|
+
worksheet4.write_comment('C9', comment, :y_scale => 2)
|
172
|
+
|
173
|
+
|
174
|
+
cell_text = 'This cell comment is scaled in both directions.'
|
175
|
+
|
176
|
+
comment = 'Hello.'
|
177
|
+
|
178
|
+
worksheet4.write('C16', cell_text, text_wrap)
|
179
|
+
worksheet4.write_comment('C16', comment, :x_scale => 1.2, :y_scale => 0.8)
|
180
|
+
|
181
|
+
|
182
|
+
cell_text = 'This cell comment has width and height specified in pixels.'
|
183
|
+
|
184
|
+
comment = 'Hello.'
|
185
|
+
|
186
|
+
worksheet4.write('C19', cell_text, text_wrap)
|
187
|
+
worksheet4.write_comment('C19', comment, :width => 200, :height => 20)
|
188
|
+
|
189
|
+
###############################################################################
|
190
|
+
#
|
191
|
+
# Example 5. Demonstrates changes to the cell comment position.
|
192
|
+
#
|
193
|
+
|
194
|
+
worksheet5.set_column('C:C', 25)
|
195
|
+
worksheet5.set_row(2, 50)
|
196
|
+
worksheet5.set_row(5, 50)
|
197
|
+
worksheet5.set_row(8, 50)
|
198
|
+
worksheet5.set_row(11, 50)
|
199
|
+
|
200
|
+
worksheet5.show_comments
|
201
|
+
|
202
|
+
cell_text = 'This cell comment is in the default position.'
|
203
|
+
|
204
|
+
comment = 'Hello.'
|
205
|
+
|
206
|
+
worksheet5.write('C3', cell_text, text_wrap)
|
207
|
+
worksheet5.write_comment('C3', comment)
|
208
|
+
|
209
|
+
|
210
|
+
cell_text = 'This cell comment has been moved to another cell.'
|
211
|
+
|
212
|
+
comment = 'Hello.'
|
213
|
+
|
214
|
+
worksheet5.write('C6', cell_text, text_wrap)
|
215
|
+
worksheet5.write_comment('C6', comment, :start_cell => 'E4')
|
216
|
+
|
217
|
+
|
218
|
+
cell_text = 'This cell comment has been moved to another cell.'
|
219
|
+
|
220
|
+
comment = 'Hello.'
|
221
|
+
|
222
|
+
worksheet5.write('C9', cell_text, text_wrap)
|
223
|
+
worksheet5.write_comment('C9', comment, :start_row => 8, :start_col => 4)
|
224
|
+
|
225
|
+
|
226
|
+
cell_text = 'This cell comment has been shifted within its default cell.'
|
227
|
+
|
228
|
+
comment = 'Hello.'
|
229
|
+
|
230
|
+
worksheet5.write('C12', cell_text, text_wrap)
|
231
|
+
worksheet5.write_comment('C12', comment, :x_offset => 30, :y_offset => 12)
|
232
|
+
|
233
|
+
###############################################################################
|
234
|
+
#
|
235
|
+
# Example 6. Demonstrates changes to the comment background colour.
|
236
|
+
#
|
237
|
+
|
238
|
+
worksheet6.set_column('C:C', 25)
|
239
|
+
worksheet6.set_row(2, 50)
|
240
|
+
worksheet6.set_row(5, 50)
|
241
|
+
worksheet6.set_row(8, 50)
|
242
|
+
|
243
|
+
worksheet6.show_comments
|
244
|
+
|
245
|
+
cell_text = 'This cell comment has a different colour.'
|
246
|
+
|
247
|
+
comment = 'Hello.'
|
248
|
+
|
249
|
+
worksheet6.write('C3', cell_text, text_wrap)
|
250
|
+
worksheet6.write_comment('C3', comment, :color => 'green')
|
251
|
+
|
252
|
+
|
253
|
+
cell_text = 'This cell comment has the default colour.'
|
254
|
+
|
255
|
+
comment = 'Hello.'
|
256
|
+
|
257
|
+
worksheet6.write('C6', cell_text, text_wrap)
|
258
|
+
worksheet6.write_comment('C6', comment)
|
259
|
+
|
260
|
+
cell_text = 'This cell comment has a different colour.'
|
261
|
+
|
262
|
+
comment = 'Hello.'
|
263
|
+
|
264
|
+
worksheet6.write('C9', cell_text, text_wrap)
|
265
|
+
worksheet6.write_comment('C9', comment, :color => 0x35)
|
266
|
+
|
267
|
+
###############################################################################
|
268
|
+
#
|
269
|
+
# Example 7. Demonstrates how to set the cell comment author.
|
270
|
+
#
|
271
|
+
|
272
|
+
worksheet7.set_column('C:C', 30)
|
273
|
+
worksheet7.set_row(2, 50)
|
274
|
+
worksheet7.set_row(5, 50)
|
275
|
+
worksheet7.set_row(8, 50)
|
276
|
+
worksheet7.set_row(11, 50)
|
277
|
+
|
278
|
+
author = ''
|
279
|
+
cell = 'C3'
|
280
|
+
|
281
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented "+
|
282
|
+
"by #{author}' (blank) in the status bar at the bottom"
|
283
|
+
|
284
|
+
comment = 'Hello.'
|
285
|
+
|
286
|
+
worksheet7.write(cell, cell_text, text_wrap)
|
287
|
+
worksheet7.write_comment(cell, comment)
|
288
|
+
|
289
|
+
author = 'Perl'
|
290
|
+
cell = 'C6'
|
291
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
292
|
+
"by #{author}' in the status bar at the bottom"
|
293
|
+
|
294
|
+
comment = 'Hello.'
|
295
|
+
|
296
|
+
worksheet7.write(cell, cell_text, text_wrap)
|
297
|
+
worksheet7.write_comment(cell, comment, :author => author)
|
298
|
+
|
299
|
+
author = [0x20AC].pack("n") # UTF-16 Euro
|
300
|
+
cell = 'C9'
|
301
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
302
|
+
"by Euro' in the status bar at the bottom"
|
303
|
+
|
304
|
+
comment = 'Hello.'
|
305
|
+
|
306
|
+
worksheet7.write(cell, cell_text, text_wrap)
|
307
|
+
worksheet7.write_comment(cell, comment, :author => author,
|
308
|
+
:author_encoding => 1)
|
309
|
+
|
310
|
+
# UTF-8 string.
|
311
|
+
author = '☺' # smiley
|
312
|
+
cell = 'C12'
|
313
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
314
|
+
"by #{author}' in the status bar at the bottom"
|
315
|
+
comment = 'Hello.'
|
316
|
+
|
317
|
+
worksheet7.write(cell, cell_text, text_wrap)
|
318
|
+
worksheet7.write_comment(cell, comment, :author => author)
|
319
|
+
|
320
|
+
###############################################################################
|
321
|
+
#
|
322
|
+
# Example 8. Demonstrates the need to explicitly set the row height.
|
323
|
+
#
|
324
|
+
|
325
|
+
# Set up some formatting.
|
326
|
+
worksheet8.set_column('C:C', 25)
|
327
|
+
worksheet8.set_row(2, 80)
|
328
|
+
|
329
|
+
worksheet8.show_comments
|
330
|
+
|
331
|
+
cell_text = 'The height of this row has been adjusted explicitly using ' +
|
332
|
+
'set_row(). The size of the comment box is adjusted ' +
|
333
|
+
'accordingly by WriteExcel.'
|
334
|
+
|
335
|
+
comment = 'Hello.'
|
336
|
+
|
337
|
+
worksheet8.write('C3', cell_text, text_wrap)
|
338
|
+
worksheet8.write_comment('C3', comment)
|
339
|
+
|
340
|
+
cell_text = 'The height of this row has been adjusted by Excel due to the ' +
|
341
|
+
'text wrap property being set. Unfortunately this means that ' +
|
342
|
+
'the height of the row is unknown to WriteExcel at run time ' +
|
343
|
+
"and thus the comment box is stretched as well.\n\n" +
|
344
|
+
'Use set_row() to specify the row height explicitly to avoid ' +
|
345
|
+
'this problem.'
|
346
|
+
|
347
|
+
comment = 'Hello.'
|
348
|
+
|
349
|
+
worksheet8.write('C6', cell_text, text_wrap)
|
350
|
+
worksheet8.write_comment('C6', comment)
|
351
|
+
|
352
|
+
workbook.close
|