writeexcel 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +103 -0
- data/examples/a_simple.rb +42 -0
- data/examples/autofilters.rb +266 -0
- data/examples/copyformat.rb +51 -0
- data/examples/data_validate.rb +278 -0
- data/examples/date_time.rb +86 -0
- data/examples/demo.rb +118 -0
- data/examples/diag_border.rb +35 -0
- data/examples/formats.rb +489 -0
- data/examples/header.rb +136 -0
- data/examples/hidden.rb +28 -0
- data/examples/hyperlink.rb +42 -0
- data/examples/images.rb +52 -0
- data/examples/merge1.rb +39 -0
- data/examples/merge2.rb +44 -0
- data/examples/merge3.rb +65 -0
- data/examples/merge4.rb +82 -0
- data/examples/merge5.rb +79 -0
- data/examples/protection.rb +46 -0
- data/examples/regions.rb +52 -0
- data/examples/repeat.rb +42 -0
- data/examples/republic.png +0 -0
- data/examples/stats.rb +75 -0
- data/examples/stocks.rb +80 -0
- data/examples/tab_colors.rb +30 -0
- data/lib/writeexcel/biffwriter.rb +260 -0
- data/lib/writeexcel/chart.rb +217 -0
- data/lib/writeexcel/excelformulaparser.rb +573 -0
- data/lib/writeexcel/format.rb +1108 -0
- data/lib/writeexcel/formula.rb +986 -0
- data/lib/writeexcel/olewriter.rb +322 -0
- data/lib/writeexcel/properties.rb +250 -0
- data/lib/writeexcel/workbook.rb +2630 -0
- data/lib/writeexcel/worksheet.rb +6377 -0
- data/lib/writeexcel.rb +18 -0
- data/test/perl_output/README +31 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/biff_add_continue_testdata +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/diag_border.xls +0 -0
- data/test/perl_output/f_font_biff +0 -0
- data/test/perl_output/f_font_key +1 -0
- data/test/perl_output/f_xf_biff +0 -0
- data/test/perl_output/file_font_biff +0 -0
- data/test/perl_output/file_font_key +1 -0
- data/test/perl_output/file_xf_biff +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hidden.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/ole_write_header +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/perl_output/ws_colinfo +1 -0
- data/test/perl_output/ws_store_colinfo +0 -0
- data/test/perl_output/ws_store_dimensions +0 -0
- data/test/perl_output/ws_store_filtermode +0 -0
- data/test/perl_output/ws_store_filtermode_off +0 -0
- data/test/perl_output/ws_store_filtermode_on +0 -0
- data/test/perl_output/ws_store_selection +0 -0
- data/test/perl_output/ws_store_window2 +1 -0
- data/test/republic.png +0 -0
- data/test/tc_all.rb +31 -0
- data/test/tc_biff.rb +104 -0
- data/test/tc_chart.rb +22 -0
- data/test/tc_example_match.rb +1280 -0
- data/test/tc_format.rb +1267 -0
- data/test/tc_formula.rb +63 -0
- data/test/tc_ole.rb +110 -0
- data/test/tc_workbook.rb +115 -0
- data/test/tc_worksheet.rb +115 -0
- data/test/test_00_IEEE_double.rb +14 -0
- data/test/test_01_add_worksheet.rb +12 -0
- data/test/test_02_merge_formats.rb +58 -0
- data/test/test_04_dimensions.rb +397 -0
- data/test/test_05_rows.rb +182 -0
- data/test/test_06_extsst.rb +80 -0
- data/test/test_11_date_time.rb +484 -0
- data/test/test_12_date_only.rb +506 -0
- data/test/test_13_date_seconds.rb +486 -0
- data/test/test_21_escher.rb +629 -0
- data/test/test_22_mso_drawing_group.rb +739 -0
- data/test/test_23_note.rb +78 -0
- data/test/test_24_txo.rb +80 -0
- data/test/test_26_autofilter.rb +327 -0
- data/test/test_27_autofilter.rb +144 -0
- data/test/test_28_autofilter.rb +174 -0
- data/test/test_29_process_jpg.rb +131 -0
- data/test/test_30_validation_dval.rb +82 -0
- data/test/test_31_validation_dv_strings.rb +131 -0
- data/test/test_32_validation_dv_formula.rb +211 -0
- data/test/test_40_property_types.rb +191 -0
- data/test/test_41_properties.rb +238 -0
- data/test/test_42_set_properties.rb +419 -0
- data/test/ts_all.rb +34 -0
- metadata +170 -0
data/README
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
= WriteExcel
|
|
2
|
+
|
|
3
|
+
Write to a cross-platform Excel binary file.
|
|
4
|
+
|
|
5
|
+
== Description
|
|
6
|
+
|
|
7
|
+
This library is converted from Spreadsheet::WriteExcel module of Perl.
|
|
8
|
+
http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.25/
|
|
9
|
+
|
|
10
|
+
Some function does not implemented yet.
|
|
11
|
+
* import externally generated charts into WriteExcel file.
|
|
12
|
+
* output is file only. not to a memory.
|
|
13
|
+
* file property of Excel(such as author, time, etc.) is not supported.
|
|
14
|
+
|
|
15
|
+
Some examples written in perl was successfully converted to Ruby. But
|
|
16
|
+
this library written in Ruby has many bugs, I think.
|
|
17
|
+
|
|
18
|
+
Original description is below:
|
|
19
|
+
|
|
20
|
+
The Spreadsheet::WriteExcel module can be used to create a cross-
|
|
21
|
+
platform Excel binary file. Multiple worksheets can be added to a
|
|
22
|
+
workbook and formatting can be applied to cells. Text, numbers,
|
|
23
|
+
formulas, hyperlinks and images can be written to the cells.
|
|
24
|
+
|
|
25
|
+
TThe Excel file produced by this module is compatible with 97,
|
|
26
|
+
2000, 2002 and 2003.
|
|
27
|
+
|
|
28
|
+
The module will work on the majority of Windows, UNIX and
|
|
29
|
+
Macintosh platforms. Generated files are also compatible with the
|
|
30
|
+
spreadsheet applications Gnumeric and OpenOffice.org.
|
|
31
|
+
|
|
32
|
+
This module cannot be used to read an Excel file. See
|
|
33
|
+
Spreadsheet::ParseExcel or look at the main documentation for some
|
|
34
|
+
suggestions. This module cannot be uses to write to an existing
|
|
35
|
+
Excel file.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
== Usage
|
|
39
|
+
|
|
40
|
+
Document has not converted yet.
|
|
41
|
+
reference of methods, see original document.
|
|
42
|
+
http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.25/lib/Spreadsheet/WriteExcel.pm
|
|
43
|
+
|
|
44
|
+
Example Code:
|
|
45
|
+
|
|
46
|
+
require 'writeexcel'
|
|
47
|
+
|
|
48
|
+
# Create a new Excel Workbook
|
|
49
|
+
workbook = WriteExcel.new('ruby.xls')
|
|
50
|
+
|
|
51
|
+
# Add worksheet(s)
|
|
52
|
+
worksheet = workbook.add_worksheet
|
|
53
|
+
worksheet2 = workbook.add_worksheet
|
|
54
|
+
|
|
55
|
+
# Add and define a format
|
|
56
|
+
format = workbook.add_format
|
|
57
|
+
format.set_bold
|
|
58
|
+
format.set_color('red')
|
|
59
|
+
format.set_align('right')
|
|
60
|
+
|
|
61
|
+
# write a formatted and unformatted string.
|
|
62
|
+
worksheet.write(1, 1, 'Hi Excel.', format) # cell B2
|
|
63
|
+
worksheet.write(2, 1, 'Hi Excel.') # cell B3
|
|
64
|
+
|
|
65
|
+
# write a number and formula using A1 notation
|
|
66
|
+
worksheet.write('B4', 3.14159)
|
|
67
|
+
worksheet.write('B5', '=SIN(B4/4)')
|
|
68
|
+
|
|
69
|
+
# write to file
|
|
70
|
+
workbook.close
|
|
71
|
+
|
|
72
|
+
== Difference with Perl module
|
|
73
|
+
|
|
74
|
+
* Spreadsheet::WriteExcel.new()
|
|
75
|
+
* accept default format parameter such as new('foo.xls', :font => 'Roman', :size => 12)
|
|
76
|
+
* Worksheet.write(row, col, token, format)
|
|
77
|
+
* if token.kind_of?(Numeric) then call write_number, if token.kind_of?(String) then not call write_number().
|
|
78
|
+
* Worksheet.keep_leading_zeros()
|
|
79
|
+
* ignore. if write 0001, use string such as write(1,2, '0001')
|
|
80
|
+
* and ......
|
|
81
|
+
|
|
82
|
+
== Caution
|
|
83
|
+
|
|
84
|
+
This library can handle multibyte character written in utf8. I tested in Japanese,
|
|
85
|
+
and it looks work well. But, in this version, utf8 or not is recognized
|
|
86
|
+
by matching non-ascii characters because ruby 1.8 can not recognize character code
|
|
87
|
+
correctly.
|
|
88
|
+
|
|
89
|
+
== Dependencies
|
|
90
|
+
|
|
91
|
+
* ruby 1.8
|
|
92
|
+
* ruby-ole (you can install via rubygem)
|
|
93
|
+
|
|
94
|
+
== Author
|
|
95
|
+
|
|
96
|
+
Original was written in Perl by John McNamara (jmcnamara@cpan.org).
|
|
97
|
+
|
|
98
|
+
Convert to ruby by Hideo Nakamura (cxn03651@msj.biglobe.ne.jp)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
== License
|
|
102
|
+
|
|
103
|
+
same as Ruby.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
#
|
|
3
|
+
# Example of how to use the WriteExcel module to write text and numbers
|
|
4
|
+
# to an Excel binary file.
|
|
5
|
+
#
|
|
6
|
+
# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
|
|
7
|
+
#
|
|
8
|
+
# original written in Perl by John McNamara
|
|
9
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
|
10
|
+
#
|
|
11
|
+
require 'rubygems'
|
|
12
|
+
require 'writeexcel'
|
|
13
|
+
|
|
14
|
+
# Create a new workbook called simple.xls and add a worksheet
|
|
15
|
+
workbook = Spreadsheet::WriteExcel.new('a_simple.xls');
|
|
16
|
+
worksheet = workbook.add_worksheet
|
|
17
|
+
|
|
18
|
+
# The general syntax is write(row, column, token). Note that row and
|
|
19
|
+
# column are zero indexed
|
|
20
|
+
#
|
|
21
|
+
|
|
22
|
+
# Write some text
|
|
23
|
+
worksheet.write(0, 0, "Hi Excel!")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Write some numbers
|
|
27
|
+
worksheet.write(2, 0, 3) # Writes 3
|
|
28
|
+
worksheet.write(3, 0, 3.00000) # Writes 3
|
|
29
|
+
worksheet.write(4, 0, 3.00001) # Writes 3.00001
|
|
30
|
+
worksheet.write(5, 0, 3.14159) # TeX revision no.?
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# Write some formulas
|
|
34
|
+
worksheet.write(7, 0, '=A3 + A6')
|
|
35
|
+
worksheet.write(8, 0, '=IF(A5>3,"Yes", "No")')
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Write a hyperlink
|
|
39
|
+
worksheet.write(10, 0, 'http://www.perl.com/')
|
|
40
|
+
|
|
41
|
+
# File save
|
|
42
|
+
workbook.close
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
|
|
3
|
+
#######################################################################
|
|
4
|
+
#
|
|
5
|
+
# Example of how to create autofilters with Spreadsheet::WriteExcel.
|
|
6
|
+
#
|
|
7
|
+
# reverse('©'), September 2007, 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
|
+
def get_data
|
|
16
|
+
[
|
|
17
|
+
['East', 'Apple', 9000, 'July'],
|
|
18
|
+
['East', 'Apple', 5000, 'July'],
|
|
19
|
+
['South', 'Orange', 9000, 'September'],
|
|
20
|
+
['North', 'Apple', 2000, 'November'],
|
|
21
|
+
['West', 'Apple', 9000, 'November'],
|
|
22
|
+
['South', 'Pear', 7000, 'October'],
|
|
23
|
+
['North', 'Pear', 9000, 'August'],
|
|
24
|
+
['West', 'Orange', 1000, 'December'],
|
|
25
|
+
['West', 'Grape', 1000, 'November'],
|
|
26
|
+
['South', 'Pear', 10000, 'April'],
|
|
27
|
+
['West', 'Grape', 6000, 'January'],
|
|
28
|
+
['South', 'Orange', 3000, 'May'],
|
|
29
|
+
['North', 'Apple', 3000, 'December'],
|
|
30
|
+
['South', 'Apple', 7000, 'February'],
|
|
31
|
+
['West', 'Grape', 1000, 'December'],
|
|
32
|
+
['East', 'Grape', 8000, 'February'],
|
|
33
|
+
['South', 'Grape', 10000, 'June'],
|
|
34
|
+
['West', 'Pear', 7000, 'December'],
|
|
35
|
+
['South', 'Apple', 2000, 'October'],
|
|
36
|
+
['East', 'Grape', 7000, 'December'],
|
|
37
|
+
['North', 'Grape', 6000, 'April'],
|
|
38
|
+
['East', 'Pear', 8000, 'February'],
|
|
39
|
+
['North', 'Apple', 7000, 'August'],
|
|
40
|
+
['North', 'Orange', 7000, 'July'],
|
|
41
|
+
['North', 'Apple', 6000, 'June'],
|
|
42
|
+
['South', 'Grape', 8000, 'September'],
|
|
43
|
+
['West', 'Apple', 3000, 'October'],
|
|
44
|
+
['South', 'Orange', 10000, 'November'],
|
|
45
|
+
['West', 'Grape', 4000, 'July'],
|
|
46
|
+
['North', 'Orange', 5000, 'August'],
|
|
47
|
+
['East', 'Orange', 1000, 'November'],
|
|
48
|
+
['East', 'Orange', 4000, 'October'],
|
|
49
|
+
['North', 'Grape', 5000, 'August'],
|
|
50
|
+
['East', 'Apple', 1000, 'December'],
|
|
51
|
+
['South', 'Apple', 10000, 'March'],
|
|
52
|
+
['East', 'Grape', 7000, 'October'],
|
|
53
|
+
['West', 'Grape', 1000, 'September'],
|
|
54
|
+
['East', 'Grape', 10000, 'October'],
|
|
55
|
+
['South', 'Orange', 8000, 'March'],
|
|
56
|
+
['North', 'Apple', 4000, 'July'],
|
|
57
|
+
['South', 'Orange', 5000, 'July'],
|
|
58
|
+
['West', 'Apple', 4000, 'June'],
|
|
59
|
+
['East', 'Apple', 5000, 'April'],
|
|
60
|
+
['North', 'Pear', 3000, 'August'],
|
|
61
|
+
['East', 'Grape', 9000, 'November'],
|
|
62
|
+
['North', 'Orange', 8000, 'October'],
|
|
63
|
+
['East', 'Apple', 10000, 'June'],
|
|
64
|
+
['South', 'Pear', 1000, 'December'],
|
|
65
|
+
['North', 'Grape', 10000, 'July'],
|
|
66
|
+
['East', 'Grape', 6000, 'February'],
|
|
67
|
+
]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#######################################################################
|
|
71
|
+
#
|
|
72
|
+
# Main
|
|
73
|
+
#
|
|
74
|
+
|
|
75
|
+
xlsfile = 'autofilters.xls'
|
|
76
|
+
|
|
77
|
+
workbook = Spreadsheet::WriteExcel.new(xlsfile)
|
|
78
|
+
bp=1
|
|
79
|
+
|
|
80
|
+
worksheet1 = workbook.add_worksheet
|
|
81
|
+
worksheet2 = workbook.add_worksheet
|
|
82
|
+
worksheet3 = workbook.add_worksheet
|
|
83
|
+
worksheet4 = workbook.add_worksheet
|
|
84
|
+
worksheet5 = workbook.add_worksheet
|
|
85
|
+
worksheet6 = workbook.add_worksheet
|
|
86
|
+
|
|
87
|
+
bold = workbook.add_format(:bold => 1)
|
|
88
|
+
|
|
89
|
+
# Extract the data embedded at the end of this file.
|
|
90
|
+
headings = %w(Region Item Volume Month)
|
|
91
|
+
data = get_data
|
|
92
|
+
|
|
93
|
+
# Set up several sheets with the same data.
|
|
94
|
+
workbook.sheets.each do |worksheet|
|
|
95
|
+
worksheet.set_column('A:D', 12)
|
|
96
|
+
worksheet.set_row(0, 20, bold)
|
|
97
|
+
worksheet.write('A1', headings)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
###############################################################################
|
|
101
|
+
#
|
|
102
|
+
# Example 1. Autofilter without conditions.
|
|
103
|
+
#
|
|
104
|
+
|
|
105
|
+
worksheet1.autofilter('A1:D51')
|
|
106
|
+
worksheet1.write('A2', [data])
|
|
107
|
+
|
|
108
|
+
###############################################################################
|
|
109
|
+
#
|
|
110
|
+
#
|
|
111
|
+
# Example 2. Autofilter with a filter condition in the first column.
|
|
112
|
+
#
|
|
113
|
+
|
|
114
|
+
# The range in this example is the same as above but in row-column notation.
|
|
115
|
+
worksheet2.autofilter(0, 0, 50, 3)
|
|
116
|
+
|
|
117
|
+
# The placeholder "Region" in the filter is ignored and can be any string
|
|
118
|
+
# that adds clarity to the expression.
|
|
119
|
+
#
|
|
120
|
+
worksheet2.filter_column(0, 'Region eq East')
|
|
121
|
+
|
|
122
|
+
#
|
|
123
|
+
# Hide the rows that don't match the filter criteria.
|
|
124
|
+
#
|
|
125
|
+
row = 1
|
|
126
|
+
|
|
127
|
+
data.each do |row_data|
|
|
128
|
+
region = row_data[0]
|
|
129
|
+
|
|
130
|
+
if region == 'East'
|
|
131
|
+
# Row is visible.
|
|
132
|
+
else
|
|
133
|
+
# Hide row.
|
|
134
|
+
worksheet2.set_row(row, nil, nil, 1)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
worksheet2.write(row, 0, row_data)
|
|
138
|
+
row += 1
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
###############################################################################
|
|
143
|
+
#
|
|
144
|
+
#
|
|
145
|
+
# Example 3. Autofilter with a dual filter condition in one of the columns.
|
|
146
|
+
#
|
|
147
|
+
|
|
148
|
+
worksheet3.autofilter('A1:D51')
|
|
149
|
+
|
|
150
|
+
worksheet3.filter_column('A', 'x eq East or x eq South')
|
|
151
|
+
|
|
152
|
+
#
|
|
153
|
+
# Hide the rows that don't match the filter criteria.
|
|
154
|
+
#
|
|
155
|
+
row = 1
|
|
156
|
+
|
|
157
|
+
data.each do |row_data|
|
|
158
|
+
region = row_data[0]
|
|
159
|
+
|
|
160
|
+
if region == 'East' || region == 'South'
|
|
161
|
+
# Row is visible.
|
|
162
|
+
else
|
|
163
|
+
# Hide row.
|
|
164
|
+
worksheet3.set_row(row, nil, nil, 1)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
worksheet3.write(row, 0, row_data)
|
|
168
|
+
row += 1
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
###############################################################################
|
|
173
|
+
#
|
|
174
|
+
#
|
|
175
|
+
# Example 4. Autofilter with filter conditions in two columns.
|
|
176
|
+
#
|
|
177
|
+
|
|
178
|
+
worksheet4.autofilter('A1:D51')
|
|
179
|
+
|
|
180
|
+
worksheet4.filter_column('A', 'x eq East')
|
|
181
|
+
worksheet4.filter_column('C', 'x > 3000 and x < 8000' )
|
|
182
|
+
|
|
183
|
+
#
|
|
184
|
+
# Hide the rows that don't match the filter criteria.
|
|
185
|
+
#
|
|
186
|
+
row = 1
|
|
187
|
+
|
|
188
|
+
data.each do |row_data|
|
|
189
|
+
region = row_data[0]
|
|
190
|
+
volume = row_data[2]
|
|
191
|
+
|
|
192
|
+
if region == 'East' && volume > 3000 && volume < 8000
|
|
193
|
+
# Row is visible.
|
|
194
|
+
else
|
|
195
|
+
# Hide row.
|
|
196
|
+
worksheet4.set_row(row, nil, nil, 1)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
worksheet4.write(row, 0, row_data)
|
|
200
|
+
row += 1
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
###############################################################################
|
|
205
|
+
#
|
|
206
|
+
#
|
|
207
|
+
# Example 5. Autofilter with filter for blanks.
|
|
208
|
+
#
|
|
209
|
+
|
|
210
|
+
# Create a blank cell in our test data.
|
|
211
|
+
data[5][0] = ''
|
|
212
|
+
|
|
213
|
+
worksheet5.autofilter('A1:D51')
|
|
214
|
+
worksheet5.filter_column('A', 'x == Blanks')
|
|
215
|
+
|
|
216
|
+
#
|
|
217
|
+
# Hide the rows that don't match the filter criteria.
|
|
218
|
+
#
|
|
219
|
+
row = 1
|
|
220
|
+
|
|
221
|
+
data.each do |row_data|
|
|
222
|
+
region = row_data[0]
|
|
223
|
+
|
|
224
|
+
if region == ''
|
|
225
|
+
# Row is visible.
|
|
226
|
+
else
|
|
227
|
+
# Hide row.
|
|
228
|
+
worksheet5.set_row(row, nil, nil, 1)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
worksheet5.write(row, 0, row_data)
|
|
232
|
+
row += 1
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
###############################################################################
|
|
237
|
+
#
|
|
238
|
+
#
|
|
239
|
+
# Example 6. Autofilter with filter for non-blanks.
|
|
240
|
+
#
|
|
241
|
+
|
|
242
|
+
worksheet6.autofilter('A1:D51')
|
|
243
|
+
worksheet6.filter_column('A', 'x == NonBlanks')
|
|
244
|
+
|
|
245
|
+
#
|
|
246
|
+
# Hide the rows that don't match the filter criteria.
|
|
247
|
+
#
|
|
248
|
+
row = 1
|
|
249
|
+
|
|
250
|
+
data.each do |row_data|
|
|
251
|
+
region = row_data[0]
|
|
252
|
+
|
|
253
|
+
if region != ''
|
|
254
|
+
# Row is visible.
|
|
255
|
+
else
|
|
256
|
+
# Hide row.
|
|
257
|
+
worksheet6.set_row(row, nil, nil, 1)
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
worksheet6.write(row, 0, row_data)
|
|
261
|
+
row += 1
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
workbook.close
|
|
265
|
+
|
|
266
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
|
|
3
|
+
###############################################################################
|
|
4
|
+
#
|
|
5
|
+
# Example of how to use the format copying method with Spreadsheet::WriteExcel #
|
|
6
|
+
# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
|
|
7
|
+
#
|
|
8
|
+
# original written in Perl by John McNamara
|
|
9
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
|
10
|
+
#
|
|
11
|
+
require 'rubygems'
|
|
12
|
+
require 'writeexcel'
|
|
13
|
+
|
|
14
|
+
# Create workbook1
|
|
15
|
+
workbook1 = Spreadsheet::WriteExcel.new("workbook1.xls")
|
|
16
|
+
worksheet1 = workbook1.add_worksheet
|
|
17
|
+
format1a = workbook1.add_format
|
|
18
|
+
format1b = workbook1.add_format
|
|
19
|
+
|
|
20
|
+
# Create workbook2
|
|
21
|
+
workbook2 = Spreadsheet::WriteExcel.new("workbook2.xls")
|
|
22
|
+
worksheet2 = workbook2.add_worksheet
|
|
23
|
+
format2a = workbook2.add_format
|
|
24
|
+
format2b = workbook2.add_format
|
|
25
|
+
|
|
26
|
+
# Create a global format object that isn't tied to a workbook
|
|
27
|
+
global_format = Format.new
|
|
28
|
+
|
|
29
|
+
# Set the formatting
|
|
30
|
+
global_format.set_color('blue')
|
|
31
|
+
global_format.set_bold
|
|
32
|
+
global_format.set_italic
|
|
33
|
+
|
|
34
|
+
# Create another example format
|
|
35
|
+
format1b.set_color('red')
|
|
36
|
+
|
|
37
|
+
# Copy the global format properties to the worksheet formats
|
|
38
|
+
format1a.copy(global_format)
|
|
39
|
+
format2a.copy(global_format)
|
|
40
|
+
|
|
41
|
+
# Copy a format from worksheet1 to worksheet2
|
|
42
|
+
format2b.copy(format1b)
|
|
43
|
+
|
|
44
|
+
# Write some output
|
|
45
|
+
worksheet1.write(0, 0, "Ciao", format1a)
|
|
46
|
+
worksheet1.write(1, 0, "Ciao", format1b)
|
|
47
|
+
|
|
48
|
+
worksheet2.write(0, 0, "Hello", format2a)
|
|
49
|
+
worksheet2.write(1, 0, "Hello", format2b)
|
|
50
|
+
workbook1.close
|
|
51
|
+
workbook2.close
|