writeexcel 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/VERSION +1 -1
- data/examples/chess.rb +141 -0
- data/examples/colors.rb +128 -0
- data/examples/comments1.rb +26 -0
- data/examples/comments2.rb +351 -0
- data/lib/writeexcel/worksheet.rb +30 -36
- data/test/perl_output/chess.xls +0 -0
- data/test/perl_output/colors.xls +0 -0
- data/test/perl_output/comments1.xls +0 -0
- data/test/perl_output/comments2.xls +0 -0
- data/test/test_example_match.rb +589 -1
- data/writeexcel.gemspec +14 -2
- metadata +15 -3
data/test/test_example_match.rb
CHANGED
@@ -1949,11 +1949,599 @@ workbook.close
|
|
1949
1949
|
compare_file("#{PERL_OUTDIR}/chart_line.xls", @file)
|
1950
1950
|
end
|
1951
1951
|
|
1952
|
+
def test_chess
|
1953
|
+
workbook = WriteExcel.new(@file)
|
1954
|
+
worksheet = workbook.add_worksheet()
|
1955
|
+
|
1956
|
+
# Some row and column formatting
|
1957
|
+
worksheet.set_column('B:I', 10)
|
1958
|
+
|
1959
|
+
(1..8).each { |i| worksheet.set_row(i, 50) }
|
1960
|
+
|
1961
|
+
# Define the property hashes
|
1962
|
+
#
|
1963
|
+
black = {
|
1964
|
+
'fg_color' => 'black',
|
1965
|
+
'pattern' => 1,
|
1966
|
+
}
|
1967
|
+
|
1968
|
+
top = { 'top' => 6 }
|
1969
|
+
bottom = { 'bottom' => 6 }
|
1970
|
+
left = { 'left' => 6 }
|
1971
|
+
right = { 'right' => 6 }
|
1972
|
+
|
1973
|
+
# Define the formats
|
1974
|
+
#
|
1975
|
+
format01 = workbook.add_format(top.merge(left))
|
1976
|
+
format02 = workbook.add_format(top.merge(black))
|
1977
|
+
format03 = workbook.add_format(top)
|
1978
|
+
format04 = workbook.add_format(top.merge(right).merge(black))
|
1979
|
+
|
1980
|
+
format05 = workbook.add_format(left)
|
1981
|
+
format06 = workbook.add_format(black)
|
1982
|
+
format07 = workbook.add_format
|
1983
|
+
format08 = workbook.add_format(right.merge(black))
|
1984
|
+
format09 = workbook.add_format(right)
|
1985
|
+
format10 = workbook.add_format(left.merge(black))
|
1986
|
+
|
1987
|
+
format11 = workbook.add_format(bottom.merge(left).merge(black))
|
1988
|
+
format12 = workbook.add_format(bottom)
|
1989
|
+
format13 = workbook.add_format(bottom.merge(black))
|
1990
|
+
format14 = workbook.add_format(bottom.merge(right))
|
1991
|
+
|
1992
|
+
|
1993
|
+
# Draw the pattern
|
1994
|
+
worksheet.write('B2', '', format01)
|
1995
|
+
worksheet.write('C2', '', format02)
|
1996
|
+
worksheet.write('D2', '', format03)
|
1997
|
+
worksheet.write('E2', '', format02)
|
1998
|
+
worksheet.write('F2', '', format03)
|
1999
|
+
worksheet.write('G2', '', format02)
|
2000
|
+
worksheet.write('H2', '', format03)
|
2001
|
+
worksheet.write('I2', '', format04)
|
2002
|
+
|
2003
|
+
worksheet.write('B3', '', format10)
|
2004
|
+
worksheet.write('C3', '', format07)
|
2005
|
+
worksheet.write('D3', '', format06)
|
2006
|
+
worksheet.write('E3', '', format07)
|
2007
|
+
worksheet.write('F3', '', format06)
|
2008
|
+
worksheet.write('G3', '', format07)
|
2009
|
+
worksheet.write('H3', '', format06)
|
2010
|
+
worksheet.write('I3', '', format09)
|
2011
|
+
|
2012
|
+
worksheet.write('B4', '', format05)
|
2013
|
+
worksheet.write('C4', '', format06)
|
2014
|
+
worksheet.write('D4', '', format07)
|
2015
|
+
worksheet.write('E4', '', format06)
|
2016
|
+
worksheet.write('F4', '', format07)
|
2017
|
+
worksheet.write('G4', '', format06)
|
2018
|
+
worksheet.write('H4', '', format07)
|
2019
|
+
worksheet.write('I4', '', format08)
|
2020
|
+
|
2021
|
+
worksheet.write('B5', '', format10)
|
2022
|
+
worksheet.write('C5', '', format07)
|
2023
|
+
worksheet.write('D5', '', format06)
|
2024
|
+
worksheet.write('E5', '', format07)
|
2025
|
+
worksheet.write('F5', '', format06)
|
2026
|
+
worksheet.write('G5', '', format07)
|
2027
|
+
worksheet.write('H5', '', format06)
|
2028
|
+
worksheet.write('I5', '', format09)
|
2029
|
+
|
2030
|
+
worksheet.write('B6', '', format05)
|
2031
|
+
worksheet.write('C6', '', format06)
|
2032
|
+
worksheet.write('D6', '', format07)
|
2033
|
+
worksheet.write('E6', '', format06)
|
2034
|
+
worksheet.write('F6', '', format07)
|
2035
|
+
worksheet.write('G6', '', format06)
|
2036
|
+
worksheet.write('H6', '', format07)
|
2037
|
+
worksheet.write('I6', '', format08)
|
2038
|
+
|
2039
|
+
worksheet.write('B7', '', format10)
|
2040
|
+
worksheet.write('C7', '', format07)
|
2041
|
+
worksheet.write('D7', '', format06)
|
2042
|
+
worksheet.write('E7', '', format07)
|
2043
|
+
worksheet.write('F7', '', format06)
|
2044
|
+
worksheet.write('G7', '', format07)
|
2045
|
+
worksheet.write('H7', '', format06)
|
2046
|
+
worksheet.write('I7', '', format09)
|
2047
|
+
|
2048
|
+
worksheet.write('B8', '', format05)
|
2049
|
+
worksheet.write('C8', '', format06)
|
2050
|
+
worksheet.write('D8', '', format07)
|
2051
|
+
worksheet.write('E8', '', format06)
|
2052
|
+
worksheet.write('F8', '', format07)
|
2053
|
+
worksheet.write('G8', '', format06)
|
2054
|
+
worksheet.write('H8', '', format07)
|
2055
|
+
worksheet.write('I8', '', format08)
|
2056
|
+
|
2057
|
+
worksheet.write('B9', '', format11)
|
2058
|
+
worksheet.write('C9', '', format12)
|
2059
|
+
worksheet.write('D9', '', format13)
|
2060
|
+
worksheet.write('E9', '', format12)
|
2061
|
+
worksheet.write('F9', '', format13)
|
2062
|
+
worksheet.write('G9', '', format12)
|
2063
|
+
worksheet.write('H9', '', format13)
|
2064
|
+
worksheet.write('I9', '', format14)
|
2065
|
+
|
2066
|
+
workbook.close
|
2067
|
+
|
2068
|
+
# do assertion
|
2069
|
+
compare_file("#{PERL_OUTDIR}/chess.xls", @file)
|
2070
|
+
end
|
2071
|
+
|
2072
|
+
def test_colors
|
2073
|
+
workbook = WriteExcel.new(@file)
|
2074
|
+
|
2075
|
+
# Some common formats
|
2076
|
+
center = workbook.add_format(:align => 'center')
|
2077
|
+
heading = workbook.add_format(:align => 'center', :bold => 1)
|
2078
|
+
|
2079
|
+
######################################################################
|
2080
|
+
#
|
2081
|
+
# Demonstrate the named colors.
|
2082
|
+
#
|
2083
|
+
|
2084
|
+
order = [
|
2085
|
+
0x21,
|
2086
|
+
0x0B,
|
2087
|
+
0x35,
|
2088
|
+
0x11,
|
2089
|
+
0x16,
|
2090
|
+
0x12,
|
2091
|
+
0x0D,
|
2092
|
+
0x10,
|
2093
|
+
0x17,
|
2094
|
+
0x09,
|
2095
|
+
0x0C,
|
2096
|
+
0x0F,
|
2097
|
+
0x0E,
|
2098
|
+
0x14,
|
2099
|
+
0x08,
|
2100
|
+
0x0A
|
2101
|
+
]
|
2102
|
+
|
2103
|
+
colors = {
|
2104
|
+
0x08 => 'black',
|
2105
|
+
0x0C => 'blue',
|
2106
|
+
0x10 => 'brown',
|
2107
|
+
0x0F => 'cyan',
|
2108
|
+
0x17 => 'gray',
|
2109
|
+
0x11 => 'green',
|
2110
|
+
0x0B => 'lime',
|
2111
|
+
0x0E => 'magenta',
|
2112
|
+
0x12 => 'navy',
|
2113
|
+
0x35 => 'orange',
|
2114
|
+
0x21 => 'pink',
|
2115
|
+
0x14 => 'purple',
|
2116
|
+
0x0A => 'red',
|
2117
|
+
0x16 => 'silver',
|
2118
|
+
0x09 => 'white',
|
2119
|
+
0x0D => 'yellow',
|
2120
|
+
}
|
2121
|
+
|
2122
|
+
worksheet1 = workbook.add_worksheet('Named colors')
|
2123
|
+
|
2124
|
+
worksheet1.set_column(0, 3, 15)
|
2125
|
+
|
2126
|
+
worksheet1.write(0, 0, "Index", heading)
|
2127
|
+
worksheet1.write(0, 1, "Index", heading)
|
2128
|
+
worksheet1.write(0, 2, "Name", heading)
|
2129
|
+
worksheet1.write(0, 3, "Color", heading)
|
2130
|
+
|
2131
|
+
i = 1
|
2132
|
+
|
2133
|
+
# original was colors.each....
|
2134
|
+
# order unmatch between perl and ruby (of cource, it's hash!)
|
2135
|
+
# so i use order array to match perl's xls order.
|
2136
|
+
#
|
2137
|
+
order.each do |index|
|
2138
|
+
format = workbook.add_format(
|
2139
|
+
:fg_color => colors[index],
|
2140
|
+
:pattern => 1,
|
2141
|
+
:border => 1
|
2142
|
+
)
|
2143
|
+
|
2144
|
+
worksheet1.write(i + 1, 0, index, center)
|
2145
|
+
worksheet1.write(i + 1, 1, sprintf("0x%02X", index), center)
|
2146
|
+
worksheet1.write(i + 1, 2, colors[index], center)
|
2147
|
+
worksheet1.write(i + 1, 3, '', format)
|
2148
|
+
i += 1
|
2149
|
+
end
|
2150
|
+
|
2151
|
+
######################################################################
|
2152
|
+
#
|
2153
|
+
# Demonstrate the standard Excel colors in the range 8..63.
|
2154
|
+
#
|
2155
|
+
|
2156
|
+
worksheet2 = workbook.add_worksheet('Standard colors')
|
2157
|
+
|
2158
|
+
worksheet2.set_column(0, 3, 15)
|
2159
|
+
|
2160
|
+
worksheet2.write(0, 0, "Index", heading)
|
2161
|
+
worksheet2.write(0, 1, "Index", heading)
|
2162
|
+
worksheet2.write(0, 2, "Color", heading)
|
2163
|
+
worksheet2.write(0, 3, "Name", heading)
|
2164
|
+
|
2165
|
+
(8..63).each do |i|
|
2166
|
+
format = workbook.add_format(
|
2167
|
+
:fg_color => i,
|
2168
|
+
:pattern => 1,
|
2169
|
+
:border => 1
|
2170
|
+
)
|
2171
|
+
|
2172
|
+
worksheet2.write((i - 7), 0, i, center)
|
2173
|
+
worksheet2.write((i - 7), 1, sprintf("0x%02X", i), center)
|
2174
|
+
worksheet2.write((i - 7), 2, '', format)
|
2175
|
+
|
2176
|
+
# Add the color names
|
2177
|
+
if colors.has_key?(i)
|
2178
|
+
worksheet2.write((i - 7), 3, colors[i], center)
|
2179
|
+
end
|
2180
|
+
end
|
2181
|
+
|
2182
|
+
workbook.close
|
2183
|
+
|
2184
|
+
# do assertion
|
2185
|
+
compare_file("#{PERL_OUTDIR}/colors.xls", @file)
|
2186
|
+
end
|
2187
|
+
|
2188
|
+
def test_comments1
|
2189
|
+
workbook = WriteExcel.new(@file)
|
2190
|
+
worksheet = workbook.add_worksheet
|
2191
|
+
|
2192
|
+
worksheet.write('A1', 'Hello')
|
2193
|
+
worksheet.write_comment('A1', 'This is a comment')
|
2194
|
+
|
2195
|
+
workbook.close
|
2196
|
+
|
2197
|
+
# do assertion
|
2198
|
+
compare_file("#{PERL_OUTDIR}/comments1.xls", @file)
|
2199
|
+
end
|
2200
|
+
|
2201
|
+
def test_comments2
|
2202
|
+
workbook = WriteExcel.new(@file)
|
2203
|
+
text_wrap = workbook.add_format(:text_wrap => 1, :valign => 'top')
|
2204
|
+
worksheet1 = workbook.add_worksheet
|
2205
|
+
worksheet2 = workbook.add_worksheet
|
2206
|
+
worksheet3 = workbook.add_worksheet
|
2207
|
+
worksheet4 = workbook.add_worksheet
|
2208
|
+
worksheet5 = workbook.add_worksheet
|
2209
|
+
worksheet6 = workbook.add_worksheet
|
2210
|
+
worksheet7 = workbook.add_worksheet
|
2211
|
+
worksheet8 = workbook.add_worksheet
|
2212
|
+
|
2213
|
+
# Variables that we will use in each example.
|
2214
|
+
cell_text = ''
|
2215
|
+
comment = ''
|
2216
|
+
|
2217
|
+
###############################################################################
|
2218
|
+
#
|
2219
|
+
# Example 1. Demonstrates a simple cell comment without formatting and Unicode
|
2220
|
+
# comments encoded as UTF-16 and as UTF-8.
|
2221
|
+
#
|
2222
|
+
|
2223
|
+
# Set up some formatting.
|
2224
|
+
worksheet1.set_column('C:C', 25)
|
2225
|
+
worksheet1.set_row(2, 50)
|
2226
|
+
worksheet1.set_row(5, 50)
|
2227
|
+
|
2228
|
+
# Simple ascii string.
|
2229
|
+
cell_text = 'Hold the mouse over this cell to see the comment.'
|
2230
|
+
|
2231
|
+
comment = 'This is a comment.'
|
2232
|
+
|
2233
|
+
worksheet1.write('C3', cell_text, text_wrap)
|
2234
|
+
worksheet1.write_comment('C3', comment)
|
2235
|
+
|
2236
|
+
# UTF-16 string.
|
2237
|
+
cell_text = 'This is a UTF-16 comment.'
|
2238
|
+
|
2239
|
+
comment = [0x263a].pack("n")
|
2240
|
+
|
2241
|
+
worksheet1.write('C6', cell_text, text_wrap)
|
2242
|
+
worksheet1.write_comment('C6', comment, :encoding => 1)
|
2243
|
+
|
2244
|
+
# UTF-8 string in perl 5.8.
|
2245
|
+
worksheet1.set_row(8, 50)
|
2246
|
+
cell_text = 'This is a UTF-8 string.'
|
2247
|
+
comment = '☺' # chr 0x263a in perl.
|
2248
|
+
|
2249
|
+
worksheet1.write('C9', cell_text, text_wrap)
|
2250
|
+
worksheet1.write_comment('C9', comment)
|
2251
|
+
|
2252
|
+
###############################################################################
|
2253
|
+
#
|
2254
|
+
# Example 2. Demonstrates visible and hidden comments.
|
2255
|
+
#
|
2256
|
+
|
2257
|
+
# Set up some formatting.
|
2258
|
+
worksheet2.set_column('C:C', 25)
|
2259
|
+
worksheet2.set_row(2, 50)
|
2260
|
+
worksheet2.set_row(5, 50)
|
2261
|
+
|
2262
|
+
|
2263
|
+
cell_text = 'This cell comment is visible.'
|
2264
|
+
|
2265
|
+
comment = 'Hello.'
|
2266
|
+
|
2267
|
+
worksheet2.write('C3', cell_text, text_wrap)
|
2268
|
+
worksheet2.write_comment('C3', comment, :visible => 1)
|
2269
|
+
|
2270
|
+
|
2271
|
+
cell_text = "This cell comment isn't visible (the default)."
|
2272
|
+
|
2273
|
+
comment = 'Hello.'
|
2274
|
+
|
2275
|
+
worksheet2.write('C6', cell_text, text_wrap)
|
2276
|
+
worksheet2.write_comment('C6', comment)
|
2277
|
+
|
2278
|
+
###############################################################################
|
2279
|
+
#
|
2280
|
+
# Example 3. Demonstrates visible and hidden comments set at the worksheet
|
2281
|
+
# level.
|
2282
|
+
#
|
2283
|
+
|
2284
|
+
# Set up some formatting.
|
2285
|
+
worksheet3.set_column('C:C', 25)
|
2286
|
+
worksheet3.set_row(2, 50)
|
2287
|
+
worksheet3.set_row(5, 50)
|
2288
|
+
worksheet3.set_row(8, 50)
|
2289
|
+
|
2290
|
+
# Make all comments on the worksheet visible.
|
2291
|
+
worksheet3.show_comments
|
2292
|
+
|
2293
|
+
cell_text = 'This cell comment is visible, explicitly.'
|
2294
|
+
|
2295
|
+
comment = 'Hello.'
|
2296
|
+
|
2297
|
+
worksheet3.write('C3', cell_text, text_wrap)
|
2298
|
+
worksheet3.write_comment('C3', comment, :visible => 1)
|
2299
|
+
|
2300
|
+
|
2301
|
+
cell_text = 'This cell comment is also visible because ' +
|
2302
|
+
'we used show_comments().'
|
2303
|
+
|
2304
|
+
comment = 'Hello.'
|
2305
|
+
|
2306
|
+
worksheet3.write('C6', cell_text, text_wrap)
|
2307
|
+
worksheet3.write_comment('C6', comment)
|
2308
|
+
|
2309
|
+
|
2310
|
+
cell_text = 'However, we can still override it locally.'
|
2311
|
+
|
2312
|
+
comment = 'Hello.'
|
2313
|
+
|
2314
|
+
worksheet3.write('C9', cell_text, text_wrap)
|
2315
|
+
worksheet3.write_comment('C9', comment, :visible => 0)
|
2316
|
+
|
2317
|
+
###############################################################################
|
2318
|
+
#
|
2319
|
+
# Example 4. Demonstrates changes to the comment box dimensions.
|
2320
|
+
#
|
2321
|
+
|
2322
|
+
# Set up some formatting.
|
2323
|
+
worksheet4.set_column('C:C', 25)
|
2324
|
+
worksheet4.set_row(2, 50)
|
2325
|
+
worksheet4.set_row(5, 50)
|
2326
|
+
worksheet4.set_row(8, 50)
|
2327
|
+
worksheet4.set_row(15, 50)
|
2328
|
+
|
2329
|
+
worksheet4.show_comments
|
2330
|
+
|
2331
|
+
cell_text = 'This cell comment is default size.'
|
2332
|
+
|
2333
|
+
comment = 'Hello.'
|
2334
|
+
|
2335
|
+
worksheet4.write('C3', cell_text, text_wrap)
|
2336
|
+
worksheet4.write_comment('C3', comment)
|
2337
|
+
|
2338
|
+
|
2339
|
+
cell_text = 'This cell comment is twice as wide.'
|
2340
|
+
|
2341
|
+
comment = 'Hello.'
|
2342
|
+
|
2343
|
+
worksheet4.write('C6', cell_text, text_wrap)
|
2344
|
+
worksheet4.write_comment('C6', comment, :x_scale => 2)
|
2345
|
+
|
2346
|
+
|
2347
|
+
cell_text = 'This cell comment is twice as high.'
|
2348
|
+
|
2349
|
+
comment = 'Hello.'
|
2350
|
+
|
2351
|
+
worksheet4.write('C9', cell_text, text_wrap)
|
2352
|
+
worksheet4.write_comment('C9', comment, :y_scale => 2)
|
2353
|
+
|
2354
|
+
|
2355
|
+
cell_text = 'This cell comment is scaled in both directions.'
|
2356
|
+
|
2357
|
+
comment = 'Hello.'
|
2358
|
+
|
2359
|
+
worksheet4.write('C16', cell_text, text_wrap)
|
2360
|
+
worksheet4.write_comment('C16', comment, :x_scale => 1.2, :y_scale => 0.8)
|
2361
|
+
|
2362
|
+
|
2363
|
+
cell_text = 'This cell comment has width and height specified in pixels.'
|
2364
|
+
|
2365
|
+
comment = 'Hello.'
|
2366
|
+
|
2367
|
+
worksheet4.write('C19', cell_text, text_wrap)
|
2368
|
+
worksheet4.write_comment('C19', comment, :width => 200, :height => 20)
|
2369
|
+
|
2370
|
+
###############################################################################
|
2371
|
+
#
|
2372
|
+
# Example 5. Demonstrates changes to the cell comment position.
|
2373
|
+
#
|
2374
|
+
|
2375
|
+
worksheet5.set_column('C:C', 25)
|
2376
|
+
worksheet5.set_row(2, 50)
|
2377
|
+
worksheet5.set_row(5, 50)
|
2378
|
+
worksheet5.set_row(8, 50)
|
2379
|
+
worksheet5.set_row(11, 50)
|
2380
|
+
|
2381
|
+
worksheet5.show_comments
|
2382
|
+
|
2383
|
+
cell_text = 'This cell comment is in the default position.'
|
2384
|
+
|
2385
|
+
comment = 'Hello.'
|
2386
|
+
|
2387
|
+
worksheet5.write('C3', cell_text, text_wrap)
|
2388
|
+
worksheet5.write_comment('C3', comment)
|
2389
|
+
|
2390
|
+
|
2391
|
+
cell_text = 'This cell comment has been moved to another cell.'
|
2392
|
+
|
2393
|
+
comment = 'Hello.'
|
2394
|
+
|
2395
|
+
worksheet5.write('C6', cell_text, text_wrap)
|
2396
|
+
worksheet5.write_comment('C6', comment, :start_cell => 'E4')
|
2397
|
+
|
2398
|
+
|
2399
|
+
cell_text = 'This cell comment has been moved to another cell.'
|
2400
|
+
|
2401
|
+
comment = 'Hello.'
|
2402
|
+
|
2403
|
+
worksheet5.write('C9', cell_text, text_wrap)
|
2404
|
+
worksheet5.write_comment('C9', comment, :start_row => 8, :start_col => 4)
|
2405
|
+
|
2406
|
+
|
2407
|
+
cell_text = 'This cell comment has been shifted within its default cell.'
|
2408
|
+
|
2409
|
+
comment = 'Hello.'
|
2410
|
+
|
2411
|
+
worksheet5.write('C12', cell_text, text_wrap)
|
2412
|
+
worksheet5.write_comment('C12', comment, :x_offset => 30, :y_offset => 12)
|
2413
|
+
|
2414
|
+
###############################################################################
|
2415
|
+
#
|
2416
|
+
# Example 6. Demonstrates changes to the comment background colour.
|
2417
|
+
#
|
2418
|
+
|
2419
|
+
worksheet6.set_column('C:C', 25)
|
2420
|
+
worksheet6.set_row(2, 50)
|
2421
|
+
worksheet6.set_row(5, 50)
|
2422
|
+
worksheet6.set_row(8, 50)
|
2423
|
+
|
2424
|
+
worksheet6.show_comments
|
2425
|
+
|
2426
|
+
cell_text = 'This cell comment has a different colour.'
|
2427
|
+
|
2428
|
+
comment = 'Hello.'
|
2429
|
+
|
2430
|
+
worksheet6.write('C3', cell_text, text_wrap)
|
2431
|
+
worksheet6.write_comment('C3', comment, :color => 'green')
|
2432
|
+
|
2433
|
+
|
2434
|
+
cell_text = 'This cell comment has the default colour.'
|
2435
|
+
|
2436
|
+
comment = 'Hello.'
|
2437
|
+
|
2438
|
+
worksheet6.write('C6', cell_text, text_wrap)
|
2439
|
+
worksheet6.write_comment('C6', comment)
|
2440
|
+
|
2441
|
+
cell_text = 'This cell comment has a different colour.'
|
2442
|
+
|
2443
|
+
comment = 'Hello.'
|
2444
|
+
|
2445
|
+
worksheet6.write('C9', cell_text, text_wrap)
|
2446
|
+
worksheet6.write_comment('C9', comment, :color => 0x35)
|
2447
|
+
|
2448
|
+
###############################################################################
|
2449
|
+
#
|
2450
|
+
# Example 7. Demonstrates how to set the cell comment author.
|
2451
|
+
#
|
2452
|
+
|
2453
|
+
worksheet7.set_column('C:C', 30)
|
2454
|
+
worksheet7.set_row(2, 50)
|
2455
|
+
worksheet7.set_row(5, 50)
|
2456
|
+
worksheet7.set_row(8, 50)
|
2457
|
+
worksheet7.set_row(11, 50)
|
2458
|
+
|
2459
|
+
author = ''
|
2460
|
+
cell = 'C3'
|
2461
|
+
|
2462
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented "+
|
2463
|
+
"by #{author}' (blank) in the status bar at the bottom"
|
2464
|
+
|
2465
|
+
comment = 'Hello.'
|
2466
|
+
|
2467
|
+
worksheet7.write(cell, cell_text, text_wrap)
|
2468
|
+
worksheet7.write_comment(cell, comment)
|
2469
|
+
|
2470
|
+
author = 'Perl'
|
2471
|
+
cell = 'C6'
|
2472
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
2473
|
+
"by #{author}' in the status bar at the bottom"
|
2474
|
+
|
2475
|
+
comment = 'Hello.'
|
2476
|
+
|
2477
|
+
worksheet7.write(cell, cell_text, text_wrap)
|
2478
|
+
worksheet7.write_comment(cell, comment, :author => author)
|
2479
|
+
|
2480
|
+
author = [0x20AC].pack("n") # UTF-16 Euro
|
2481
|
+
cell = 'C9'
|
2482
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
2483
|
+
"by Euro' in the status bar at the bottom"
|
2484
|
+
|
2485
|
+
comment = 'Hello.'
|
2486
|
+
|
2487
|
+
worksheet7.write(cell, cell_text, text_wrap)
|
2488
|
+
worksheet7.write_comment(cell, comment, :author => author,
|
2489
|
+
:author_encoding => 1)
|
2490
|
+
|
2491
|
+
# UTF-8 string in perl 5.8.
|
2492
|
+
author = '☺' # smiley
|
2493
|
+
cell = 'C12'
|
2494
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
2495
|
+
"by #{author}' in the status bar at the bottom"
|
2496
|
+
comment = 'Hello.'
|
2497
|
+
|
2498
|
+
worksheet7.write(cell, cell_text, text_wrap)
|
2499
|
+
worksheet7.write_comment(cell, comment, :author => author)
|
2500
|
+
|
2501
|
+
###############################################################################
|
2502
|
+
#
|
2503
|
+
# Example 8. Demonstrates the need to explicitly set the row height.
|
2504
|
+
#
|
2505
|
+
|
2506
|
+
# Set up some formatting.
|
2507
|
+
worksheet8.set_column('C:C', 25)
|
2508
|
+
worksheet8.set_row(2, 80)
|
2509
|
+
|
2510
|
+
worksheet8.show_comments
|
2511
|
+
|
2512
|
+
cell_text = 'The height of this row has been adjusted explicitly using ' +
|
2513
|
+
'set_row(). The size of the comment box is adjusted ' +
|
2514
|
+
'accordingly by WriteExcel.'
|
2515
|
+
|
2516
|
+
comment = 'Hello.'
|
2517
|
+
|
2518
|
+
worksheet8.write('C3', cell_text, text_wrap)
|
2519
|
+
worksheet8.write_comment('C3', comment)
|
2520
|
+
|
2521
|
+
cell_text = 'The height of this row has been adjusted by Excel due to the ' +
|
2522
|
+
'text wrap property being set. Unfortunately this means that ' +
|
2523
|
+
'the height of the row is unknown to WriteExcel at run time ' +
|
2524
|
+
"and thus the comment box is stretched as well.\n\n" +
|
2525
|
+
'Use set_row() to specify the row height explicitly to avoid ' +
|
2526
|
+
'this problem.'
|
2527
|
+
|
2528
|
+
comment = 'Hello.'
|
2529
|
+
|
2530
|
+
worksheet8.write('C6', cell_text, text_wrap)
|
2531
|
+
worksheet8.write_comment('C6', comment)
|
2532
|
+
|
2533
|
+
workbook.close
|
2534
|
+
|
2535
|
+
# do assertion
|
2536
|
+
compare_file("#{PERL_OUTDIR}/comments2.xls", @file)
|
2537
|
+
end
|
2538
|
+
|
1952
2539
|
def compare_file(expected, target)
|
1953
2540
|
# target is StringIO object.
|
1954
2541
|
assert_equal(
|
1955
2542
|
open(expected, 'rb') { |f| f.read },
|
1956
|
-
target.string
|
2543
|
+
target.string,
|
2544
|
+
"#{File.basename(expected)} doesn't match."
|
1957
2545
|
)
|
1958
2546
|
end
|
1959
2547
|
end
|
data/writeexcel.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{writeexcel}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Hideo NAKAMURA"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-07}
|
13
13
|
s.description = %q{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
14
|
s.email = %q{cxn03651@msj.biglobe.ne.jp}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,6 +42,10 @@ Gem::Specification.new do |s|
|
|
42
42
|
"examples/chart_pie.rb",
|
43
43
|
"examples/chart_scatter.rb",
|
44
44
|
"examples/chart_stock.rb",
|
45
|
+
"examples/chess.rb",
|
46
|
+
"examples/colors.rb",
|
47
|
+
"examples/comments1.rb",
|
48
|
+
"examples/comments2.rb",
|
45
49
|
"examples/copyformat.rb",
|
46
50
|
"examples/data_validate.rb",
|
47
51
|
"examples/date_time.rb",
|
@@ -107,6 +111,10 @@ Gem::Specification.new do |s|
|
|
107
111
|
"test/perl_output/chart_bar.xls",
|
108
112
|
"test/perl_output/chart_column.xls",
|
109
113
|
"test/perl_output/chart_line.xls",
|
114
|
+
"test/perl_output/chess.xls",
|
115
|
+
"test/perl_output/colors.xls",
|
116
|
+
"test/perl_output/comments1.xls",
|
117
|
+
"test/perl_output/comments2.xls",
|
110
118
|
"test/perl_output/data_validate.xls",
|
111
119
|
"test/perl_output/date_time.xls",
|
112
120
|
"test/perl_output/defined_name.xls",
|
@@ -250,6 +258,10 @@ Gem::Specification.new do |s|
|
|
250
258
|
"examples/chart_pie.rb",
|
251
259
|
"examples/chart_scatter.rb",
|
252
260
|
"examples/chart_stock.rb",
|
261
|
+
"examples/chess.rb",
|
262
|
+
"examples/colors.rb",
|
263
|
+
"examples/comments1.rb",
|
264
|
+
"examples/comments2.rb",
|
253
265
|
"examples/copyformat.rb",
|
254
266
|
"examples/data_validate.rb",
|
255
267
|
"examples/date_time.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 4
|
9
|
+
version: 0.3.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Hideo NAKAMURA
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-07 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -53,6 +53,10 @@ files:
|
|
53
53
|
- examples/chart_pie.rb
|
54
54
|
- examples/chart_scatter.rb
|
55
55
|
- examples/chart_stock.rb
|
56
|
+
- examples/chess.rb
|
57
|
+
- examples/colors.rb
|
58
|
+
- examples/comments1.rb
|
59
|
+
- examples/comments2.rb
|
56
60
|
- examples/copyformat.rb
|
57
61
|
- examples/data_validate.rb
|
58
62
|
- examples/date_time.rb
|
@@ -118,6 +122,10 @@ files:
|
|
118
122
|
- test/perl_output/chart_bar.xls
|
119
123
|
- test/perl_output/chart_column.xls
|
120
124
|
- test/perl_output/chart_line.xls
|
125
|
+
- test/perl_output/chess.xls
|
126
|
+
- test/perl_output/colors.xls
|
127
|
+
- test/perl_output/comments1.xls
|
128
|
+
- test/perl_output/comments2.xls
|
121
129
|
- test/perl_output/data_validate.xls
|
122
130
|
- test/perl_output/date_time.xls
|
123
131
|
- test/perl_output/defined_name.xls
|
@@ -285,6 +293,10 @@ test_files:
|
|
285
293
|
- examples/chart_pie.rb
|
286
294
|
- examples/chart_scatter.rb
|
287
295
|
- examples/chart_stock.rb
|
296
|
+
- examples/chess.rb
|
297
|
+
- examples/colors.rb
|
298
|
+
- examples/comments1.rb
|
299
|
+
- examples/comments2.rb
|
288
300
|
- examples/copyformat.rb
|
289
301
|
- examples/data_validate.rb
|
290
302
|
- examples/date_time.rb
|