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/stats.rb
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
###############################################################################
|
5
|
-
#
|
6
|
-
# This is a simple example of how to use functions with the
|
7
|
-
# WriteExcel module.
|
8
|
-
#
|
9
|
-
# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
|
10
|
-
#
|
11
|
-
# original written in Perl by John McNamara
|
12
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
13
|
-
#
|
14
|
-
|
15
|
-
require 'writeexcel'
|
16
|
-
xlsfile = 'stats.xls'
|
17
|
-
|
18
|
-
workbook = WriteExcel.new(xlsfile)
|
19
|
-
worksheet = workbook.add_worksheet('Test data')
|
20
|
-
|
21
|
-
# Set the column width for columns 1
|
22
|
-
worksheet.set_column(0, 0, 20)
|
23
|
-
|
24
|
-
|
25
|
-
# Create a format for the headings
|
26
|
-
format = workbook.add_format
|
27
|
-
format.set_bold
|
28
|
-
|
29
|
-
|
30
|
-
# Write the sample data
|
31
|
-
worksheet.write(0, 0, 'Sample', format)
|
32
|
-
worksheet.write(0, 1, 1)
|
33
|
-
worksheet.write(0, 2, 2)
|
34
|
-
worksheet.write(0, 3, 3)
|
35
|
-
worksheet.write(0, 4, 4)
|
36
|
-
worksheet.write(0, 5, 5)
|
37
|
-
worksheet.write(0, 6, 6)
|
38
|
-
worksheet.write(0, 7, 7)
|
39
|
-
worksheet.write(0, 8, 8)
|
40
|
-
|
41
|
-
worksheet.write(1, 0, 'Length', format)
|
42
|
-
worksheet.write(1, 1, 25.4)
|
43
|
-
worksheet.write(1, 2, 25.4)
|
44
|
-
worksheet.write(1, 3, 24.8)
|
45
|
-
worksheet.write(1, 4, 25.0)
|
46
|
-
worksheet.write(1, 5, 25.3)
|
47
|
-
worksheet.write(1, 6, 24.9)
|
48
|
-
worksheet.write(1, 7, 25.2)
|
49
|
-
worksheet.write(1, 8, 24.8)
|
50
|
-
|
51
|
-
# Write some statistical functions
|
52
|
-
worksheet.write(4, 0, 'Count', format)
|
53
|
-
worksheet.write(4, 1, '=COUNT(B1:I1)')
|
54
|
-
|
55
|
-
worksheet.write(5, 0, 'Sum', format)
|
56
|
-
worksheet.write(5, 1, '=SUM(B2:I2)')
|
57
|
-
|
58
|
-
worksheet.write(6, 0, 'Average', format)
|
59
|
-
worksheet.write(6, 1, '=AVERAGE(B2:I2)')
|
60
|
-
|
61
|
-
worksheet.write(7, 0, 'Min', format)
|
62
|
-
worksheet.write(7, 1, '=MIN(B2:I2)')
|
63
|
-
|
64
|
-
worksheet.write(8, 0, 'Max', format)
|
65
|
-
worksheet.write(8, 1, '=MAX(B2:I2)')
|
66
|
-
|
67
|
-
worksheet.write(9, 0, 'Standard Deviation', format)
|
68
|
-
worksheet.write(9, 1, '=STDEV(B2:I2)')
|
69
|
-
|
70
|
-
worksheet.write(10, 0, 'Kurtosis', format)
|
71
|
-
worksheet.write(10, 1, '=KURT(B2:I2)')
|
72
|
-
|
73
|
-
workbook.close
|
74
|
-
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
###############################################################################
|
5
|
+
#
|
6
|
+
# This is a simple example of how to use functions with the
|
7
|
+
# WriteExcel module.
|
8
|
+
#
|
9
|
+
# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
|
10
|
+
#
|
11
|
+
# original written in Perl by John McNamara
|
12
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'writeexcel'
|
16
|
+
xlsfile = 'stats.xls'
|
17
|
+
|
18
|
+
workbook = WriteExcel.new(xlsfile)
|
19
|
+
worksheet = workbook.add_worksheet('Test data')
|
20
|
+
|
21
|
+
# Set the column width for columns 1
|
22
|
+
worksheet.set_column(0, 0, 20)
|
23
|
+
|
24
|
+
|
25
|
+
# Create a format for the headings
|
26
|
+
format = workbook.add_format
|
27
|
+
format.set_bold
|
28
|
+
|
29
|
+
|
30
|
+
# Write the sample data
|
31
|
+
worksheet.write(0, 0, 'Sample', format)
|
32
|
+
worksheet.write(0, 1, 1)
|
33
|
+
worksheet.write(0, 2, 2)
|
34
|
+
worksheet.write(0, 3, 3)
|
35
|
+
worksheet.write(0, 4, 4)
|
36
|
+
worksheet.write(0, 5, 5)
|
37
|
+
worksheet.write(0, 6, 6)
|
38
|
+
worksheet.write(0, 7, 7)
|
39
|
+
worksheet.write(0, 8, 8)
|
40
|
+
|
41
|
+
worksheet.write(1, 0, 'Length', format)
|
42
|
+
worksheet.write(1, 1, 25.4)
|
43
|
+
worksheet.write(1, 2, 25.4)
|
44
|
+
worksheet.write(1, 3, 24.8)
|
45
|
+
worksheet.write(1, 4, 25.0)
|
46
|
+
worksheet.write(1, 5, 25.3)
|
47
|
+
worksheet.write(1, 6, 24.9)
|
48
|
+
worksheet.write(1, 7, 25.2)
|
49
|
+
worksheet.write(1, 8, 24.8)
|
50
|
+
|
51
|
+
# Write some statistical functions
|
52
|
+
worksheet.write(4, 0, 'Count', format)
|
53
|
+
worksheet.write(4, 1, '=COUNT(B1:I1)')
|
54
|
+
|
55
|
+
worksheet.write(5, 0, 'Sum', format)
|
56
|
+
worksheet.write(5, 1, '=SUM(B2:I2)')
|
57
|
+
|
58
|
+
worksheet.write(6, 0, 'Average', format)
|
59
|
+
worksheet.write(6, 1, '=AVERAGE(B2:I2)')
|
60
|
+
|
61
|
+
worksheet.write(7, 0, 'Min', format)
|
62
|
+
worksheet.write(7, 1, '=MIN(B2:I2)')
|
63
|
+
|
64
|
+
worksheet.write(8, 0, 'Max', format)
|
65
|
+
worksheet.write(8, 1, '=MAX(B2:I2)')
|
66
|
+
|
67
|
+
worksheet.write(9, 0, 'Standard Deviation', format)
|
68
|
+
worksheet.write(9, 1, '=STDEV(B2:I2)')
|
69
|
+
|
70
|
+
worksheet.write(10, 0, 'Kurtosis', format)
|
71
|
+
worksheet.write(10, 1, '=KURT(B2:I2)')
|
72
|
+
|
73
|
+
workbook.close
|
74
|
+
|
data/examples/stocks.rb
CHANGED
@@ -1,81 +1,81 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#!/usr/bin/ruby -w
|
3
|
-
|
4
|
-
###############################################################################
|
5
|
-
#
|
6
|
-
# Example of formatting using the WriteExcel module
|
7
|
-
#
|
8
|
-
# This example shows how to use a conditional numerical format
|
9
|
-
# with colours to indicate if a share price has gone up or down.
|
10
|
-
#
|
11
|
-
# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
|
12
|
-
#
|
13
|
-
# original written in Perl by John McNamara
|
14
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
15
|
-
#
|
16
|
-
|
17
|
-
require 'rubygems'
|
18
|
-
require 'writeexcel'
|
19
|
-
|
20
|
-
# Create a new workbook and add a worksheet
|
21
|
-
workbook = WriteExcel.new("stocks.xls")
|
22
|
-
worksheet = workbook.add_worksheet
|
23
|
-
|
24
|
-
# Set the column width for columns 1, 2, 3 and 4
|
25
|
-
worksheet.set_column(0, 3, 15)
|
26
|
-
|
27
|
-
|
28
|
-
# Create a format for the column headings
|
29
|
-
header = workbook.add_format
|
30
|
-
header.set_bold
|
31
|
-
header.set_size(12)
|
32
|
-
header.set_color('blue')
|
33
|
-
|
34
|
-
|
35
|
-
# Create a format for the stock price
|
36
|
-
f_price = workbook.add_format
|
37
|
-
f_price.set_align('left')
|
38
|
-
f_price.set_num_format('$0.00')
|
39
|
-
|
40
|
-
|
41
|
-
# Create a format for the stock volume
|
42
|
-
f_volume = workbook.add_format
|
43
|
-
f_volume.set_align('left')
|
44
|
-
f_volume.set_num_format('#,##0')
|
45
|
-
|
46
|
-
|
47
|
-
# Create a format for the price change. This is an example of a conditional
|
48
|
-
# format. The number is formatted as a percentage. If it is positive it is
|
49
|
-
# formatted in green, if it is negative it is formatted in red and if it is
|
50
|
-
# zero it is formatted as the default font colour (in this case black).
|
51
|
-
# Note: the [Green] format produces an unappealing lime green. Try
|
52
|
-
# [Color 10] instead for a dark green.
|
53
|
-
#
|
54
|
-
f_change = workbook.add_format
|
55
|
-
f_change.set_align('left')
|
56
|
-
f_change.set_num_format('[Green]0.0%;[Red]-0.0%;0.0%')
|
57
|
-
|
58
|
-
|
59
|
-
# Write out the data
|
60
|
-
worksheet.write(0, 0, 'Company', header)
|
61
|
-
worksheet.write(0, 1, 'Price', header)
|
62
|
-
worksheet.write(0, 2, 'Volume', header)
|
63
|
-
worksheet.write(0, 3, 'Change', header)
|
64
|
-
|
65
|
-
worksheet.write(1, 0, 'Damage Inc.' )
|
66
|
-
worksheet.write(1, 1, 30.25, f_price) # $30.25
|
67
|
-
worksheet.write(1, 2, 1234567, f_volume) # 1,234,567
|
68
|
-
worksheet.write(1, 3, 0.085, f_change) # 8.5% in green
|
69
|
-
|
70
|
-
worksheet.write(2, 0, 'Dump Corp.' )
|
71
|
-
worksheet.write(2, 1, 1.56, f_price) # $1.56
|
72
|
-
worksheet.write(2, 2, 7564, f_volume) # 7,564
|
73
|
-
worksheet.write(2, 3, -0.015, f_change) # -1.5% in red
|
74
|
-
|
75
|
-
worksheet.write(3, 0, 'Rev Ltd.' )
|
76
|
-
worksheet.write(3, 1, 0.13, f_price) # $0.13
|
77
|
-
worksheet.write(3, 2, 321, f_volume) # 321
|
78
|
-
worksheet.write(3, 3, 0, f_change) # 0 in the font color (black)
|
79
|
-
|
80
|
-
|
81
|
-
workbook.close
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#!/usr/bin/ruby -w
|
3
|
+
|
4
|
+
###############################################################################
|
5
|
+
#
|
6
|
+
# Example of formatting using the WriteExcel module
|
7
|
+
#
|
8
|
+
# This example shows how to use a conditional numerical format
|
9
|
+
# with colours to indicate if a share price has gone up or down.
|
10
|
+
#
|
11
|
+
# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
|
12
|
+
#
|
13
|
+
# original written in Perl by John McNamara
|
14
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
require 'writeexcel'
|
19
|
+
|
20
|
+
# Create a new workbook and add a worksheet
|
21
|
+
workbook = WriteExcel.new("stocks.xls")
|
22
|
+
worksheet = workbook.add_worksheet
|
23
|
+
|
24
|
+
# Set the column width for columns 1, 2, 3 and 4
|
25
|
+
worksheet.set_column(0, 3, 15)
|
26
|
+
|
27
|
+
|
28
|
+
# Create a format for the column headings
|
29
|
+
header = workbook.add_format
|
30
|
+
header.set_bold
|
31
|
+
header.set_size(12)
|
32
|
+
header.set_color('blue')
|
33
|
+
|
34
|
+
|
35
|
+
# Create a format for the stock price
|
36
|
+
f_price = workbook.add_format
|
37
|
+
f_price.set_align('left')
|
38
|
+
f_price.set_num_format('$0.00')
|
39
|
+
|
40
|
+
|
41
|
+
# Create a format for the stock volume
|
42
|
+
f_volume = workbook.add_format
|
43
|
+
f_volume.set_align('left')
|
44
|
+
f_volume.set_num_format('#,##0')
|
45
|
+
|
46
|
+
|
47
|
+
# Create a format for the price change. This is an example of a conditional
|
48
|
+
# format. The number is formatted as a percentage. If it is positive it is
|
49
|
+
# formatted in green, if it is negative it is formatted in red and if it is
|
50
|
+
# zero it is formatted as the default font colour (in this case black).
|
51
|
+
# Note: the [Green] format produces an unappealing lime green. Try
|
52
|
+
# [Color 10] instead for a dark green.
|
53
|
+
#
|
54
|
+
f_change = workbook.add_format
|
55
|
+
f_change.set_align('left')
|
56
|
+
f_change.set_num_format('[Green]0.0%;[Red]-0.0%;0.0%')
|
57
|
+
|
58
|
+
|
59
|
+
# Write out the data
|
60
|
+
worksheet.write(0, 0, 'Company', header)
|
61
|
+
worksheet.write(0, 1, 'Price', header)
|
62
|
+
worksheet.write(0, 2, 'Volume', header)
|
63
|
+
worksheet.write(0, 3, 'Change', header)
|
64
|
+
|
65
|
+
worksheet.write(1, 0, 'Damage Inc.' )
|
66
|
+
worksheet.write(1, 1, 30.25, f_price) # $30.25
|
67
|
+
worksheet.write(1, 2, 1234567, f_volume) # 1,234,567
|
68
|
+
worksheet.write(1, 3, 0.085, f_change) # 8.5% in green
|
69
|
+
|
70
|
+
worksheet.write(2, 0, 'Dump Corp.' )
|
71
|
+
worksheet.write(2, 1, 1.56, f_price) # $1.56
|
72
|
+
worksheet.write(2, 2, 7564, f_volume) # 7,564
|
73
|
+
worksheet.write(2, 3, -0.015, f_change) # -1.5% in red
|
74
|
+
|
75
|
+
worksheet.write(3, 0, 'Rev Ltd.' )
|
76
|
+
worksheet.write(3, 1, 0.13, f_price) # $0.13
|
77
|
+
worksheet.write(3, 2, 321, f_volume) # 321
|
78
|
+
worksheet.write(3, 3, 0, f_change) # 0 in the font color (black)
|
79
|
+
|
80
|
+
|
81
|
+
workbook.close
|
data/examples/tab_colors.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
#######################################################################
|
5
|
-
#
|
6
|
-
# Example of how to set Excel worksheet tab colours.
|
7
|
-
#
|
8
|
-
# reverse('©'), May 2006, John McNamara, jmcnamara@cpan.org
|
9
|
-
#
|
10
|
-
# original written in Perl by John McNamara
|
11
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
12
|
-
#
|
13
|
-
|
14
|
-
require 'rubygems'
|
15
|
-
require 'writeexcel'
|
16
|
-
|
17
|
-
workbook = WriteExcel.new('tab_colors.xls')
|
18
|
-
|
19
|
-
worksheet1 = workbook.add_worksheet
|
20
|
-
worksheet2 = workbook.add_worksheet
|
21
|
-
worksheet3 = workbook.add_worksheet
|
22
|
-
worksheet4 = workbook.add_worksheet
|
23
|
-
|
24
|
-
# Worsheet1 will have the default tab colour.
|
25
|
-
worksheet2.set_tab_color('red')
|
26
|
-
worksheet3.set_tab_color('green')
|
27
|
-
worksheet4.set_tab_color(0x35) # Orange
|
28
|
-
|
29
|
-
workbook.close
|
30
|
-
|
31
|
-
workbook.close
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
#######################################################################
|
5
|
+
#
|
6
|
+
# Example of how to set Excel worksheet tab colours.
|
7
|
+
#
|
8
|
+
# reverse('©'), May 2006, John McNamara, jmcnamara@cpan.org
|
9
|
+
#
|
10
|
+
# original written in Perl by John McNamara
|
11
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'writeexcel'
|
16
|
+
|
17
|
+
workbook = WriteExcel.new('tab_colors.xls')
|
18
|
+
|
19
|
+
worksheet1 = workbook.add_worksheet
|
20
|
+
worksheet2 = workbook.add_worksheet
|
21
|
+
worksheet3 = workbook.add_worksheet
|
22
|
+
worksheet4 = workbook.add_worksheet
|
23
|
+
|
24
|
+
# Worsheet1 will have the default tab colour.
|
25
|
+
worksheet2.set_tab_color('red')
|
26
|
+
worksheet3.set_tab_color('green')
|
27
|
+
worksheet4.set_tab_color(0x35) # Orange
|
28
|
+
|
29
|
+
workbook.close
|
30
|
+
|
31
|
+
workbook.close
|
data/examples/utf8.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
$debug = true
|
5
|
-
|
6
|
-
require 'writeexcel'
|
7
|
-
|
8
|
-
workbook = WriteExcel.new('utf8.xls')
|
9
|
-
worksheet = workbook.add_worksheet('シート1')
|
10
|
-
format = workbook.add_format(:font => 'MS 明朝')
|
11
|
-
worksheet.set_footer('フッター')
|
12
|
-
worksheet.set_header('ヘッダー')
|
13
|
-
worksheet.write('A1', 'UTF8文字列', format)
|
14
|
-
worksheet.write('A2', '=CONCATENATE(A1,"の連結")', format)
|
15
|
-
workbook.close
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
$debug = true
|
5
|
+
|
6
|
+
require 'writeexcel'
|
7
|
+
|
8
|
+
workbook = WriteExcel.new('utf8.xls')
|
9
|
+
worksheet = workbook.add_worksheet('シート1')
|
10
|
+
format = workbook.add_format(:font => 'MS 明朝')
|
11
|
+
worksheet.set_footer('フッター')
|
12
|
+
worksheet.set_header('ヘッダー')
|
13
|
+
worksheet.write('A1', 'UTF8文字列', format)
|
14
|
+
worksheet.write('A2', '=CONCATENATE(A1,"の連結")', format)
|
15
|
+
workbook.close
|
data/examples/write_arrays.rb
CHANGED
@@ -1,83 +1,83 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
#######################################################################
|
5
|
-
#
|
6
|
-
# Example of how to use the WriteExcel module to
|
7
|
-
# write 1D and 2D arrays of data.
|
8
|
-
#
|
9
|
-
require 'rubygems'
|
10
|
-
require 'writeexcel'
|
11
|
-
|
12
|
-
workbook = WriteExcel.new("write_arrays.xls")
|
13
|
-
worksheet1 = workbook.add_worksheet('Example 1')
|
14
|
-
worksheet2 = workbook.add_worksheet('Example 2')
|
15
|
-
worksheet3 = workbook.add_worksheet('Example 3')
|
16
|
-
worksheet4 = workbook.add_worksheet('Example 4')
|
17
|
-
worksheet5 = workbook.add_worksheet('Example 5')
|
18
|
-
worksheet6 = workbook.add_worksheet('Example 6')
|
19
|
-
worksheet7 = workbook.add_worksheet('Example 7')
|
20
|
-
worksheet8 = workbook.add_worksheet('Example 8')
|
21
|
-
|
22
|
-
format = workbook.add_format(:color => 'red', :bold => 1)
|
23
|
-
format_cmd = workbook.add_format(:color => 'blue', :bold => 1)
|
24
|
-
# Data arrays used in the following examples.
|
25
|
-
# undef values are written as blank cells (with format if specified).
|
26
|
-
#
|
27
|
-
array = [ 'one', 'two', nil, 'four' ]
|
28
|
-
|
29
|
-
array2d = [
|
30
|
-
['maggie', 'milly', 'molly', 'may' ],
|
31
|
-
[13, 14, 15, 16 ],
|
32
|
-
['shell', 'star', 'crab', 'stone'],
|
33
|
-
]
|
34
|
-
|
35
|
-
# 1. Write a row of data using an array.
|
36
|
-
#
|
37
|
-
# array[0] array[1] array[2]
|
38
|
-
worksheet1.write('A1', "worksheet1.write('A3', array)", format_cmd)
|
39
|
-
worksheet1.write('A3', array)
|
40
|
-
|
41
|
-
# 2. Write a data using an array of array.
|
42
|
-
#
|
43
|
-
# array[0]
|
44
|
-
# array[1]
|
45
|
-
# array[2]
|
46
|
-
worksheet2.write('A1', "worksheet2.write('A3', [ array ])", format_cmd)
|
47
|
-
worksheet2.write('A3', [ array ])
|
48
|
-
|
49
|
-
# 3. Write a row of data using an explicit write_row() method call.
|
50
|
-
# This is the same as calling write() in Ex. 1 above.
|
51
|
-
#
|
52
|
-
worksheet3.write('A1', "worksheet3.write_row('A3', array)", format_cmd)
|
53
|
-
worksheet3.write_row('A3', array)
|
54
|
-
|
55
|
-
# 4. Write a column of data using the write_col() method call.
|
56
|
-
# This is same as Ex. 2 above.
|
57
|
-
worksheet4.write('A1', "worksheet4.write_col('A3', array)", format_cmd)
|
58
|
-
worksheet4.write_col('A3', array)
|
59
|
-
|
60
|
-
# 5. Write a 2D array in col-row order.
|
61
|
-
# array[0][0] array[1][0] ...
|
62
|
-
# array[0][1] array[1][1] ...
|
63
|
-
# array[0][2] array[1][2] ...
|
64
|
-
worksheet5.write('A1', "worksheet5.write('A3', array2d)", format_cmd)
|
65
|
-
worksheet5.write('A3', array2d)
|
66
|
-
|
67
|
-
# 6. Write a 2D array in row-col order using array of 2D array.
|
68
|
-
# array[0][0] array[0][1] ...
|
69
|
-
# array[1][0] array[1][1] ...
|
70
|
-
# array[2][0] array[2][1] ...
|
71
|
-
worksheet6.write('A1', "worksheet6.write('A3', [ array2d ] )", format_cmd)
|
72
|
-
worksheet6.write('A3', [ array2d ] )
|
73
|
-
|
74
|
-
# 7. Write a 2D array in row-col order using write_col().
|
75
|
-
# This is same as Ex. 6 above.
|
76
|
-
worksheet7.write('A1', "worksheet7.write_col('A3', array2d)", format_cmd)
|
77
|
-
worksheet7.write_col('A3', array2d)
|
78
|
-
|
79
|
-
# 8. Write a row of data with formatting. The blank cell is also formatted.
|
80
|
-
worksheet8.write('A1', "worksheet8.write('A3', array, format)", format_cmd)
|
81
|
-
worksheet8.write('A3', array, format)
|
82
|
-
|
83
|
-
workbook.close
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
#######################################################################
|
5
|
+
#
|
6
|
+
# Example of how to use the WriteExcel module to
|
7
|
+
# write 1D and 2D arrays of data.
|
8
|
+
#
|
9
|
+
require 'rubygems'
|
10
|
+
require 'writeexcel'
|
11
|
+
|
12
|
+
workbook = WriteExcel.new("write_arrays.xls")
|
13
|
+
worksheet1 = workbook.add_worksheet('Example 1')
|
14
|
+
worksheet2 = workbook.add_worksheet('Example 2')
|
15
|
+
worksheet3 = workbook.add_worksheet('Example 3')
|
16
|
+
worksheet4 = workbook.add_worksheet('Example 4')
|
17
|
+
worksheet5 = workbook.add_worksheet('Example 5')
|
18
|
+
worksheet6 = workbook.add_worksheet('Example 6')
|
19
|
+
worksheet7 = workbook.add_worksheet('Example 7')
|
20
|
+
worksheet8 = workbook.add_worksheet('Example 8')
|
21
|
+
|
22
|
+
format = workbook.add_format(:color => 'red', :bold => 1)
|
23
|
+
format_cmd = workbook.add_format(:color => 'blue', :bold => 1)
|
24
|
+
# Data arrays used in the following examples.
|
25
|
+
# undef values are written as blank cells (with format if specified).
|
26
|
+
#
|
27
|
+
array = [ 'one', 'two', nil, 'four' ]
|
28
|
+
|
29
|
+
array2d = [
|
30
|
+
['maggie', 'milly', 'molly', 'may' ],
|
31
|
+
[13, 14, 15, 16 ],
|
32
|
+
['shell', 'star', 'crab', 'stone'],
|
33
|
+
]
|
34
|
+
|
35
|
+
# 1. Write a row of data using an array.
|
36
|
+
#
|
37
|
+
# array[0] array[1] array[2]
|
38
|
+
worksheet1.write('A1', "worksheet1.write('A3', array)", format_cmd)
|
39
|
+
worksheet1.write('A3', array)
|
40
|
+
|
41
|
+
# 2. Write a data using an array of array.
|
42
|
+
#
|
43
|
+
# array[0]
|
44
|
+
# array[1]
|
45
|
+
# array[2]
|
46
|
+
worksheet2.write('A1', "worksheet2.write('A3', [ array ])", format_cmd)
|
47
|
+
worksheet2.write('A3', [ array ])
|
48
|
+
|
49
|
+
# 3. Write a row of data using an explicit write_row() method call.
|
50
|
+
# This is the same as calling write() in Ex. 1 above.
|
51
|
+
#
|
52
|
+
worksheet3.write('A1', "worksheet3.write_row('A3', array)", format_cmd)
|
53
|
+
worksheet3.write_row('A3', array)
|
54
|
+
|
55
|
+
# 4. Write a column of data using the write_col() method call.
|
56
|
+
# This is same as Ex. 2 above.
|
57
|
+
worksheet4.write('A1', "worksheet4.write_col('A3', array)", format_cmd)
|
58
|
+
worksheet4.write_col('A3', array)
|
59
|
+
|
60
|
+
# 5. Write a 2D array in col-row order.
|
61
|
+
# array[0][0] array[1][0] ...
|
62
|
+
# array[0][1] array[1][1] ...
|
63
|
+
# array[0][2] array[1][2] ...
|
64
|
+
worksheet5.write('A1', "worksheet5.write('A3', array2d)", format_cmd)
|
65
|
+
worksheet5.write('A3', array2d)
|
66
|
+
|
67
|
+
# 6. Write a 2D array in row-col order using array of 2D array.
|
68
|
+
# array[0][0] array[0][1] ...
|
69
|
+
# array[1][0] array[1][1] ...
|
70
|
+
# array[2][0] array[2][1] ...
|
71
|
+
worksheet6.write('A1', "worksheet6.write('A3', [ array2d ] )", format_cmd)
|
72
|
+
worksheet6.write('A3', [ array2d ] )
|
73
|
+
|
74
|
+
# 7. Write a 2D array in row-col order using write_col().
|
75
|
+
# This is same as Ex. 6 above.
|
76
|
+
worksheet7.write('A1', "worksheet7.write_col('A3', array2d)", format_cmd)
|
77
|
+
worksheet7.write_col('A3', array2d)
|
78
|
+
|
79
|
+
# 8. Write a row of data with formatting. The blank cell is also formatted.
|
80
|
+
worksheet8.write('A1', "worksheet8.write('A3', array, format)", format_cmd)
|
81
|
+
worksheet8.write('A3', array, format)
|
82
|
+
|
83
|
+
workbook.close
|