ricardoo27-writeexcel 0.6.12.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitattributes +1 -0
- data/README.rdoc +136 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/charts/chartex.rb +316 -0
- data/charts/demo1.rb +46 -0
- data/charts/demo101.bin +0 -0
- data/charts/demo2.rb +65 -0
- data/charts/demo201.bin +0 -0
- data/charts/demo3.rb +117 -0
- data/charts/demo301.bin +0 -0
- data/charts/demo4.rb +119 -0
- data/charts/demo401.bin +0 -0
- data/charts/demo5.rb +48 -0
- data/charts/demo501.bin +0 -0
- data/examples/a_simple.rb +43 -0
- data/examples/autofilter.rb +265 -0
- data/examples/bigfile.rb +30 -0
- data/examples/chart_area.rb +121 -0
- data/examples/chart_bar.rb +120 -0
- data/examples/chart_column.rb +120 -0
- data/examples/chart_line.rb +120 -0
- data/examples/chart_pie.rb +108 -0
- data/examples/chart_scatter.rb +121 -0
- data/examples/chart_stock.rb +148 -0
- data/examples/chess.rb +142 -0
- data/examples/colors.rb +129 -0
- data/examples/comments1.rb +27 -0
- data/examples/comments2.rb +352 -0
- data/examples/copyformat.rb +52 -0
- data/examples/data_validate.rb +279 -0
- data/examples/date_time.rb +87 -0
- data/examples/defined_name.rb +32 -0
- data/examples/demo.rb +124 -0
- data/examples/diag_border.rb +36 -0
- data/examples/formats.rb +490 -0
- data/examples/formula_result.rb +30 -0
- data/examples/header.rb +137 -0
- data/examples/hide_sheet.rb +29 -0
- data/examples/hyperlink.rb +43 -0
- data/examples/images.rb +63 -0
- data/examples/indent.rb +31 -0
- data/examples/merge1.rb +40 -0
- data/examples/merge2.rb +45 -0
- data/examples/merge3.rb +66 -0
- data/examples/merge4.rb +83 -0
- data/examples/merge5.rb +80 -0
- data/examples/merge6.rb +67 -0
- data/examples/outline.rb +255 -0
- data/examples/outline_collapsed.rb +209 -0
- data/examples/panes.rb +113 -0
- data/examples/password_protection.rb +33 -0
- data/examples/properties.rb +34 -0
- data/examples/properties_jp.rb +33 -0
- data/examples/protection.rb +47 -0
- data/examples/regions.rb +53 -0
- data/examples/repeat.rb +43 -0
- data/examples/republic.png +0 -0
- data/examples/right_to_left.rb +27 -0
- data/examples/row_wrap.rb +53 -0
- data/examples/set_first_sheet.rb +14 -0
- data/examples/stats.rb +74 -0
- data/examples/stocks.rb +81 -0
- data/examples/store_formula.rb +15 -0
- data/examples/tab_colors.rb +31 -0
- data/examples/utf8.rb +15 -0
- data/examples/write_arrays.rb +83 -0
- data/html/en/doc_en.html +5946 -0
- data/html/images/a_simple.jpg +0 -0
- data/html/images/area1.jpg +0 -0
- data/html/images/bar1.jpg +0 -0
- data/html/images/chart_area.xls +0 -0
- data/html/images/column1.jpg +0 -0
- data/html/images/data_validation.jpg +0 -0
- data/html/images/line1.jpg +0 -0
- data/html/images/pie1.jpg +0 -0
- data/html/images/regions.jpg +0 -0
- data/html/images/scatter1.jpg +0 -0
- data/html/images/stats.jpg +0 -0
- data/html/images/stock1.jpg +0 -0
- data/html/images/stocks.jpg +0 -0
- data/html/index.html +16 -0
- data/html/style.css +433 -0
- data/lib/writeexcel.rb +1159 -0
- data/lib/writeexcel/biffwriter.rb +223 -0
- data/lib/writeexcel/caller_info.rb +12 -0
- data/lib/writeexcel/cell_range.rb +332 -0
- data/lib/writeexcel/chart.rb +1968 -0
- data/lib/writeexcel/charts/area.rb +154 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +66 -0
- data/lib/writeexcel/charts/line.rb +154 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +213 -0
- data/lib/writeexcel/col_info.rb +87 -0
- data/lib/writeexcel/colors.rb +68 -0
- data/lib/writeexcel/comments.rb +460 -0
- data/lib/writeexcel/compatibility.rb +65 -0
- data/lib/writeexcel/convert_date_time.rb +117 -0
- data/lib/writeexcel/data_validations.rb +370 -0
- data/lib/writeexcel/debug_info.rb +41 -0
- data/lib/writeexcel/embedded_chart.rb +35 -0
- data/lib/writeexcel/excelformula.y +139 -0
- data/lib/writeexcel/excelformulaparser.rb +587 -0
- data/lib/writeexcel/format.rb +1575 -0
- data/lib/writeexcel/formula.rb +987 -0
- data/lib/writeexcel/helper.rb +78 -0
- data/lib/writeexcel/image.rb +218 -0
- data/lib/writeexcel/olewriter.rb +305 -0
- data/lib/writeexcel/outline.rb +24 -0
- data/lib/writeexcel/properties.rb +242 -0
- data/lib/writeexcel/shared_string_table.rb +153 -0
- data/lib/writeexcel/storage_lite.rb +984 -0
- data/lib/writeexcel/workbook.rb +2478 -0
- data/lib/writeexcel/worksheet.rb +6925 -0
- data/lib/writeexcel/worksheets.rb +25 -0
- data/lib/writeexcel/write_file.rb +63 -0
- 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/helper.rb +31 -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/README +31 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/biff_add_continue_testdata +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/chess.xls +0 -0
- data/test/perl_output/colors.xls +0 -0
- data/test/perl_output/comments0.xls +0 -0
- data/test/perl_output/comments1.xls +0 -0
- data/test/perl_output/comments2.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/defined_name.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/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/formula_result.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hidden.xls +0 -0
- data/test/perl_output/hide_zero.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/indent.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/merge6.xls +0 -0
- data/test/perl_output/ole_write_header +0 -0
- data/test/perl_output/outline.xls +0 -0
- data/test/perl_output/outline_collapsed.xls +0 -0
- data/test/perl_output/panes.xls +0 -0
- data/test/perl_output/password_protection.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/right_to_left.xls +0 -0
- data/test/perl_output/set_first_sheet.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/store_formula.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/utf8.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/test_00_IEEE_double.rb +13 -0
- data/test/test_01_add_worksheet.rb +10 -0
- data/test/test_02_merge_formats.rb +49 -0
- data/test/test_04_dimensions.rb +388 -0
- data/test/test_05_rows.rb +175 -0
- data/test/test_06_extsst.rb +74 -0
- data/test/test_11_date_time.rb +475 -0
- data/test/test_12_date_only.rb +525 -0
- data/test/test_13_date_seconds.rb +477 -0
- data/test/test_21_escher.rb +624 -0
- data/test/test_22_mso_drawing_group.rb +741 -0
- data/test/test_23_note.rb +57 -0
- data/test/test_24_txo.rb +74 -0
- data/test/test_25_position_object.rb +80 -0
- data/test/test_26_autofilter.rb +309 -0
- data/test/test_27_autofilter.rb +126 -0
- data/test/test_28_autofilter.rb +156 -0
- data/test/test_29_process_jpg.rb +670 -0
- data/test/test_30_validation_dval.rb +74 -0
- data/test/test_31_validation_dv_strings.rb +123 -0
- data/test/test_32_validation_dv_formula.rb +203 -0
- data/test/test_40_property_types.rb +188 -0
- data/test/test_41_properties.rb +235 -0
- data/test/test_42_set_properties.rb +434 -0
- data/test/test_50_name_stored.rb +295 -0
- data/test/test_51_name_print_area.rb +353 -0
- data/test/test_52_name_print_titles.rb +450 -0
- data/test/test_53_autofilter.rb +199 -0
- data/test/test_60_chart_generic.rb +574 -0
- data/test/test_61_chart_subclasses.rb +84 -0
- data/test/test_62_chart_formats.rb +268 -0
- data/test/test_63_chart_area_formats.rb +645 -0
- data/test/test_biff.rb +71 -0
- data/test/test_big_workbook.rb +17 -0
- data/test/test_compatibility.rb +12 -0
- data/test/test_example_match.rb +3246 -0
- data/test/test_format.rb +1189 -0
- data/test/test_formula.rb +61 -0
- data/test/test_ole.rb +102 -0
- data/test/test_storage_lite.rb +116 -0
- data/test/test_workbook.rb +146 -0
- data/test/test_worksheet.rb +106 -0
- data/utils/add_magic_comment.rb +80 -0
- data/writeexcel.gemspec +278 -0
- data/writeexcel.rdoc +1425 -0
- metadata +292 -0
data/examples/demo.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
#######################################################################
|
5
|
+
#
|
6
|
+
# Demo of some of the features of WriteExcel.
|
7
|
+
# Used to create the project screenshot for Freshmeat.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# reverse('©'), October 2001, John McNamara, jmcnamara@cpan.org
|
11
|
+
#
|
12
|
+
# original written in Perl by John McNamara
|
13
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
require 'writeexcel'
|
18
|
+
|
19
|
+
# $debug = true
|
20
|
+
|
21
|
+
workbook = WriteExcel.new("demo.xls")
|
22
|
+
worksheet = workbook.add_worksheet('Demo')
|
23
|
+
worksheet2 = workbook.add_worksheet('Another sheet')
|
24
|
+
worksheet3 = workbook.add_worksheet('And another')
|
25
|
+
|
26
|
+
bold = workbook.add_format(:bold => 1)
|
27
|
+
|
28
|
+
#######################################################################
|
29
|
+
#
|
30
|
+
# Write a general heading
|
31
|
+
#
|
32
|
+
worksheet.set_column('A:A', 36, bold)
|
33
|
+
worksheet.set_column('B:B', 20 )
|
34
|
+
worksheet.set_row(0, 40 )
|
35
|
+
|
36
|
+
heading = workbook.add_format(
|
37
|
+
:bold => 1,
|
38
|
+
:color => 'blue',
|
39
|
+
:size => 16,
|
40
|
+
:merge => 1,
|
41
|
+
:align => 'vcenter'
|
42
|
+
)
|
43
|
+
|
44
|
+
headings = ['Features of Spreadsheet::WriteExcel', '']
|
45
|
+
worksheet.write_row('A1', headings, heading)
|
46
|
+
|
47
|
+
|
48
|
+
#######################################################################
|
49
|
+
#
|
50
|
+
# Some text examples
|
51
|
+
#
|
52
|
+
text_format = workbook.add_format(
|
53
|
+
:bold => 1,
|
54
|
+
:italic => 1,
|
55
|
+
:color => 'red',
|
56
|
+
:size => 18,
|
57
|
+
:font =>'Lucida Calligraphy'
|
58
|
+
)
|
59
|
+
|
60
|
+
# A phrase in Cyrillic
|
61
|
+
unicode = [
|
62
|
+
"042d0442043e002004440440043004370430002004"+
|
63
|
+
"3d043000200440044304410441043a043e043c0021"
|
64
|
+
].pack('H*')
|
65
|
+
|
66
|
+
worksheet.write('A2', "Text")
|
67
|
+
worksheet.write('B2', "Hello Excel")
|
68
|
+
worksheet.write('A3', "Formatted text")
|
69
|
+
worksheet.write('B3', "Hello Excel", text_format)
|
70
|
+
worksheet.write('A4', "Unicode text")
|
71
|
+
worksheet.write_utf16be_string('B4', unicode)
|
72
|
+
|
73
|
+
|
74
|
+
#######################################################################
|
75
|
+
#
|
76
|
+
# Some numeric examples
|
77
|
+
#
|
78
|
+
num1_format = workbook.add_format(:num_format => '$#,##0.00')
|
79
|
+
num2_format = workbook.add_format(:num_format => ' d mmmm yyy')
|
80
|
+
|
81
|
+
worksheet.write('A5', "Numbers")
|
82
|
+
worksheet.write('B5', 1234.56)
|
83
|
+
worksheet.write('A6', "Formatted numbers")
|
84
|
+
worksheet.write('B6', 1234.56, num1_format)
|
85
|
+
worksheet.write('A7', "Formatted numbers")
|
86
|
+
worksheet.write('B7', 37257, num2_format)
|
87
|
+
|
88
|
+
|
89
|
+
#######################################################################
|
90
|
+
#
|
91
|
+
# Formulae
|
92
|
+
#
|
93
|
+
worksheet.set_selection('B8')
|
94
|
+
worksheet.write('A8', 'Formulas and functions, "=SIN(PI()/4)"')
|
95
|
+
worksheet.write('B8', '=SIN(PI()/4)')
|
96
|
+
|
97
|
+
|
98
|
+
#######################################################################
|
99
|
+
#
|
100
|
+
# Hyperlinks
|
101
|
+
#
|
102
|
+
worksheet.write('A9', "Hyperlinks")
|
103
|
+
worksheet.write('B9', 'http://www.perl.com/' )
|
104
|
+
|
105
|
+
|
106
|
+
#######################################################################
|
107
|
+
#
|
108
|
+
# Images
|
109
|
+
#
|
110
|
+
worksheet.write('A10', "Images")
|
111
|
+
worksheet.insert_image('B10',
|
112
|
+
File.join(File.dirname(File.expand_path(__FILE__)), 'republic.png'),
|
113
|
+
16, 8
|
114
|
+
)
|
115
|
+
|
116
|
+
|
117
|
+
#######################################################################
|
118
|
+
#
|
119
|
+
# Misc
|
120
|
+
#
|
121
|
+
worksheet.write('A18', "Page/printer setup")
|
122
|
+
worksheet.write('A19', "Multiple worksheets")
|
123
|
+
|
124
|
+
workbook.close
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
##############################################################################
|
5
|
+
#
|
6
|
+
# A simple formatting example using WriteExcel.
|
7
|
+
#
|
8
|
+
# This program demonstrates the diagonal border cell format.
|
9
|
+
#
|
10
|
+
# reverse('©'), May 2004, John McNamara, jmcnamara@cpan.org
|
11
|
+
#
|
12
|
+
# original written in Perl by John McNamara
|
13
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
require 'writeexcel'
|
18
|
+
|
19
|
+
workbook = WriteExcel.new('diag_border.xls')
|
20
|
+
worksheet = workbook.add_worksheet
|
21
|
+
|
22
|
+
format1 = workbook.add_format(:diag_type => 1)
|
23
|
+
format2 = workbook.add_format(:diag_type => 2)
|
24
|
+
format3 = workbook.add_format(:diag_type => 3)
|
25
|
+
format4 = workbook.add_format(
|
26
|
+
:diag_type => 3,
|
27
|
+
:diag_border => 7,
|
28
|
+
:diag_color => 'red'
|
29
|
+
)
|
30
|
+
|
31
|
+
worksheet.write('B3', 'Text', format1)
|
32
|
+
worksheet.write('B6', 'Text', format2)
|
33
|
+
worksheet.write('B9', 'Text', format3)
|
34
|
+
worksheet.write('B12', 'Text', format4)
|
35
|
+
|
36
|
+
workbook.close
|
data/examples/formats.rb
ADDED
@@ -0,0 +1,490 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
######################################################################
|
5
|
+
#
|
6
|
+
# Examples of formatting using the WriteExcel module
|
7
|
+
#
|
8
|
+
# reverse('©'), September 2002, 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
|
+
|
18
|
+
######################################################################
|
19
|
+
#
|
20
|
+
# Intro.
|
21
|
+
#
|
22
|
+
def intro(workbook)
|
23
|
+
|
24
|
+
worksheet = workbook.add_worksheet('Introduction')
|
25
|
+
|
26
|
+
worksheet.set_column(0, 0, 60)
|
27
|
+
|
28
|
+
format = workbook.add_format()
|
29
|
+
format.set_bold()
|
30
|
+
format.set_size(14)
|
31
|
+
format.set_color('blue')
|
32
|
+
format.set_align('center')
|
33
|
+
|
34
|
+
format2 = workbook.add_format()
|
35
|
+
format2.set_bold()
|
36
|
+
format2.set_color('blue')
|
37
|
+
|
38
|
+
worksheet.write(2, 0, 'This workbook demonstrates some of', format)
|
39
|
+
worksheet.write(3, 0, 'the formatting options provided by', format)
|
40
|
+
worksheet.write(4, 0, 'the WriteExcel module.', format)
|
41
|
+
|
42
|
+
worksheet.write('A7', 'Sections:', format2)
|
43
|
+
worksheet.write('A8', "internal:Fonts!A1", 'Fonts' )
|
44
|
+
worksheet.write('A9', "internal:'Named colors'!A1", 'Named colors' )
|
45
|
+
worksheet.write('A10', "internal:'Standard colors'!A1", 'Standard colors')
|
46
|
+
worksheet.write('A11', "internal:'Numeric formats'!A1", 'Numeric formats')
|
47
|
+
worksheet.write('A12', "internal:Borders!A1", 'Borders' )
|
48
|
+
worksheet.write('A13', "internal:Patterns!A1", 'Patterns' )
|
49
|
+
worksheet.write('A14', "internal:Alignment!A1", 'Alignment' )
|
50
|
+
worksheet.write('A15', "internal:Miscellaneous!A1", 'Miscellaneous' )
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
######################################################################
|
56
|
+
#
|
57
|
+
# Demonstrate the named colors.
|
58
|
+
#
|
59
|
+
def named_colors(workbook, heading, center)
|
60
|
+
|
61
|
+
worksheet = workbook.add_worksheet('Named colors')
|
62
|
+
|
63
|
+
worksheet.set_column(0, 3, 15)
|
64
|
+
|
65
|
+
worksheet.write(0, 0, "Index", heading)
|
66
|
+
worksheet.write(0, 1, "Index", heading)
|
67
|
+
worksheet.write(0, 2, "Name", heading)
|
68
|
+
worksheet.write(0, 3, "Color", heading)
|
69
|
+
|
70
|
+
i = 1
|
71
|
+
|
72
|
+
COLORS.each do |index, color|
|
73
|
+
format = workbook.add_format(
|
74
|
+
:bg_color => color,
|
75
|
+
:pattern => 1,
|
76
|
+
:border => 1
|
77
|
+
)
|
78
|
+
|
79
|
+
worksheet.write(i+1, 0, index, center)
|
80
|
+
worksheet.write(i+1, 1, sprintf("0x%02X", index), center)
|
81
|
+
worksheet.write(i+1, 2, color, center)
|
82
|
+
worksheet.write(i+1, 3, '', format)
|
83
|
+
i += 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
######################################################################
|
89
|
+
#
|
90
|
+
# Demonstrate the standard Excel colors in the range 8..63.
|
91
|
+
#
|
92
|
+
def standard_colors(workbook, heading, center)
|
93
|
+
|
94
|
+
worksheet = workbook.add_worksheet('Standard colors')
|
95
|
+
|
96
|
+
worksheet.set_column(0, 3, 15)
|
97
|
+
|
98
|
+
worksheet.write(0, 0, "Index", heading)
|
99
|
+
worksheet.write(0, 1, "Index", heading)
|
100
|
+
worksheet.write(0, 2, "Color", heading)
|
101
|
+
worksheet.write(0, 3, "Name", heading)
|
102
|
+
|
103
|
+
8.upto(63) do |i|
|
104
|
+
format = workbook.add_format(
|
105
|
+
:bg_color => i,
|
106
|
+
:pattern => 1,
|
107
|
+
:border => 1
|
108
|
+
)
|
109
|
+
|
110
|
+
worksheet.write((i -7), 0, i, center)
|
111
|
+
worksheet.write((i -7), 1, sprintf("0x%02X", i), center)
|
112
|
+
worksheet.write((i -7), 2, '', format)
|
113
|
+
|
114
|
+
# Add the color names
|
115
|
+
if COLORS[i]
|
116
|
+
worksheet.write((i -7), 3, COLORS[i], center)
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
######################################################################
|
124
|
+
#
|
125
|
+
# Demonstrate the standard numeric formats.
|
126
|
+
#
|
127
|
+
def numeric_formats(workbook, heading, center)
|
128
|
+
|
129
|
+
worksheet = workbook.add_worksheet('Numeric formats')
|
130
|
+
|
131
|
+
worksheet.set_column(0, 4, 15)
|
132
|
+
worksheet.set_column(5, 5, 45)
|
133
|
+
|
134
|
+
worksheet.write(0, 0, "Index", heading)
|
135
|
+
worksheet.write(0, 1, "Index", heading)
|
136
|
+
worksheet.write(0, 2, "Unformatted", heading)
|
137
|
+
worksheet.write(0, 3, "Formatted", heading)
|
138
|
+
worksheet.write(0, 4, "Negative", heading)
|
139
|
+
worksheet.write(0, 5, "Format", heading)
|
140
|
+
|
141
|
+
formats = []
|
142
|
+
formats.push([ 0x00, 1234.567, 0, 'General' ])
|
143
|
+
formats.push([ 0x01, 1234.567, 0, '0' ])
|
144
|
+
formats.push([ 0x02, 1234.567, 0, '0.00' ])
|
145
|
+
formats.push([ 0x03, 1234.567, 0, '#,##0' ])
|
146
|
+
formats.push([ 0x04, 1234.567, 0, '#,##0.00' ])
|
147
|
+
formats.push([ 0x05, 1234.567, -1234.567, '($#,##0_);($#,##0)' ])
|
148
|
+
formats.push([ 0x06, 1234.567, -1234.567, '($#,##0_);[Red]($#,##0)' ])
|
149
|
+
formats.push([ 0x07, 1234.567, -1234.567, '($#,##0.00_);($#,##0.00)' ])
|
150
|
+
formats.push([ 0x08, 1234.567, -1234.567, '($#,##0.00_);[Red]($#,##0.00)' ])
|
151
|
+
formats.push([ 0x09, 0.567, 0, '0%' ])
|
152
|
+
formats.push([ 0x0a, 0.567, 0, '0.00%' ])
|
153
|
+
formats.push([ 0x0b, 1234.567, 0, '0.00E+00' ])
|
154
|
+
formats.push([ 0x0c, 0.75, 0, '# ?/?' ])
|
155
|
+
formats.push([ 0x0d, 0.3125, 0, '# ??/??' ])
|
156
|
+
formats.push([ 0x0e, 36892.521, 0, 'm/d/yy' ])
|
157
|
+
formats.push([ 0x0f, 36892.521, 0, 'd-mmm-yy' ])
|
158
|
+
formats.push([ 0x10, 36892.521, 0, 'd-mmm' ])
|
159
|
+
formats.push([ 0x11, 36892.521, 0, 'mmm-yy' ])
|
160
|
+
formats.push([ 0x12, 36892.521, 0, 'h:mm AM/PM' ])
|
161
|
+
formats.push([ 0x13, 36892.521, 0, 'h:mm:ss AM/PM' ])
|
162
|
+
formats.push([ 0x14, 36892.521, 0, 'h:mm' ])
|
163
|
+
formats.push([ 0x15, 36892.521, 0, 'h:mm:ss' ])
|
164
|
+
formats.push([ 0x16, 36892.521, 0, 'm/d/yy h:mm' ])
|
165
|
+
formats.push([ 0x25, 1234.567, -1234.567, '(#,##0_);(#,##0)' ])
|
166
|
+
formats.push([ 0x26, 1234.567, -1234.567, '(#,##0_);[Red](#,##0)' ])
|
167
|
+
formats.push([ 0x27, 1234.567, -1234.567, '(#,##0.00_);(#,##0.00)' ])
|
168
|
+
formats.push([ 0x28, 1234.567, -1234.567, '(#,##0.00_);[Red](#,##0.00)' ])
|
169
|
+
formats.push([ 0x29, 1234.567, -1234.567, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' ])
|
170
|
+
formats.push([ 0x2a, 1234.567, -1234.567, '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' ])
|
171
|
+
formats.push([ 0x2b, 1234.567, -1234.567, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' ])
|
172
|
+
formats.push([ 0x2c, 1234.567, -1234.567, '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' ])
|
173
|
+
formats.push([ 0x2d, 36892.521, 0, 'mm:ss' ])
|
174
|
+
formats.push([ 0x2e, 3.0153, 0, '[h]:mm:ss' ])
|
175
|
+
formats.push([ 0x2f, 36892.521, 0, 'mm:ss.0' ])
|
176
|
+
formats.push([ 0x30, 1234.567, 0, '##0.0E+0' ])
|
177
|
+
formats.push([ 0x31, 1234.567, 0, '@' ])
|
178
|
+
|
179
|
+
i = 0
|
180
|
+
formats.each do |format|
|
181
|
+
style = workbook.add_format()
|
182
|
+
style.set_num_format(format[0])
|
183
|
+
|
184
|
+
i += 1
|
185
|
+
worksheet.write(i, 0, format[0], center)
|
186
|
+
worksheet.write(i, 1, sprintf("0x%02X", format[0]), center)
|
187
|
+
worksheet.write(i, 2, format[1], center)
|
188
|
+
worksheet.write(i, 3, format[1], style)
|
189
|
+
|
190
|
+
if format[2] != 0
|
191
|
+
worksheet.write(i, 4, format[2], style)
|
192
|
+
end
|
193
|
+
|
194
|
+
worksheet.write_string(i, 5, format[3])
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
######################################################################
|
200
|
+
#
|
201
|
+
# Demonstrate the font options.
|
202
|
+
#
|
203
|
+
def fonts(workbook, heading, center)
|
204
|
+
|
205
|
+
worksheet = workbook.add_worksheet('Fonts')
|
206
|
+
|
207
|
+
worksheet.set_column(0, 0, 30)
|
208
|
+
worksheet.set_column(1, 1, 10)
|
209
|
+
|
210
|
+
worksheet.write(0, 0, "Font name", heading)
|
211
|
+
worksheet.write(0, 1, "Font size", heading)
|
212
|
+
|
213
|
+
fonts = []
|
214
|
+
fonts.push([10, 'Arial' ])
|
215
|
+
fonts.push([12, 'Arial' ])
|
216
|
+
fonts.push([14, 'Arial' ])
|
217
|
+
fonts.push([12, 'Arial Black' ])
|
218
|
+
fonts.push([12, 'Arial Narrow' ])
|
219
|
+
fonts.push([12, 'Century Schoolbook' ])
|
220
|
+
fonts.push([12, 'Courier' ])
|
221
|
+
fonts.push([12, 'Courier New' ])
|
222
|
+
fonts.push([12, 'Garamond' ])
|
223
|
+
fonts.push([12, 'Impact' ])
|
224
|
+
fonts.push([12, 'Lucida Handwriting'] )
|
225
|
+
fonts.push([12, 'Times New Roman' ])
|
226
|
+
fonts.push([12, 'Symbol' ])
|
227
|
+
fonts.push([12, 'Wingdings' ])
|
228
|
+
fonts.push([12, 'A font that doesnt exist' ])
|
229
|
+
|
230
|
+
i = 0
|
231
|
+
fonts.each do |font|
|
232
|
+
format = workbook.add_format()
|
233
|
+
|
234
|
+
format.set_size(font[0])
|
235
|
+
format.set_font(font[1])
|
236
|
+
|
237
|
+
i += 1
|
238
|
+
worksheet.write(i, 0, font[1], format)
|
239
|
+
worksheet.write(i, 1, font[0], format)
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
######################################################################
|
246
|
+
#
|
247
|
+
# Demonstrate the standard Excel border styles.
|
248
|
+
#
|
249
|
+
def borders(workbook, heading, center)
|
250
|
+
|
251
|
+
worksheet = workbook.add_worksheet('Borders')
|
252
|
+
|
253
|
+
worksheet.set_column(0, 4, 10)
|
254
|
+
worksheet.set_column(5, 5, 40)
|
255
|
+
|
256
|
+
worksheet.write(0, 0, "Index", heading)
|
257
|
+
worksheet.write(0, 1, "Index", heading)
|
258
|
+
worksheet.write(0, 3, "Style", heading)
|
259
|
+
worksheet.write(0, 5, "The style is highlighted in red for ", heading)
|
260
|
+
worksheet.write(1, 5, "emphasis, the default color is black.", heading)
|
261
|
+
|
262
|
+
0.upto(13) do |i|
|
263
|
+
format = workbook.add_format()
|
264
|
+
format.set_border(i)
|
265
|
+
format.set_border_color('red')
|
266
|
+
format.set_align('center')
|
267
|
+
|
268
|
+
worksheet.write((2*(i+1)), 0, i, center)
|
269
|
+
worksheet.write((2*(i+1)), 1, sprintf("0x%02X", i), center)
|
270
|
+
|
271
|
+
worksheet.write((2*(i+1)), 3, "Border", format)
|
272
|
+
end
|
273
|
+
|
274
|
+
worksheet.write(30, 0, "Diag type", heading)
|
275
|
+
worksheet.write(30, 1, "Index", heading)
|
276
|
+
worksheet.write(30, 3, "Style", heading)
|
277
|
+
worksheet.write(30, 5, "Diagonal Boder styles", heading)
|
278
|
+
|
279
|
+
1.upto(3) do |i|
|
280
|
+
format = workbook.add_format()
|
281
|
+
format.set_diag_type(i)
|
282
|
+
format.set_diag_border(1)
|
283
|
+
format.set_diag_color('red')
|
284
|
+
format.set_align('center')
|
285
|
+
|
286
|
+
worksheet.write((2*(i+15)), 0, i, center)
|
287
|
+
worksheet.write((2*(i+15)), 1, sprintf("0x%02X", i), center)
|
288
|
+
|
289
|
+
worksheet.write((2*(i+15)), 3, "Border", format)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
######################################################################
|
296
|
+
#
|
297
|
+
# Demonstrate the standard Excel cell patterns.
|
298
|
+
#
|
299
|
+
def patterns(workbook, heading, center)
|
300
|
+
|
301
|
+
worksheet = workbook.add_worksheet('Patterns')
|
302
|
+
|
303
|
+
worksheet.set_column(0, 4, 10)
|
304
|
+
worksheet.set_column(5, 5, 50)
|
305
|
+
|
306
|
+
worksheet.write(0, 0, "Index", heading)
|
307
|
+
worksheet.write(0, 1, "Index", heading)
|
308
|
+
worksheet.write(0, 3, "Pattern", heading)
|
309
|
+
|
310
|
+
worksheet.write(0, 5, "The background colour has been set to silver.", heading)
|
311
|
+
worksheet.write(1, 5, "The foreground colour has been set to green.", heading)
|
312
|
+
|
313
|
+
0.upto(18) do |i|
|
314
|
+
format = workbook.add_format()
|
315
|
+
|
316
|
+
format.set_pattern(i)
|
317
|
+
format.set_bg_color('silver')
|
318
|
+
format.set_fg_color('green')
|
319
|
+
format.set_align('center')
|
320
|
+
|
321
|
+
worksheet.write((2*(i+1)), 0, i, center)
|
322
|
+
worksheet.write((2*(i+1)), 1, sprintf("0x%02X", i), center)
|
323
|
+
|
324
|
+
worksheet.write((2*(i+1)), 3, "Pattern", format)
|
325
|
+
|
326
|
+
if i == 1
|
327
|
+
worksheet.write((2*(i+1)), 5, "This is solid colour, the most useful pattern.", heading)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
|
333
|
+
######################################################################
|
334
|
+
#
|
335
|
+
# Demonstrate the standard Excel cell alignments.
|
336
|
+
#
|
337
|
+
def alignment(workbook, heading, center)
|
338
|
+
|
339
|
+
worksheet = workbook.add_worksheet('Alignment')
|
340
|
+
|
341
|
+
worksheet.set_column(0, 7, 12)
|
342
|
+
worksheet.set_row(0, 40)
|
343
|
+
worksheet.set_selection(7, 0)
|
344
|
+
|
345
|
+
format01 = workbook.add_format()
|
346
|
+
format02 = workbook.add_format()
|
347
|
+
format03 = workbook.add_format()
|
348
|
+
format04 = workbook.add_format()
|
349
|
+
format05 = workbook.add_format()
|
350
|
+
format06 = workbook.add_format()
|
351
|
+
format07 = workbook.add_format()
|
352
|
+
format08 = workbook.add_format()
|
353
|
+
format09 = workbook.add_format()
|
354
|
+
format10 = workbook.add_format()
|
355
|
+
format11 = workbook.add_format()
|
356
|
+
format12 = workbook.add_format()
|
357
|
+
format13 = workbook.add_format()
|
358
|
+
format14 = workbook.add_format()
|
359
|
+
format15 = workbook.add_format()
|
360
|
+
format16 = workbook.add_format()
|
361
|
+
format17 = workbook.add_format()
|
362
|
+
|
363
|
+
format02.set_align('top')
|
364
|
+
format03.set_align('bottom')
|
365
|
+
format04.set_align('vcenter')
|
366
|
+
format05.set_align('vjustify')
|
367
|
+
format06.set_text_wrap()
|
368
|
+
|
369
|
+
format07.set_align('left')
|
370
|
+
format08.set_align('right')
|
371
|
+
format09.set_align('center')
|
372
|
+
format10.set_align('fill')
|
373
|
+
format11.set_align('justify')
|
374
|
+
format12.set_merge()
|
375
|
+
|
376
|
+
format13.set_rotation(45)
|
377
|
+
format14.set_rotation(-45)
|
378
|
+
format15.set_rotation(270)
|
379
|
+
|
380
|
+
format16.set_shrink()
|
381
|
+
format17.set_indent(1)
|
382
|
+
|
383
|
+
worksheet.write(0, 0, 'Vertical', heading)
|
384
|
+
worksheet.write(0, 1, 'top', format02)
|
385
|
+
worksheet.write(0, 2, 'bottom', format03)
|
386
|
+
worksheet.write(0, 3, 'vcenter', format04)
|
387
|
+
worksheet.write(0, 4, 'vjustify', format05)
|
388
|
+
worksheet.write(0, 5, "text\nwrap", format06)
|
389
|
+
|
390
|
+
worksheet.write(2, 0, 'Horizontal', heading)
|
391
|
+
worksheet.write(2, 1, 'left', format07)
|
392
|
+
worksheet.write(2, 2, 'right', format08)
|
393
|
+
worksheet.write(2, 3, 'center', format09)
|
394
|
+
worksheet.write(2, 4, 'fill', format10)
|
395
|
+
worksheet.write(2, 5, 'justify', format11)
|
396
|
+
|
397
|
+
worksheet.write(3, 1, 'merge', format12)
|
398
|
+
worksheet.write(3, 2, '', format12)
|
399
|
+
|
400
|
+
worksheet.write(3, 3, 'Shrink ' * 3, format16)
|
401
|
+
worksheet.write(3, 4, 'Indent', format17)
|
402
|
+
|
403
|
+
|
404
|
+
worksheet.write(5, 0, 'Rotation', heading)
|
405
|
+
worksheet.write(5, 1, 'Rotate 45', format13)
|
406
|
+
worksheet.write(6, 1, 'Rotate -45', format14)
|
407
|
+
worksheet.write(7, 1, 'Rotate 270', format15)
|
408
|
+
end
|
409
|
+
|
410
|
+
|
411
|
+
######################################################################
|
412
|
+
#
|
413
|
+
# Demonstrate other miscellaneous features.
|
414
|
+
#
|
415
|
+
def misc(workbook)
|
416
|
+
|
417
|
+
worksheet = workbook.add_worksheet('Miscellaneous')
|
418
|
+
|
419
|
+
worksheet.set_column(2, 2, 25)
|
420
|
+
|
421
|
+
format01 = workbook.add_format()
|
422
|
+
format02 = workbook.add_format()
|
423
|
+
format03 = workbook.add_format()
|
424
|
+
format04 = workbook.add_format()
|
425
|
+
format05 = workbook.add_format()
|
426
|
+
format06 = workbook.add_format()
|
427
|
+
format07 = workbook.add_format()
|
428
|
+
|
429
|
+
format01.set_underline(0x01)
|
430
|
+
format02.set_underline(0x02)
|
431
|
+
format03.set_underline(0x21)
|
432
|
+
format04.set_underline(0x22)
|
433
|
+
format05.set_font_strikeout()
|
434
|
+
format06.set_font_outline()
|
435
|
+
format07.set_font_shadow()
|
436
|
+
|
437
|
+
worksheet.write(1, 2, 'Underline 0x01', format01)
|
438
|
+
worksheet.write(3, 2, 'Underline 0x02', format02)
|
439
|
+
worksheet.write(5, 2, 'Underline 0x21', format03)
|
440
|
+
worksheet.write(7, 2, 'Underline 0x22', format04)
|
441
|
+
worksheet.write(9, 2, 'Strikeout', format05)
|
442
|
+
worksheet.write(11, 2, 'Outline (Macintosh only)', format06)
|
443
|
+
worksheet.write(13, 2, 'Shadow (Macintosh only)', format07)
|
444
|
+
end
|
445
|
+
|
446
|
+
|
447
|
+
######################################################################
|
448
|
+
#
|
449
|
+
# main
|
450
|
+
#
|
451
|
+
workbook = WriteExcel.new('formats.xls')
|
452
|
+
|
453
|
+
# Some common formats
|
454
|
+
center = workbook.add_format(:align => 'center')
|
455
|
+
heading = workbook.add_format(:align => 'center', :bold => 1)
|
456
|
+
|
457
|
+
# The named colors
|
458
|
+
COLORS = {
|
459
|
+
0x08 => 'black',
|
460
|
+
0x0C => 'blue',
|
461
|
+
0x10 => 'brown',
|
462
|
+
0x0F => 'cyan',
|
463
|
+
0x17 => 'gray',
|
464
|
+
0x11 => 'green',
|
465
|
+
0x0B => 'lime',
|
466
|
+
0x0E => 'magenta',
|
467
|
+
0x12 => 'navy',
|
468
|
+
0x35 => 'orange',
|
469
|
+
0x21 => 'pink',
|
470
|
+
0x14 => 'purple',
|
471
|
+
0x0A => 'red',
|
472
|
+
0x16 => 'silver',
|
473
|
+
0x09 => 'white',
|
474
|
+
0x0D => 'yellow',
|
475
|
+
}
|
476
|
+
|
477
|
+
# Call these subroutines to demonstrate different formatting options
|
478
|
+
intro(workbook)
|
479
|
+
fonts(workbook, heading, center)
|
480
|
+
named_colors(workbook, heading, center)
|
481
|
+
standard_colors(workbook, heading, center)
|
482
|
+
numeric_formats(workbook, heading, center)
|
483
|
+
borders(workbook, heading, center)
|
484
|
+
patterns(workbook, heading, center)
|
485
|
+
alignment(workbook, heading, center)
|
486
|
+
misc(workbook)
|
487
|
+
|
488
|
+
# Note: this is required
|
489
|
+
workbook.close
|
490
|
+
|