writeexcel 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +26 -31
- data/examples/a_simple.rb +42 -42
- data/examples/{autofilters.rb → autofilter.rb} +264 -266
- data/examples/bigfile.rb +29 -0
- data/examples/chart_area.rb +120 -0
- data/examples/chart_bar.rb +119 -0
- data/examples/chart_column.rb +119 -0
- data/examples/chart_line.rb +119 -0
- data/examples/chart_pie.rb +107 -0
- data/examples/chart_scatter.rb +120 -0
- data/examples/chart_stock.rb +147 -0
- data/examples/copyformat.rb +51 -51
- data/examples/data_validate.rb +278 -278
- data/examples/date_time.rb +86 -86
- data/examples/defined_name.rb +31 -0
- data/examples/demo.rb +120 -118
- data/examples/diag_border.rb +35 -35
- data/examples/formats.rb +489 -489
- data/examples/header.rb +136 -136
- data/examples/hidden.rb +28 -28
- data/examples/hyperlink.rb +42 -42
- data/examples/images.rb +52 -52
- data/examples/merge1.rb +39 -39
- data/examples/merge2.rb +44 -44
- data/examples/merge3.rb +65 -65
- data/examples/merge4.rb +82 -82
- data/examples/merge5.rb +79 -79
- data/examples/properties.rb +33 -0
- data/examples/properties_jp.rb +32 -0
- data/examples/protection.rb +46 -46
- data/examples/regions.rb +52 -52
- data/examples/repeat.rb +42 -42
- data/examples/stats.rb +75 -75
- data/examples/stocks.rb +80 -80
- data/examples/tab_colors.rb +30 -30
- data/examples/write_arrays.rb +82 -0
- data/lib/writeexcel.rb +1134 -18
- data/lib/writeexcel/biffwriter.rb +273 -260
- data/lib/writeexcel/chart.rb +2306 -217
- data/lib/writeexcel/charts/area.rb +152 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +61 -0
- data/lib/writeexcel/charts/line.rb +152 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +211 -0
- data/lib/writeexcel/excelformulaparser.rb +208 -195
- data/lib/writeexcel/format.rb +1697 -1108
- data/lib/writeexcel/formula.rb +1050 -986
- data/lib/writeexcel/olewriter.rb +322 -322
- data/lib/writeexcel/properties.rb +251 -250
- data/lib/writeexcel/storage_lite.rb +968 -0
- data/lib/writeexcel/workbook.rb +3294 -2630
- data/lib/writeexcel/worksheet.rb +9012 -6377
- data/test/excelfile/Chart1.xls +0 -0
- data/test/excelfile/Chart2.xls +0 -0
- data/test/excelfile/Chart3.xls +0 -0
- data/test/excelfile/Chart4.xls +0 -0
- data/test/excelfile/Chart5.xls +0 -0
- data/test/perl_output/Chart1.xls.data +0 -0
- data/test/perl_output/Chart2.xls.data +0 -0
- data/test/perl_output/Chart3.xls.data +0 -0
- data/test/perl_output/Chart4.xls.data +0 -0
- data/test/perl_output/Chart5.xls.data +0 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/chart_area.xls +0 -0
- data/test/perl_output/chart_bar.xls +0 -0
- data/test/perl_output/chart_column.xls +0 -0
- data/test/perl_output/chart_line.xls +0 -0
- data/test/perl_output/data_validate.xls +0 -0
- data/test/perl_output/date_time.xls +0 -0
- data/test/perl_output/demo.xls +0 -0
- data/test/perl_output/demo101.bin +0 -0
- data/test/perl_output/demo201.bin +0 -0
- data/test/perl_output/demo301.bin +0 -0
- data/test/perl_output/demo401.bin +0 -0
- data/test/perl_output/demo501.bin +0 -0
- data/test/perl_output/diag_border.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/merge1.xls +0 -0
- data/test/perl_output/merge2.xls +0 -0
- data/test/perl_output/merge3.xls +0 -0
- data/test/perl_output/merge4.xls +0 -0
- data/test/perl_output/merge5.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/tab_colors.xls +0 -0
- data/test/perl_output/unicode_cyrillic.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/tc_all.rb +32 -31
- data/test/tc_biff.rb +104 -104
- data/test/tc_chart.rb +22 -22
- data/test/tc_example_match.rb +1944 -1280
- data/test/tc_format.rb +1254 -1267
- data/test/tc_formula.rb +63 -63
- data/test/tc_ole.rb +110 -110
- data/test/tc_storage_lite.rb +149 -0
- data/test/tc_workbook.rb +140 -115
- data/test/tc_worksheet.rb +115 -115
- data/test/test_00_IEEE_double.rb +14 -14
- data/test/test_01_add_worksheet.rb +12 -12
- data/test/test_02_merge_formats.rb +58 -58
- data/test/test_04_dimensions.rb +397 -397
- data/test/test_05_rows.rb +182 -182
- data/test/test_06_extsst.rb +80 -80
- data/test/test_11_date_time.rb +484 -484
- data/test/test_12_date_only.rb +506 -506
- data/test/test_13_date_seconds.rb +486 -486
- data/test/test_21_escher.rb +642 -629
- data/test/test_22_mso_drawing_group.rb +750 -739
- data/test/test_23_note.rb +78 -78
- data/test/test_24_txo.rb +80 -80
- data/test/test_25_position_object.rb +82 -0
- data/test/test_26_autofilter.rb +327 -327
- data/test/test_27_autofilter.rb +144 -144
- data/test/test_28_autofilter.rb +174 -174
- data/test/test_29_process_jpg.rb +681 -131
- data/test/test_30_validation_dval.rb +82 -82
- data/test/test_31_validation_dv_strings.rb +131 -131
- data/test/test_32_validation_dv_formula.rb +211 -211
- data/test/test_40_property_types.rb +191 -191
- data/test/test_41_properties.rb +238 -238
- data/test/test_42_set_properties.rb +442 -419
- data/test/test_50_name_stored.rb +305 -0
- data/test/test_51_name_print_area.rb +363 -0
- data/test/test_52_name_print_titles.rb +460 -0
- data/test/test_53_autofilter.rb +209 -0
- data/test/test_60_chart_generic.rb +576 -0
- data/test/test_61_chart_subclasses.rb +97 -0
- data/test/test_62_chart_formats.rb +270 -0
- data/test/test_63_chart_area_formats.rb +647 -0
- data/test/test_chartex.rb +35 -0
- data/test/ts_all.rb +46 -34
- data/writeexcel.gemspec +18 -0
- data/writeexcel.rdoc +583 -0
- metadata +162 -108
data/examples/header.rb
CHANGED
@@ -1,136 +1,136 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
######################################################################
|
4
|
-
#
|
5
|
-
# This program shows several examples of how to set up headers and
|
6
|
-
# footers with
|
7
|
-
#
|
8
|
-
# The control characters used in the header/footer strings are:
|
9
|
-
#
|
10
|
-
# Control Category Description
|
11
|
-
# ======= ======== ===========
|
12
|
-
# &L Justification Left
|
13
|
-
# &C Center
|
14
|
-
# &R Right
|
15
|
-
#
|
16
|
-
# &P Information Page number
|
17
|
-
# &N Total number of pages
|
18
|
-
# &D Date
|
19
|
-
# &T Time
|
20
|
-
# &F File name
|
21
|
-
# &A Worksheet name
|
22
|
-
#
|
23
|
-
# &fontsize Font Font size
|
24
|
-
# &"font,style" Font name and style
|
25
|
-
# &U Single underline
|
26
|
-
# &E Double underline
|
27
|
-
# &S Strikethrough
|
28
|
-
# &X Superscript
|
29
|
-
# &Y Subscript
|
30
|
-
#
|
31
|
-
# && Miscellaneous Literal ampersand &
|
32
|
-
#
|
33
|
-
#
|
34
|
-
# reverse('©'), March 2002, John McNamara, jmcnamara@cpan.org
|
35
|
-
#
|
36
|
-
# original written in Perl by John McNamara
|
37
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
38
|
-
#
|
39
|
-
|
40
|
-
require 'rubygems'
|
41
|
-
require 'writeexcel'
|
42
|
-
|
43
|
-
workbook =
|
44
|
-
preview = "Select Print Preview to see the header and footer"
|
45
|
-
|
46
|
-
|
47
|
-
######################################################################
|
48
|
-
#
|
49
|
-
# A simple example to start
|
50
|
-
#
|
51
|
-
worksheet1 = workbook.add_worksheet('Simple')
|
52
|
-
|
53
|
-
header1 = '&CHere is some centred text.'
|
54
|
-
|
55
|
-
footer1 = '&LHere is some left aligned text.'
|
56
|
-
|
57
|
-
|
58
|
-
worksheet1.set_header(header1)
|
59
|
-
worksheet1.set_footer(footer1)
|
60
|
-
|
61
|
-
worksheet1.set_column('A:A', 50)
|
62
|
-
worksheet1.write('A1', preview)
|
63
|
-
|
64
|
-
|
65
|
-
######################################################################
|
66
|
-
#
|
67
|
-
# This is an example of some of the header/footer variables.
|
68
|
-
#
|
69
|
-
worksheet2 = workbook.add_worksheet('Variables')
|
70
|
-
|
71
|
-
header2 = '&LPage &P of &N'+
|
72
|
-
'&CFilename: &F' +
|
73
|
-
'&RSheetname: &A'
|
74
|
-
|
75
|
-
footer2 = '&LCurrent date: &D'+
|
76
|
-
'&RCurrent time: &T'
|
77
|
-
|
78
|
-
worksheet2.set_header(header2)
|
79
|
-
worksheet2.set_footer(footer2)
|
80
|
-
|
81
|
-
|
82
|
-
worksheet2.set_column('A:A', 50)
|
83
|
-
worksheet2.write('A1', preview)
|
84
|
-
worksheet2.write('A21', "Next sheet")
|
85
|
-
worksheet2.set_h_pagebreaks(20)
|
86
|
-
|
87
|
-
|
88
|
-
######################################################################
|
89
|
-
#
|
90
|
-
# This example shows how to use more than one font
|
91
|
-
#
|
92
|
-
worksheet3 = workbook.add_worksheet('Mixed fonts')
|
93
|
-
|
94
|
-
header3 = '&C' +
|
95
|
-
'&"Courier New,Bold"Hello ' +
|
96
|
-
'&"Arial,Italic"World'
|
97
|
-
|
98
|
-
footer3 = '&C' +
|
99
|
-
'&"Symbol"e' +
|
100
|
-
'&"Arial" = mc&X2'
|
101
|
-
|
102
|
-
worksheet3.set_header(header3)
|
103
|
-
worksheet3.set_footer(footer3)
|
104
|
-
|
105
|
-
worksheet3.set_column('A:A', 50)
|
106
|
-
worksheet3.write('A1', preview)
|
107
|
-
|
108
|
-
|
109
|
-
######################################################################
|
110
|
-
#
|
111
|
-
# Example of line wrapping
|
112
|
-
#
|
113
|
-
worksheet4 = workbook.add_worksheet('Word wrap')
|
114
|
-
|
115
|
-
header4 = "&CHeading 1\nHeading 2\nHeading 3"
|
116
|
-
|
117
|
-
worksheet4.set_header(header4)
|
118
|
-
|
119
|
-
worksheet4.set_column('A:A', 50)
|
120
|
-
worksheet4.write('A1', preview)
|
121
|
-
|
122
|
-
|
123
|
-
######################################################################
|
124
|
-
#
|
125
|
-
# Example of inserting a literal ampersand &
|
126
|
-
#
|
127
|
-
worksheet5 = workbook.add_worksheet('Ampersand')
|
128
|
-
|
129
|
-
header5 = "&CCuriouser && Curiouser - Attorneys at Law"
|
130
|
-
|
131
|
-
worksheet5.set_header(header5)
|
132
|
-
|
133
|
-
worksheet5.set_column('A:A', 50)
|
134
|
-
worksheet5.write('A1', preview)
|
135
|
-
|
136
|
-
workbook.close
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
######################################################################
|
4
|
+
#
|
5
|
+
# This program shows several examples of how to set up headers and
|
6
|
+
# footers with WriteExcel.
|
7
|
+
#
|
8
|
+
# The control characters used in the header/footer strings are:
|
9
|
+
#
|
10
|
+
# Control Category Description
|
11
|
+
# ======= ======== ===========
|
12
|
+
# &L Justification Left
|
13
|
+
# &C Center
|
14
|
+
# &R Right
|
15
|
+
#
|
16
|
+
# &P Information Page number
|
17
|
+
# &N Total number of pages
|
18
|
+
# &D Date
|
19
|
+
# &T Time
|
20
|
+
# &F File name
|
21
|
+
# &A Worksheet name
|
22
|
+
#
|
23
|
+
# &fontsize Font Font size
|
24
|
+
# &"font,style" Font name and style
|
25
|
+
# &U Single underline
|
26
|
+
# &E Double underline
|
27
|
+
# &S Strikethrough
|
28
|
+
# &X Superscript
|
29
|
+
# &Y Subscript
|
30
|
+
#
|
31
|
+
# && Miscellaneous Literal ampersand &
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# reverse('©'), March 2002, John McNamara, jmcnamara@cpan.org
|
35
|
+
#
|
36
|
+
# original written in Perl by John McNamara
|
37
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
38
|
+
#
|
39
|
+
|
40
|
+
require 'rubygems'
|
41
|
+
require 'writeexcel'
|
42
|
+
|
43
|
+
workbook = WriteExcel.new("headers.xls")
|
44
|
+
preview = "Select Print Preview to see the header and footer"
|
45
|
+
|
46
|
+
|
47
|
+
######################################################################
|
48
|
+
#
|
49
|
+
# A simple example to start
|
50
|
+
#
|
51
|
+
worksheet1 = workbook.add_worksheet('Simple')
|
52
|
+
|
53
|
+
header1 = '&CHere is some centred text.'
|
54
|
+
|
55
|
+
footer1 = '&LHere is some left aligned text.'
|
56
|
+
|
57
|
+
|
58
|
+
worksheet1.set_header(header1)
|
59
|
+
worksheet1.set_footer(footer1)
|
60
|
+
|
61
|
+
worksheet1.set_column('A:A', 50)
|
62
|
+
worksheet1.write('A1', preview)
|
63
|
+
|
64
|
+
|
65
|
+
######################################################################
|
66
|
+
#
|
67
|
+
# This is an example of some of the header/footer variables.
|
68
|
+
#
|
69
|
+
worksheet2 = workbook.add_worksheet('Variables')
|
70
|
+
|
71
|
+
header2 = '&LPage &P of &N'+
|
72
|
+
'&CFilename: &F' +
|
73
|
+
'&RSheetname: &A'
|
74
|
+
|
75
|
+
footer2 = '&LCurrent date: &D'+
|
76
|
+
'&RCurrent time: &T'
|
77
|
+
|
78
|
+
worksheet2.set_header(header2)
|
79
|
+
worksheet2.set_footer(footer2)
|
80
|
+
|
81
|
+
|
82
|
+
worksheet2.set_column('A:A', 50)
|
83
|
+
worksheet2.write('A1', preview)
|
84
|
+
worksheet2.write('A21', "Next sheet")
|
85
|
+
worksheet2.set_h_pagebreaks(20)
|
86
|
+
|
87
|
+
|
88
|
+
######################################################################
|
89
|
+
#
|
90
|
+
# This example shows how to use more than one font
|
91
|
+
#
|
92
|
+
worksheet3 = workbook.add_worksheet('Mixed fonts')
|
93
|
+
|
94
|
+
header3 = '&C' +
|
95
|
+
'&"Courier New,Bold"Hello ' +
|
96
|
+
'&"Arial,Italic"World'
|
97
|
+
|
98
|
+
footer3 = '&C' +
|
99
|
+
'&"Symbol"e' +
|
100
|
+
'&"Arial" = mc&X2'
|
101
|
+
|
102
|
+
worksheet3.set_header(header3)
|
103
|
+
worksheet3.set_footer(footer3)
|
104
|
+
|
105
|
+
worksheet3.set_column('A:A', 50)
|
106
|
+
worksheet3.write('A1', preview)
|
107
|
+
|
108
|
+
|
109
|
+
######################################################################
|
110
|
+
#
|
111
|
+
# Example of line wrapping
|
112
|
+
#
|
113
|
+
worksheet4 = workbook.add_worksheet('Word wrap')
|
114
|
+
|
115
|
+
header4 = "&CHeading 1\nHeading 2\nHeading 3"
|
116
|
+
|
117
|
+
worksheet4.set_header(header4)
|
118
|
+
|
119
|
+
worksheet4.set_column('A:A', 50)
|
120
|
+
worksheet4.write('A1', preview)
|
121
|
+
|
122
|
+
|
123
|
+
######################################################################
|
124
|
+
#
|
125
|
+
# Example of inserting a literal ampersand &
|
126
|
+
#
|
127
|
+
worksheet5 = workbook.add_worksheet('Ampersand')
|
128
|
+
|
129
|
+
header5 = "&CCuriouser && Curiouser - Attorneys at Law"
|
130
|
+
|
131
|
+
worksheet5.set_header(header5)
|
132
|
+
|
133
|
+
worksheet5.set_column('A:A', 50)
|
134
|
+
worksheet5.write('A1', preview)
|
135
|
+
|
136
|
+
workbook.close
|
data/examples/hidden.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
#######################################################################
|
4
|
-
#
|
5
|
-
# Example of how to hide a worksheet with
|
6
|
-
#
|
7
|
-
# reverse('©'), April 2005, John McNamara, jmcnamara@cpan.org
|
8
|
-
#
|
9
|
-
# original written in Perl by John McNamara
|
10
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
11
|
-
#
|
12
|
-
require 'rubygems'
|
13
|
-
require 'writeexcel'
|
14
|
-
|
15
|
-
|
16
|
-
workbook =
|
17
|
-
worksheet1 = workbook.add_worksheet
|
18
|
-
worksheet2 = workbook.add_worksheet
|
19
|
-
worksheet3 = workbook.add_worksheet
|
20
|
-
|
21
|
-
# Sheet2 won't be visible until it is unhidden in Excel.
|
22
|
-
worksheet2.hide
|
23
|
-
|
24
|
-
worksheet1.write(0, 0, 'Sheet2 is hidden')
|
25
|
-
worksheet2.write(0, 0, 'How did you find me?')
|
26
|
-
worksheet3.write(0, 0, 'Sheet2 is hidden')
|
27
|
-
|
28
|
-
workbook.close
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
#######################################################################
|
4
|
+
#
|
5
|
+
# Example of how to hide a worksheet with WriteExcel.
|
6
|
+
#
|
7
|
+
# reverse('©'), April 2005, John McNamara, jmcnamara@cpan.org
|
8
|
+
#
|
9
|
+
# original written in Perl by John McNamara
|
10
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
11
|
+
#
|
12
|
+
require 'rubygems'
|
13
|
+
require 'writeexcel'
|
14
|
+
|
15
|
+
|
16
|
+
workbook = WriteExcel.new('hidden.xls')
|
17
|
+
worksheet1 = workbook.add_worksheet
|
18
|
+
worksheet2 = workbook.add_worksheet
|
19
|
+
worksheet3 = workbook.add_worksheet
|
20
|
+
|
21
|
+
# Sheet2 won't be visible until it is unhidden in Excel.
|
22
|
+
worksheet2.hide
|
23
|
+
|
24
|
+
worksheet1.write(0, 0, 'Sheet2 is hidden')
|
25
|
+
worksheet2.write(0, 0, 'How did you find me?')
|
26
|
+
worksheet3.write(0, 0, 'Sheet2 is hidden')
|
27
|
+
|
28
|
+
workbook.close
|
data/examples/hyperlink.rb
CHANGED
@@ -1,42 +1,42 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
###############################################################################
|
3
|
-
#
|
4
|
-
# Example of how to use the WriteExcel module to write hyperlinks
|
5
|
-
#
|
6
|
-
# See also hyperlink2.pl for worksheet URL examples.
|
7
|
-
#
|
8
|
-
# reverse('©'), March 2001, 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
|
-
require 'rubygems'
|
14
|
-
require 'writeexcel'
|
15
|
-
|
16
|
-
# Create a new workbook and add a worksheet
|
17
|
-
workbook =
|
18
|
-
worksheet = workbook.add_worksheet('Hyperlinks')
|
19
|
-
|
20
|
-
# Format the first column
|
21
|
-
worksheet.set_column('A:A', 30)
|
22
|
-
worksheet.set_selection('B1')
|
23
|
-
|
24
|
-
|
25
|
-
# Add a sample format
|
26
|
-
format = workbook.add_format
|
27
|
-
format.set_size(12)
|
28
|
-
format.set_bold
|
29
|
-
format.set_color('red')
|
30
|
-
format.set_underline
|
31
|
-
|
32
|
-
|
33
|
-
# Write some hyperlinks
|
34
|
-
worksheet.write('A1', 'http://www.perl.com/' )
|
35
|
-
worksheet.write('A3', 'http://www.perl.com/', 'Perl home' )
|
36
|
-
worksheet.write('A5', 'http://www.perl.com/', nil, format)
|
37
|
-
worksheet.write('A7', 'mailto:jmcnamara@cpan.org', 'Mail me')
|
38
|
-
|
39
|
-
# Write a URL that isn't a hyperlink
|
40
|
-
worksheet.write_string('A9', 'http://www.perl.com/')
|
41
|
-
|
42
|
-
workbook.close
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
###############################################################################
|
3
|
+
#
|
4
|
+
# Example of how to use the WriteExcel module to write hyperlinks
|
5
|
+
#
|
6
|
+
# See also hyperlink2.pl for worksheet URL examples.
|
7
|
+
#
|
8
|
+
# reverse('©'), March 2001, 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
|
+
require 'rubygems'
|
14
|
+
require 'writeexcel'
|
15
|
+
|
16
|
+
# Create a new workbook and add a worksheet
|
17
|
+
workbook = WriteExcel.new("hyperlink.xls")
|
18
|
+
worksheet = workbook.add_worksheet('Hyperlinks')
|
19
|
+
|
20
|
+
# Format the first column
|
21
|
+
worksheet.set_column('A:A', 30)
|
22
|
+
worksheet.set_selection('B1')
|
23
|
+
|
24
|
+
|
25
|
+
# Add a sample format
|
26
|
+
format = workbook.add_format
|
27
|
+
format.set_size(12)
|
28
|
+
format.set_bold
|
29
|
+
format.set_color('red')
|
30
|
+
format.set_underline
|
31
|
+
|
32
|
+
|
33
|
+
# Write some hyperlinks
|
34
|
+
worksheet.write('A1', 'http://www.perl.com/' )
|
35
|
+
worksheet.write('A3', 'http://www.perl.com/', 'Perl home' )
|
36
|
+
worksheet.write('A5', 'http://www.perl.com/', nil, format)
|
37
|
+
worksheet.write('A7', 'mailto:jmcnamara@cpan.org', 'Mail me')
|
38
|
+
|
39
|
+
# Write a URL that isn't a hyperlink
|
40
|
+
worksheet.write_string('A9', 'http://www.perl.com/')
|
41
|
+
|
42
|
+
workbook.close
|
data/examples/images.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
#######################################################################
|
4
|
-
#
|
5
|
-
# Example of how to insert images into an Excel worksheet using the
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# reverse('©'), October 2001, 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
|
-
# Create a new workbook called simple.xls and add a worksheet
|
18
|
-
workbook =
|
19
|
-
worksheet1 = workbook.add_worksheet('Image 1')
|
20
|
-
worksheet2 = workbook.add_worksheet('Image 2')
|
21
|
-
worksheet3 = workbook.add_worksheet('Image 3')
|
22
|
-
worksheet4 = workbook.add_worksheet('Image 4')
|
23
|
-
bp=1
|
24
|
-
|
25
|
-
# Insert a basic image
|
26
|
-
worksheet1.write('A10', "Image inserted into worksheet.")
|
27
|
-
worksheet1.insert_image('A1', 'republic.png')
|
28
|
-
|
29
|
-
|
30
|
-
# Insert an image with an offset
|
31
|
-
worksheet2.write('A10', "Image inserted with an offset.")
|
32
|
-
worksheet2.insert_image('A1', 'republic.png', 32, 10)
|
33
|
-
|
34
|
-
# Insert a scaled image
|
35
|
-
worksheet3.write('A10', "Image scaled: width x 2, height x 0.8.")
|
36
|
-
worksheet3.insert_image('A1', 'republic.png', 0, 0, 2, 0.8)
|
37
|
-
|
38
|
-
# Insert an image over varied column and row sizes
|
39
|
-
# This does not require any additional work
|
40
|
-
|
41
|
-
# Set the cols and row sizes
|
42
|
-
# NOTE: you must do this before you call insert_image()
|
43
|
-
worksheet4.set_column('A:A', 5)
|
44
|
-
worksheet4.set_column('B:B', nil, nil, 1) # Hidden
|
45
|
-
worksheet4.set_column('C:D', 10)
|
46
|
-
worksheet4.set_row(0, 30)
|
47
|
-
worksheet4.set_row(3, 5)
|
48
|
-
|
49
|
-
worksheet4.write('A10', "Image inserted over scaled rows and columns.")
|
50
|
-
worksheet4.insert_image('A1', 'republic.png')
|
51
|
-
|
52
|
-
workbook.close
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
#######################################################################
|
4
|
+
#
|
5
|
+
# Example of how to insert images into an Excel worksheet using the
|
6
|
+
# WriteExcel insert_image() method.
|
7
|
+
#
|
8
|
+
# reverse('©'), October 2001, 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
|
+
# Create a new workbook called simple.xls and add a worksheet
|
18
|
+
workbook = WriteExcel.new("images.xls")
|
19
|
+
worksheet1 = workbook.add_worksheet('Image 1')
|
20
|
+
worksheet2 = workbook.add_worksheet('Image 2')
|
21
|
+
worksheet3 = workbook.add_worksheet('Image 3')
|
22
|
+
worksheet4 = workbook.add_worksheet('Image 4')
|
23
|
+
bp=1
|
24
|
+
|
25
|
+
# Insert a basic image
|
26
|
+
worksheet1.write('A10', "Image inserted into worksheet.")
|
27
|
+
worksheet1.insert_image('A1', 'republic.png')
|
28
|
+
|
29
|
+
|
30
|
+
# Insert an image with an offset
|
31
|
+
worksheet2.write('A10', "Image inserted with an offset.")
|
32
|
+
worksheet2.insert_image('A1', 'republic.png', 32, 10)
|
33
|
+
|
34
|
+
# Insert a scaled image
|
35
|
+
worksheet3.write('A10', "Image scaled: width x 2, height x 0.8.")
|
36
|
+
worksheet3.insert_image('A1', 'republic.png', 0, 0, 2, 0.8)
|
37
|
+
|
38
|
+
# Insert an image over varied column and row sizes
|
39
|
+
# This does not require any additional work
|
40
|
+
|
41
|
+
# Set the cols and row sizes
|
42
|
+
# NOTE: you must do this before you call insert_image()
|
43
|
+
worksheet4.set_column('A:A', 5)
|
44
|
+
worksheet4.set_column('B:B', nil, nil, 1) # Hidden
|
45
|
+
worksheet4.set_column('C:D', 10)
|
46
|
+
worksheet4.set_row(0, 30)
|
47
|
+
worksheet4.set_row(3, 5)
|
48
|
+
|
49
|
+
worksheet4.write('A10', "Image inserted over scaled rows and columns.")
|
50
|
+
worksheet4.insert_image('A1', 'republic.png')
|
51
|
+
|
52
|
+
workbook.close
|