write_xlsx 0.0.2
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/Gemfile +12 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +82 -0
- data/Rakefile +78 -0
- data/VERSION +1 -0
- data/examples/a_simple.rb +45 -0
- data/examples/array_formula.rb +33 -0
- data/examples/autofilter.rb +235 -0
- data/examples/chart_area.rb +59 -0
- data/examples/chart_bar.rb +59 -0
- data/examples/chart_column.rb +58 -0
- data/examples/chart_line.rb +59 -0
- data/examples/chart_pie.rb +49 -0
- data/examples/chart_scatter.rb +59 -0
- data/examples/chart_stock.rb +65 -0
- data/examples/colors.rb +130 -0
- data/examples/comments1.rb +12 -0
- data/examples/comments2.rb +335 -0
- data/examples/conditional_format.rb +67 -0
- data/examples/data_validate.rb +279 -0
- data/examples/defined_name.rb +28 -0
- data/examples/demo.rb +104 -0
- data/examples/diag_border.rb +26 -0
- data/examples/headers.rb +119 -0
- data/examples/hide_sheet.rb +30 -0
- data/examples/hyperlink1.rb +58 -0
- data/examples/indent.rb +28 -0
- data/examples/merge1.rb +38 -0
- data/examples/merge2.rb +48 -0
- data/examples/merge3.rb +43 -0
- data/examples/merge4.rb +82 -0
- data/examples/merge5.rb +70 -0
- data/examples/merge6.rb +48 -0
- data/examples/outline.rb +252 -0
- data/examples/properties.rb +33 -0
- data/examples/protection.rb +34 -0
- data/examples/rich_strings.rb +42 -0
- data/examples/right_to_left.rb +24 -0
- data/examples/tab_colors.rb +26 -0
- data/lib/write_xlsx.rb +77 -0
- data/lib/write_xlsx/chart.rb +3027 -0
- data/lib/write_xlsx/chart/area.rb +52 -0
- data/lib/write_xlsx/chart/bar.rb +126 -0
- data/lib/write_xlsx/chart/column.rb +132 -0
- data/lib/write_xlsx/chart/line.rb +51 -0
- data/lib/write_xlsx/chart/pie.rb +210 -0
- data/lib/write_xlsx/chart/scatter.rb +252 -0
- data/lib/write_xlsx/chart/stock.rb +134 -0
- data/lib/write_xlsx/chartsheet.rb +173 -0
- data/lib/write_xlsx/colors.rb +65 -0
- data/lib/write_xlsx/compatibility.rb +71 -0
- data/lib/write_xlsx/drawing.rb +547 -0
- data/lib/write_xlsx/format.rb +683 -0
- data/lib/write_xlsx/package/app.rb +218 -0
- data/lib/write_xlsx/package/comments.rb +221 -0
- data/lib/write_xlsx/package/content_types.rb +189 -0
- data/lib/write_xlsx/package/core.rb +196 -0
- data/lib/write_xlsx/package/packager.rb +510 -0
- data/lib/write_xlsx/package/relationships.rb +98 -0
- data/lib/write_xlsx/package/shared_strings.rb +96 -0
- data/lib/write_xlsx/package/styles.rb +705 -0
- data/lib/write_xlsx/package/theme.rb +45 -0
- data/lib/write_xlsx/package/vml.rb +386 -0
- data/lib/write_xlsx/package/xml_writer_simple.rb +90 -0
- data/lib/write_xlsx/utility.rb +113 -0
- data/lib/write_xlsx/workbook.rb +1488 -0
- data/lib/write_xlsx/worksheet.rb +6578 -0
- data/lib/write_xlsx/zip_file_utils.rb +98 -0
- data/test/chart/test_add_series.rb +113 -0
- data/test/chart/test_process_names.rb +27 -0
- data/test/chart/test_write_auto.rb +15 -0
- data/test/chart/test_write_ax_id.rb +15 -0
- data/test/chart/test_write_ax_pos.rb +15 -0
- data/test/chart/test_write_chart_space.rb +15 -0
- data/test/chart/test_write_cross_ax.rb +15 -0
- data/test/chart/test_write_crosses.rb +15 -0
- data/test/chart/test_write_format_code.rb +15 -0
- data/test/chart/test_write_idx.rb +15 -0
- data/test/chart/test_write_label_align.rb +15 -0
- data/test/chart/test_write_label_offset.rb +15 -0
- data/test/chart/test_write_lang.rb +15 -0
- data/test/chart/test_write_layout.rb +15 -0
- data/test/chart/test_write_legend.rb +16 -0
- data/test/chart/test_write_legend_pos.rb +15 -0
- data/test/chart/test_write_major_gridlines.rb +15 -0
- data/test/chart/test_write_marker.rb +17 -0
- data/test/chart/test_write_marker_size.rb +15 -0
- data/test/chart/test_write_marker_value.rb +16 -0
- data/test/chart/test_write_num_cache.rb +16 -0
- data/test/chart/test_write_num_fmt.rb +16 -0
- data/test/chart/test_write_number_format.rb +15 -0
- data/test/chart/test_write_order.rb +15 -0
- data/test/chart/test_write_orientation.rb +15 -0
- data/test/chart/test_write_page_margins.rb +15 -0
- data/test/chart/test_write_page_setup.rb +15 -0
- data/test/chart/test_write_plot_vis_only.rb +15 -0
- data/test/chart/test_write_pt.rb +16 -0
- data/test/chart/test_write_pt_count.rb +16 -0
- data/test/chart/test_write_series_formula.rb +16 -0
- data/test/chart/test_write_style.rb +41 -0
- data/test/chart/test_write_symbol.rb +16 -0
- data/test/chart/test_write_tick_lbl_pos.rb +16 -0
- data/test/chart/test_write_v.rb +16 -0
- data/test/drawing/test_drawing_chart_01.rb +50 -0
- data/test/drawing/test_drawing_image_01.rb +59 -0
- data/test/helper.rb +90 -0
- data/test/package/app/test_app01.rb +44 -0
- data/test/package/app/test_app02.rb +46 -0
- data/test/package/app/test_app03.rb +53 -0
- data/test/package/comments/test_comments01.rb +36 -0
- data/test/package/comments/test_write_text_t.rb +44 -0
- data/test/package/content_types/test_content_types.rb +35 -0
- data/test/package/content_types/test_write_default.rb +13 -0
- data/test/package/content_types/test_write_override.rb +13 -0
- data/test/package/core/test_core01.rb +28 -0
- data/test/package/core/test_core02.rb +42 -0
- data/test/package/relationships/test_relationships.rb +28 -0
- data/test/package/relationships/test_sheet_rels.rb +22 -0
- data/test/package/shared_strings/test_shared_strings01.rb +30 -0
- data/test/package/shared_strings/test_shared_strings02.rb +30 -0
- data/test/package/shared_strings/test_write_si.rb +13 -0
- data/test/package/shared_strings/test_write_sst.rb +15 -0
- data/test/package/styles/test_styles_01.rb +69 -0
- data/test/package/styles/test_styles_02.rb +104 -0
- data/test/package/styles/test_styles_03.rb +90 -0
- data/test/package/styles/test_styles_04.rb +216 -0
- data/test/package/styles/test_styles_05.rb +150 -0
- data/test/package/styles/test_styles_06.rb +104 -0
- data/test/package/styles/test_styles_07.rb +104 -0
- data/test/package/styles/test_styles_08.rb +109 -0
- data/test/package/styles/test_styles_09.rb +95 -0
- data/test/package/vml/test_vml_01.rb +42 -0
- data/test/package/vml/test_write_anchor.rb +14 -0
- data/test/package/vml/test_write_auto_fill.rb +14 -0
- data/test/package/vml/test_write_column.rb +14 -0
- data/test/package/vml/test_write_div.rb +14 -0
- data/test/package/vml/test_write_fill.rb +14 -0
- data/test/package/vml/test_write_idmap.rb +14 -0
- data/test/package/vml/test_write_move_with_cells.rb +14 -0
- data/test/package/vml/test_write_path.rb +22 -0
- data/test/package/vml/test_write_row.rb +14 -0
- data/test/package/vml/test_write_shadow.rb +14 -0
- data/test/package/vml/test_write_shapelayout.rb +14 -0
- data/test/package/vml/test_write_shapetype.rb +14 -0
- data/test/package/vml/test_write_size_with_cells.rb +14 -0
- data/test/package/vml/test_write_stroke.rb +14 -0
- data/test/package/vml/test_write_textbox.rb +14 -0
- data/test/perl_output/a_simple.xlsx +0 -0
- data/test/perl_output/array_formula.xlsx +0 -0
- data/test/perl_output/autofilter.xlsx +0 -0
- data/test/perl_output/chart_area.xlsx +0 -0
- data/test/perl_output/chart_bar.xlsx +0 -0
- data/test/perl_output/chart_column.xlsx +0 -0
- data/test/perl_output/chart_line.xlsx +0 -0
- data/test/perl_output/chart_pie.xlsx +0 -0
- data/test/perl_output/chart_scatter.xlsx +0 -0
- data/test/perl_output/chart_stock.xlsx +0 -0
- data/test/perl_output/comments1.xlsx +0 -0
- data/test/perl_output/comments2.xlsx +0 -0
- data/test/perl_output/conditional_format.xlsx +0 -0
- data/test/perl_output/data_validate.xlsx +0 -0
- data/test/perl_output/defined_name.xlsx +0 -0
- data/test/perl_output/demo.xlsx +0 -0
- data/test/perl_output/diag_border.xlsx +0 -0
- data/test/perl_output/fit_to_pages.xlsx +0 -0
- data/test/perl_output/headers.xlsx +0 -0
- data/test/perl_output/hide_sheet.xlsx +0 -0
- data/test/perl_output/hyperlink.xlsx +0 -0
- data/test/perl_output/indent.xlsx +0 -0
- data/test/perl_output/merge1.xlsx +0 -0
- data/test/perl_output/merge2.xlsx +0 -0
- data/test/perl_output/merge3.xlsx +0 -0
- data/test/perl_output/merge4.xlsx +0 -0
- data/test/perl_output/merge5.xlsx +0 -0
- data/test/perl_output/merge6.xlsx +0 -0
- data/test/perl_output/outline.xlsx +0 -0
- data/test/perl_output/print_scale.xlsx +0 -0
- data/test/perl_output/properties.xlsx +0 -0
- data/test/perl_output/protection.xlsx +0 -0
- data/test/perl_output/rich_strings.xlsx +0 -0
- data/test/perl_output/right_to_left.xlsx +0 -0
- data/test/perl_output/tab_colors.xlsx +0 -0
- data/test/test_delete_files.rb +37 -0
- data/test/test_example_match.rb +2281 -0
- data/test/test_xml_writer_simple.rb +63 -0
- data/test/workbook/test_get_chart_range.rb +59 -0
- data/test/workbook/test_sort_defined_names.rb +77 -0
- data/test/workbook/test_workbook_01.rb +29 -0
- data/test/workbook/test_workbook_02.rb +31 -0
- data/test/workbook/test_workbook_03.rb +31 -0
- data/test/workbook/test_workbook_new.rb +18 -0
- data/test/workbook/test_write_defined_name.rb +17 -0
- data/test/workbook/test_write_defined_names.rb +41 -0
- data/test/worksheet/test_calculate_spans.rb +58 -0
- data/test/worksheet/test_convert_date_time_01.rb +439 -0
- data/test/worksheet/test_convert_date_time_02.rb +478 -0
- data/test/worksheet/test_convert_date_time_03.rb +435 -0
- data/test/worksheet/test_extract_filter_tokens.rb +109 -0
- data/test/worksheet/test_parse_filter_expression.rb +143 -0
- data/test/worksheet/test_position_object.rb +50 -0
- data/test/worksheet/test_repeat_formula.rb +55 -0
- data/test/worksheet/test_worksheet_01.rb +32 -0
- data/test/worksheet/test_worksheet_02.rb +38 -0
- data/test/worksheet/test_worksheet_03.rb +44 -0
- data/test/worksheet/test_worksheet_04.rb +45 -0
- data/test/worksheet/test_write_array_formula_01.rb +99 -0
- data/test/worksheet/test_write_autofilter.rb +260 -0
- data/test/worksheet/test_write_brk.rb +18 -0
- data/test/worksheet/test_write_cell.rb +49 -0
- data/test/worksheet/test_write_cell_value.rb +33 -0
- data/test/worksheet/test_write_col_breaks.rb +27 -0
- data/test/worksheet/test_write_col_info.rb +95 -0
- data/test/worksheet/test_write_conditional_formatting.rb +72 -0
- data/test/worksheet/test_write_custom_filter.rb +18 -0
- data/test/worksheet/test_write_custom_filters.rb +25 -0
- data/test/worksheet/test_write_data_validation_01.rb +113 -0
- data/test/worksheet/test_write_data_validation_02.rb +528 -0
- data/test/worksheet/test_write_dimension.rb +94 -0
- data/test/worksheet/test_write_ext.rb +18 -0
- data/test/worksheet/test_write_ext_lst.rb +18 -0
- data/test/worksheet/test_write_filter.rb +18 -0
- data/test/worksheet/test_write_filter_column.rb +18 -0
- data/test/worksheet/test_write_filters.rb +32 -0
- data/test/worksheet/test_write_header_footer.rb +53 -0
- data/test/worksheet/test_write_hyperlink.rb +39 -0
- data/test/worksheet/test_write_hyperlinks.rb +27 -0
- data/test/worksheet/test_write_legacy_drawing.rb +19 -0
- data/test/worksheet/test_write_merge_cell.rb +18 -0
- data/test/worksheet/test_write_merge_cells.rb +192 -0
- data/test/worksheet/test_write_methods.rb +353 -0
- data/test/worksheet/test_write_mx_plv.rb +19 -0
- data/test/worksheet/test_write_page_margins.rb +98 -0
- data/test/worksheet/test_write_page_set_up_pr.rb +19 -0
- data/test/worksheet/test_write_page_setup.rb +54 -0
- data/test/worksheet/test_write_pane.rb +123 -0
- data/test/worksheet/test_write_phonetic_pr.rb +19 -0
- data/test/worksheet/test_write_print_options.rb +77 -0
- data/test/worksheet/test_write_row_breaks.rb +27 -0
- data/test/worksheet/test_write_row_element.rb +69 -0
- data/test/worksheet/test_write_selection.rb +18 -0
- data/test/worksheet/test_write_sheet_calc_pr.rb +18 -0
- data/test/worksheet/test_write_sheet_data.rb +18 -0
- data/test/worksheet/test_write_sheet_format_pr.rb +18 -0
- data/test/worksheet/test_write_sheet_pr.rb +36 -0
- data/test/worksheet/test_write_sheet_protection.rb +174 -0
- data/test/worksheet/test_write_sheet_view.rb +62 -0
- data/test/worksheet/test_write_sheet_view1.rb +64 -0
- data/test/worksheet/test_write_sheet_view2.rb +56 -0
- data/test/worksheet/test_write_sheet_view3.rb +83 -0
- data/test/worksheet/test_write_sheet_view4.rb +83 -0
- data/test/worksheet/test_write_sheet_view5.rb +74 -0
- data/test/worksheet/test_write_sheet_view6.rb +51 -0
- data/test/worksheet/test_write_sheet_view7.rb +71 -0
- data/test/worksheet/test_write_sheet_view8.rb +51 -0
- data/test/worksheet/test_write_sheet_view9.rb +51 -0
- data/test/worksheet/test_write_tab_color.rb +23 -0
- data/test/worksheet/test_write_worksheet.rb +19 -0
- data/write_xlsx.gemspec +308 -0
- metadata +363 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require 'rubygems'
|
4
|
+
require 'write_xlsx'
|
5
|
+
|
6
|
+
workbook = WriteXLSX.new('comments1.xlsx')
|
7
|
+
worksheet = workbook.add_worksheet
|
8
|
+
|
9
|
+
worksheet.write('A1', 'Hello')
|
10
|
+
worksheet.write_comment('A1', 'This is a comment')
|
11
|
+
|
12
|
+
workbook.close
|
@@ -0,0 +1,335 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require 'rubygems'
|
4
|
+
require 'write_xlsx'
|
5
|
+
|
6
|
+
workbook = WriteXLSX.new('comments2.xlsx')
|
7
|
+
|
8
|
+
text_wrap = workbook.add_format( :text_wrap => 1, :valign => 'top' )
|
9
|
+
worksheet1 = workbook.add_worksheet
|
10
|
+
worksheet2 = workbook.add_worksheet
|
11
|
+
worksheet3 = workbook.add_worksheet
|
12
|
+
worksheet4 = workbook.add_worksheet
|
13
|
+
worksheet5 = workbook.add_worksheet
|
14
|
+
worksheet6 = workbook.add_worksheet
|
15
|
+
worksheet7 = workbook.add_worksheet
|
16
|
+
worksheet8 = workbook.add_worksheet
|
17
|
+
|
18
|
+
|
19
|
+
# Variables that we will use in each example.
|
20
|
+
cell_text = ''
|
21
|
+
comment = ''
|
22
|
+
|
23
|
+
|
24
|
+
###############################################################################
|
25
|
+
#
|
26
|
+
# Example 1. Demonstrates a simple cell comments without formatting.
|
27
|
+
# comments.
|
28
|
+
#
|
29
|
+
|
30
|
+
# Set up some formatting.
|
31
|
+
worksheet1.set_column( 'C:C', 25 )
|
32
|
+
worksheet1.set_row( 2, 50 )
|
33
|
+
worksheet1.set_row( 5, 50 )
|
34
|
+
|
35
|
+
|
36
|
+
# Simple ascii string.
|
37
|
+
cell_text = 'Hold the mouse over this cell to see the comment.'
|
38
|
+
|
39
|
+
comment = 'This is a comment.'
|
40
|
+
|
41
|
+
worksheet1.write( 'C3', cell_text, text_wrap )
|
42
|
+
worksheet1.write_comment( 'C3', comment )
|
43
|
+
|
44
|
+
cell_text = 'This is a UTF-8 string.'
|
45
|
+
comment = '☺'
|
46
|
+
|
47
|
+
worksheet1.write( 'C6', cell_text, text_wrap )
|
48
|
+
worksheet1.write_comment( 'C6', comment )
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
###############################################################################
|
53
|
+
#
|
54
|
+
# Example 2. Demonstrates visible and hidden comments.
|
55
|
+
#
|
56
|
+
|
57
|
+
# Set up some formatting.
|
58
|
+
worksheet2.set_column( 'C:C', 25 )
|
59
|
+
worksheet2.set_row( 2, 50 )
|
60
|
+
worksheet2.set_row( 5, 50 )
|
61
|
+
|
62
|
+
|
63
|
+
cell_text = 'This cell comment is visible.'
|
64
|
+
|
65
|
+
comment = 'Hello.'
|
66
|
+
|
67
|
+
worksheet2.write( 'C3', cell_text, text_wrap )
|
68
|
+
worksheet2.write_comment( 'C3', comment, :visible => 1 )
|
69
|
+
|
70
|
+
|
71
|
+
cell_text = "This cell comment isn't visible (the default)."
|
72
|
+
|
73
|
+
comment = 'Hello.'
|
74
|
+
|
75
|
+
worksheet2.write( 'C6', cell_text, text_wrap )
|
76
|
+
worksheet2.write_comment( 'C6', comment )
|
77
|
+
|
78
|
+
|
79
|
+
###############################################################################
|
80
|
+
#
|
81
|
+
# Example 3. Demonstrates visible and hidden comments set at the worksheet
|
82
|
+
# level.
|
83
|
+
#
|
84
|
+
|
85
|
+
# Set up some formatting.
|
86
|
+
worksheet3.set_column( 'C:C', 25 )
|
87
|
+
worksheet3.set_row( 2, 50 )
|
88
|
+
worksheet3.set_row( 5, 50 )
|
89
|
+
worksheet3.set_row( 8, 50 )
|
90
|
+
|
91
|
+
# Make all comments on the worksheet visible.
|
92
|
+
worksheet3.show_comments
|
93
|
+
|
94
|
+
cell_text = 'This cell comment is visible, explicitly.'
|
95
|
+
|
96
|
+
comment = 'Hello.'
|
97
|
+
|
98
|
+
worksheet3.write( 'C3', cell_text, text_wrap )
|
99
|
+
worksheet3.write_comment( 'C3', comment, :visible => 1 )
|
100
|
+
|
101
|
+
|
102
|
+
cell_text =
|
103
|
+
'This cell comment is also visible because we used show_comments().'
|
104
|
+
|
105
|
+
comment = 'Hello.'
|
106
|
+
|
107
|
+
worksheet3.write( 'C6', cell_text, text_wrap )
|
108
|
+
worksheet3.write_comment( 'C6', comment )
|
109
|
+
|
110
|
+
|
111
|
+
cell_text = 'However, we can still override it locally.'
|
112
|
+
|
113
|
+
comment = 'Hello.'
|
114
|
+
|
115
|
+
worksheet3.write( 'C9', cell_text, text_wrap )
|
116
|
+
worksheet3.write_comment( 'C9', comment, :visible => 0 )
|
117
|
+
|
118
|
+
|
119
|
+
###############################################################################
|
120
|
+
#
|
121
|
+
# Example 4. Demonstrates changes to the comment box dimensions.
|
122
|
+
#
|
123
|
+
|
124
|
+
# Set up some formatting.
|
125
|
+
worksheet4.set_column( 'C:C', 25 )
|
126
|
+
worksheet4.set_row( 2, 50 )
|
127
|
+
worksheet4.set_row( 5, 50 )
|
128
|
+
worksheet4.set_row( 8, 50 )
|
129
|
+
worksheet4.set_row( 15, 50 )
|
130
|
+
|
131
|
+
worksheet4.show_comments
|
132
|
+
|
133
|
+
cell_text = 'This cell comment is default size.'
|
134
|
+
|
135
|
+
comment = 'Hello.'
|
136
|
+
|
137
|
+
worksheet4.write( 'C3', cell_text, text_wrap )
|
138
|
+
worksheet4.write_comment( 'C3', comment )
|
139
|
+
|
140
|
+
|
141
|
+
cell_text = 'This cell comment is twice as wide.'
|
142
|
+
|
143
|
+
comment = 'Hello.'
|
144
|
+
|
145
|
+
worksheet4.write( 'C6', cell_text, text_wrap )
|
146
|
+
worksheet4.write_comment( 'C6', comment, :x_scale => 2 )
|
147
|
+
|
148
|
+
|
149
|
+
cell_text = 'This cell comment is twice as high.'
|
150
|
+
|
151
|
+
comment = 'Hello.'
|
152
|
+
|
153
|
+
worksheet4.write( 'C9', cell_text, text_wrap )
|
154
|
+
worksheet4.write_comment( 'C9', comment, :y_scale => 2 )
|
155
|
+
|
156
|
+
|
157
|
+
cell_text = 'This cell comment is scaled in both directions.'
|
158
|
+
|
159
|
+
comment = 'Hello.'
|
160
|
+
|
161
|
+
worksheet4.write( 'C16', cell_text, text_wrap )
|
162
|
+
worksheet4.write_comment( 'C16', comment, :x_scale => 1.2, :y_scale => 0.8 )
|
163
|
+
|
164
|
+
|
165
|
+
cell_text = 'This cell comment has width and height specified in pixels.'
|
166
|
+
|
167
|
+
comment = 'Hello.'
|
168
|
+
|
169
|
+
worksheet4.write( 'C19', cell_text, text_wrap )
|
170
|
+
worksheet4.write_comment( 'C19', comment, :width => 200, :height => 20 )
|
171
|
+
|
172
|
+
|
173
|
+
###############################################################################
|
174
|
+
#
|
175
|
+
# Example 5. Demonstrates changes to the cell comment position.
|
176
|
+
#
|
177
|
+
|
178
|
+
worksheet5.set_column( 'C:C', 25 )
|
179
|
+
worksheet5.set_row( 2, 50 )
|
180
|
+
worksheet5.set_row( 5, 50 )
|
181
|
+
worksheet5.set_row( 8, 50 )
|
182
|
+
worksheet5.set_row( 11, 50 )
|
183
|
+
|
184
|
+
worksheet5.show_comments
|
185
|
+
|
186
|
+
cell_text = 'This cell comment is in the default position.'
|
187
|
+
|
188
|
+
comment = 'Hello.'
|
189
|
+
|
190
|
+
worksheet5.write( 'C3', cell_text, text_wrap )
|
191
|
+
worksheet5.write_comment( 'C3', comment )
|
192
|
+
|
193
|
+
|
194
|
+
cell_text = 'This cell comment has been moved to another cell.'
|
195
|
+
|
196
|
+
comment = 'Hello.'
|
197
|
+
|
198
|
+
worksheet5.write( 'C6', cell_text, text_wrap )
|
199
|
+
worksheet5.write_comment( 'C6', comment, :start_cell => 'E4' )
|
200
|
+
|
201
|
+
|
202
|
+
cell_text = 'This cell comment has been moved to another cell.'
|
203
|
+
|
204
|
+
comment = 'Hello.'
|
205
|
+
|
206
|
+
worksheet5.write( 'C9', cell_text, text_wrap )
|
207
|
+
worksheet5.write_comment( 'C9', comment, :start_row => 8, :start_col => 4 )
|
208
|
+
|
209
|
+
|
210
|
+
cell_text = 'This cell comment has been shifted within its default cell.'
|
211
|
+
|
212
|
+
comment = 'Hello.'
|
213
|
+
|
214
|
+
worksheet5.write( 'C12', cell_text, text_wrap )
|
215
|
+
worksheet5.write_comment( 'C12', comment, :x_offset => 30, :y_offset => 12 )
|
216
|
+
|
217
|
+
|
218
|
+
###############################################################################
|
219
|
+
#
|
220
|
+
# Example 6. Demonstrates changes to the comment background colour.
|
221
|
+
#
|
222
|
+
|
223
|
+
worksheet6.set_column( 'C:C', 25 )
|
224
|
+
worksheet6.set_row( 2, 50 )
|
225
|
+
worksheet6.set_row( 5, 50 )
|
226
|
+
worksheet6.set_row( 8, 50 )
|
227
|
+
|
228
|
+
worksheet6.show_comments
|
229
|
+
|
230
|
+
cell_text = 'This cell comment has a different colour.'
|
231
|
+
|
232
|
+
comment = 'Hello.'
|
233
|
+
|
234
|
+
worksheet6.write( 'C3', cell_text, text_wrap )
|
235
|
+
worksheet6.write_comment( 'C3', comment, :color => 'green' )
|
236
|
+
|
237
|
+
|
238
|
+
cell_text = 'This cell comment has the default colour.'
|
239
|
+
|
240
|
+
comment = 'Hello.'
|
241
|
+
|
242
|
+
worksheet6.write( 'C6', cell_text, text_wrap )
|
243
|
+
worksheet6.write_comment( 'C6', comment )
|
244
|
+
|
245
|
+
|
246
|
+
cell_text = 'This cell comment has a different colour.'
|
247
|
+
|
248
|
+
comment = 'Hello.'
|
249
|
+
|
250
|
+
worksheet6.write( 'C9', cell_text, text_wrap )
|
251
|
+
worksheet6.write_comment( 'C9', comment, :color => 0x35 )
|
252
|
+
|
253
|
+
|
254
|
+
###############################################################################
|
255
|
+
#
|
256
|
+
# Example 7. Demonstrates how to set the cell comment author.
|
257
|
+
#
|
258
|
+
|
259
|
+
worksheet7.set_column( 'C:C', 30 )
|
260
|
+
worksheet7.set_row( 2, 50 )
|
261
|
+
worksheet7.set_row( 5, 50 )
|
262
|
+
worksheet7.set_row( 8, 50 )
|
263
|
+
|
264
|
+
author = ''
|
265
|
+
cell = 'C3'
|
266
|
+
|
267
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
268
|
+
"by #{author}' (blank) in the status bar at the bottom"
|
269
|
+
|
270
|
+
comment = 'Hello.'
|
271
|
+
|
272
|
+
worksheet7.write( cell, cell_text, text_wrap )
|
273
|
+
worksheet7.write_comment( cell, comment )
|
274
|
+
|
275
|
+
|
276
|
+
author = 'Ruby'
|
277
|
+
cell = 'C6'
|
278
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
279
|
+
"by #{author}' in the status bar at the bottom"
|
280
|
+
|
281
|
+
comment = 'Hello.'
|
282
|
+
|
283
|
+
worksheet7.write( cell, cell_text, text_wrap )
|
284
|
+
worksheet7.write_comment( cell, comment, :author => author )
|
285
|
+
|
286
|
+
|
287
|
+
author = '€'
|
288
|
+
cell = 'C9'
|
289
|
+
cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
|
290
|
+
"by #{author}' in the status bar at the bottom"
|
291
|
+
comment = 'Hello.'
|
292
|
+
|
293
|
+
worksheet7.write( cell, cell_text, text_wrap )
|
294
|
+
worksheet7.write_comment( cell, comment, :author => author )
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
###############################################################################
|
300
|
+
#
|
301
|
+
# Example 8. Demonstrates the need to explicitly set the row height.
|
302
|
+
#
|
303
|
+
|
304
|
+
# Set up some formatting.
|
305
|
+
worksheet8.set_column( 'C:C', 25 )
|
306
|
+
worksheet8.set_row( 2, 80 )
|
307
|
+
|
308
|
+
worksheet8.show_comments
|
309
|
+
|
310
|
+
|
311
|
+
cell_text =
|
312
|
+
'The height of this row has been adjusted explicitly using ' +
|
313
|
+
'set_row(). The size of the comment box is adjusted ' +
|
314
|
+
'accordingly by Excel::Writer::XLSX.'
|
315
|
+
|
316
|
+
comment = 'Hello.'
|
317
|
+
|
318
|
+
worksheet8.write( 'C3', cell_text, text_wrap )
|
319
|
+
worksheet8.write_comment( 'C3', comment )
|
320
|
+
|
321
|
+
|
322
|
+
cell_text =
|
323
|
+
'The height of this row has been adjusted by Excel due to the ' +
|
324
|
+
'text wrap property being set. Unfortunately this means that ' +
|
325
|
+
'the height of the row is unknown to Excel::Writer::XLSX at ' +
|
326
|
+
"run time and thus the comment box is stretched as well.\n\n" +
|
327
|
+
'Use set_row() to specify the row height explicitly to avoid ' +
|
328
|
+
'this problem.'
|
329
|
+
|
330
|
+
comment = 'Hello.'
|
331
|
+
|
332
|
+
worksheet8.write( 'C6', cell_text, text_wrap )
|
333
|
+
worksheet8.write_comment( 'C6', comment )
|
334
|
+
|
335
|
+
workbook.close
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'write_xlsx'
|
6
|
+
|
7
|
+
workbook = WriteXLSX.new('conditional_format.xlsx')
|
8
|
+
worksheet1 = workbook.add_worksheet
|
9
|
+
|
10
|
+
# Light red fill with dark red text.
|
11
|
+
format1 = workbook.add_format(
|
12
|
+
:bg_color => '#FFC7CE',
|
13
|
+
:color => '#9C0006'
|
14
|
+
)
|
15
|
+
|
16
|
+
# Green fill with dark green text.
|
17
|
+
format2 = workbook.add_format(
|
18
|
+
:bg_color => '#C6EFCE',
|
19
|
+
:color => '#006100'
|
20
|
+
)
|
21
|
+
|
22
|
+
# Some sample data to run the conditional formatting against.
|
23
|
+
data = [
|
24
|
+
[ 90, 80, 50, 10, 20, 90, 40, 90, 30, 40 ],
|
25
|
+
[ 20, 10, 90, 100, 30, 60, 70, 60, 50, 90 ],
|
26
|
+
[ 10, 50, 60, 50, 20, 50, 80, 30, 40, 60 ],
|
27
|
+
[ 10, 90, 20, 40, 10, 40, 50, 70, 90, 50 ],
|
28
|
+
[ 70, 100, 10, 90, 10, 10, 20, 100, 100, 40 ],
|
29
|
+
[ 20, 60, 10, 100, 30, 10, 20, 60, 100, 10 ],
|
30
|
+
[ 10, 60, 10, 80, 100, 80, 30, 30, 70, 40 ],
|
31
|
+
[ 30, 90, 60, 10, 10, 100, 40, 40, 30, 40 ],
|
32
|
+
[ 80, 90, 10, 20, 20, 50, 80, 20, 60, 90 ],
|
33
|
+
[ 60, 80, 30, 30, 10, 50, 80, 60, 50, 30 ]
|
34
|
+
]
|
35
|
+
|
36
|
+
|
37
|
+
# This example below highlights cells that have a value greater than or
|
38
|
+
# equal to 50 in red and cells below that value in green.
|
39
|
+
|
40
|
+
caption = 'Cells with values >= 50 are in light red. ' +
|
41
|
+
'Values < 50 are in light green'
|
42
|
+
|
43
|
+
# Write the data.
|
44
|
+
worksheet1.write('A1', caption)
|
45
|
+
worksheet1.write_col('B3', data)
|
46
|
+
|
47
|
+
# Write a conditional format over a range.
|
48
|
+
worksheet1.conditional_formatting('B3:K12',
|
49
|
+
{
|
50
|
+
:type => 'cell',
|
51
|
+
:format => format1,
|
52
|
+
:criteria => '>=',
|
53
|
+
:value => 50
|
54
|
+
}
|
55
|
+
)
|
56
|
+
|
57
|
+
# Write another conditional format over the same range.
|
58
|
+
worksheet1.conditional_formatting('B3:K12',
|
59
|
+
{
|
60
|
+
:type => 'cell',
|
61
|
+
:format => format2,
|
62
|
+
:criteria => '<',
|
63
|
+
:value => 50
|
64
|
+
}
|
65
|
+
)
|
66
|
+
|
67
|
+
workbook.close
|
@@ -0,0 +1,279 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
###############################################################################
|
5
|
+
#
|
6
|
+
# Example of how to add data validation and dropdown lists to a
|
7
|
+
# WriteExcel file.
|
8
|
+
#
|
9
|
+
# reverse('©'), August 2008, 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 'rubygems'
|
16
|
+
require 'write_xlsx'
|
17
|
+
|
18
|
+
workbook = WriteXLSX.new('data_validate.xlsx')
|
19
|
+
worksheet = workbook.add_worksheet
|
20
|
+
|
21
|
+
# Add a format for the header cells.
|
22
|
+
header_format = workbook.add_format(
|
23
|
+
:border => 1,
|
24
|
+
:bg_color => 43,
|
25
|
+
:bold => 1,
|
26
|
+
:text_wrap => 1,
|
27
|
+
:valign => 'vcenter',
|
28
|
+
:indent => 1
|
29
|
+
)
|
30
|
+
|
31
|
+
# Set up layout of the worksheet.
|
32
|
+
worksheet.set_column('A:A', 68)
|
33
|
+
worksheet.set_column('B:B', 15)
|
34
|
+
worksheet.set_column('D:D', 15)
|
35
|
+
worksheet.set_row(0, 36)
|
36
|
+
worksheet.set_selection('B3')
|
37
|
+
|
38
|
+
|
39
|
+
# Write the header cells and some data that will be used in the examples.
|
40
|
+
row = 0
|
41
|
+
heading1 = 'Some examples of data validation in Excel::Writer::XLSX'
|
42
|
+
heading2 = 'Enter values in this column'
|
43
|
+
heading3 = 'Sample Data'
|
44
|
+
|
45
|
+
worksheet.write('A1', heading1, header_format)
|
46
|
+
worksheet.write('B1', heading2, header_format)
|
47
|
+
worksheet.write('D1', heading3, header_format)
|
48
|
+
|
49
|
+
worksheet.write('D3', ['Integers', 1, 10])
|
50
|
+
worksheet.write('D4', ['List data', 'open', 'high', 'close'])
|
51
|
+
worksheet.write('D5', ['Formula', '=AND(F5=50,G5=60)', 50, 60])
|
52
|
+
|
53
|
+
|
54
|
+
#
|
55
|
+
# Example 1. Limiting input to an integer in a fixed range.
|
56
|
+
#
|
57
|
+
txt = 'Enter an integer between 1 and 10'
|
58
|
+
row += 2
|
59
|
+
|
60
|
+
worksheet.write(row, 0, txt)
|
61
|
+
worksheet.data_validation(row, 1,
|
62
|
+
{
|
63
|
+
:validate => 'integer',
|
64
|
+
:criteria => 'between',
|
65
|
+
:minimum => 1,
|
66
|
+
:maximum => 10
|
67
|
+
})
|
68
|
+
|
69
|
+
|
70
|
+
#
|
71
|
+
# Example 2. Limiting input to an integer outside a fixed range.
|
72
|
+
#
|
73
|
+
txt = 'Enter an integer that is not between 1 and 10 (using cell references)'
|
74
|
+
row += 2
|
75
|
+
|
76
|
+
worksheet.write(row, 0, txt)
|
77
|
+
worksheet.data_validation(row, 1,
|
78
|
+
{
|
79
|
+
:validate => 'integer',
|
80
|
+
:criteria => 'not between',
|
81
|
+
:minimum => '=E3',
|
82
|
+
:maximum => '=F3'
|
83
|
+
})
|
84
|
+
|
85
|
+
|
86
|
+
#
|
87
|
+
# Example 3. Limiting input to an integer greater than a fixed value.
|
88
|
+
#
|
89
|
+
txt = 'Enter an integer greater than 0'
|
90
|
+
row += 2
|
91
|
+
|
92
|
+
worksheet.write(row, 0, txt)
|
93
|
+
worksheet.data_validation(row, 1,
|
94
|
+
{
|
95
|
+
:validate => 'integer',
|
96
|
+
:criteria => '>',
|
97
|
+
:value => 0
|
98
|
+
})
|
99
|
+
|
100
|
+
|
101
|
+
#
|
102
|
+
# Example 4. Limiting input to an integer less than a fixed value.
|
103
|
+
#
|
104
|
+
txt = 'Enter an integer less than 10'
|
105
|
+
row += 2
|
106
|
+
|
107
|
+
worksheet.write(row, 0, txt)
|
108
|
+
worksheet.data_validation(row, 1,
|
109
|
+
{
|
110
|
+
:validate => 'integer',
|
111
|
+
:criteria => '<',
|
112
|
+
:value => 10
|
113
|
+
})
|
114
|
+
|
115
|
+
|
116
|
+
#
|
117
|
+
# Example 5. Limiting input to a decimal in a fixed range.
|
118
|
+
#
|
119
|
+
txt = 'Enter a decimal between 0.1 and 0.5'
|
120
|
+
row += 2
|
121
|
+
|
122
|
+
worksheet.write(row, 0, txt)
|
123
|
+
worksheet.data_validation(row, 1,
|
124
|
+
{
|
125
|
+
:validate => 'decimal',
|
126
|
+
:criteria => 'between',
|
127
|
+
:minimum => 0.1,
|
128
|
+
:maximum => 0.5
|
129
|
+
})
|
130
|
+
|
131
|
+
|
132
|
+
#
|
133
|
+
# Example 6. Limiting input to a value in a dropdown list.
|
134
|
+
#
|
135
|
+
txt = 'Select a value from a drop down list'
|
136
|
+
row += 2
|
137
|
+
bp=1
|
138
|
+
worksheet.write(row, 0, txt)
|
139
|
+
worksheet.data_validation(row, 1,
|
140
|
+
{
|
141
|
+
:validate => 'list',
|
142
|
+
:source => ['open', 'high', 'close']
|
143
|
+
})
|
144
|
+
|
145
|
+
|
146
|
+
#
|
147
|
+
# Example 6. Limiting input to a value in a dropdown list.
|
148
|
+
#
|
149
|
+
txt = 'Select a value from a drop down list (using a cell range)'
|
150
|
+
row += 2
|
151
|
+
|
152
|
+
worksheet.write(row, 0, txt)
|
153
|
+
worksheet.data_validation(row, 1,
|
154
|
+
{
|
155
|
+
:validate => 'list',
|
156
|
+
:source => '=$E$4:$G$4'
|
157
|
+
})
|
158
|
+
|
159
|
+
|
160
|
+
#
|
161
|
+
# Example 7. Limiting input to a date in a fixed range.
|
162
|
+
#
|
163
|
+
txt = 'Enter a date between 1/1/2008 and 12/12/2008'
|
164
|
+
row += 2
|
165
|
+
|
166
|
+
worksheet.write(row, 0, txt)
|
167
|
+
worksheet.data_validation(row, 1,
|
168
|
+
{
|
169
|
+
:validate => 'date',
|
170
|
+
:criteria => 'between',
|
171
|
+
:minimum => '2008-01-01T',
|
172
|
+
:maximum => '2008-12-12T'
|
173
|
+
})
|
174
|
+
|
175
|
+
|
176
|
+
#
|
177
|
+
# Example 8. Limiting input to a time in a fixed range.
|
178
|
+
#
|
179
|
+
txt = 'Enter a time between 6:00 and 12:00'
|
180
|
+
row += 2
|
181
|
+
|
182
|
+
worksheet.write(row, 0, txt)
|
183
|
+
worksheet.data_validation(row, 1,
|
184
|
+
{
|
185
|
+
:validate => 'time',
|
186
|
+
:criteria => 'between',
|
187
|
+
:minimum => 'T06:00',
|
188
|
+
:maximum => 'T12:00'
|
189
|
+
})
|
190
|
+
|
191
|
+
|
192
|
+
#
|
193
|
+
# Example 9. Limiting input to a string greater than a fixed length.
|
194
|
+
#
|
195
|
+
txt = 'Enter a string longer than 3 characters'
|
196
|
+
row += 2
|
197
|
+
|
198
|
+
worksheet.write(row, 0, txt)
|
199
|
+
worksheet.data_validation(row, 1,
|
200
|
+
{
|
201
|
+
:validate => 'length',
|
202
|
+
:criteria => '>',
|
203
|
+
:value => 3
|
204
|
+
})
|
205
|
+
|
206
|
+
|
207
|
+
#
|
208
|
+
# Example 10. Limiting input based on a formula.
|
209
|
+
#
|
210
|
+
txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"'
|
211
|
+
row += 2
|
212
|
+
|
213
|
+
worksheet.write(row, 0, txt)
|
214
|
+
worksheet.data_validation(row, 1,
|
215
|
+
{
|
216
|
+
:validate => 'custom',
|
217
|
+
:value => '=AND(F5=50,G5=60)'
|
218
|
+
})
|
219
|
+
|
220
|
+
|
221
|
+
#
|
222
|
+
# Example 11. Displaying and modify data validation messages.
|
223
|
+
#
|
224
|
+
txt = 'Displays a message when you select the cell'
|
225
|
+
row += 2
|
226
|
+
|
227
|
+
worksheet.write(row, 0, txt)
|
228
|
+
worksheet.data_validation(row, 1,
|
229
|
+
{
|
230
|
+
:validate => 'integer',
|
231
|
+
:criteria => 'between',
|
232
|
+
:minimum => 1,
|
233
|
+
:maximum => 100,
|
234
|
+
:input_title => 'Enter an integer:',
|
235
|
+
:input_message => 'between 1 and 100'
|
236
|
+
})
|
237
|
+
|
238
|
+
|
239
|
+
#
|
240
|
+
# Example 12. Displaying and modify data validation messages.
|
241
|
+
#
|
242
|
+
txt = 'Display a custom error message when integer isn\'t between 1 and 100'
|
243
|
+
row += 2
|
244
|
+
|
245
|
+
worksheet.write(row, 0, txt)
|
246
|
+
worksheet.data_validation(row, 1,
|
247
|
+
{
|
248
|
+
:validate => 'integer',
|
249
|
+
:criteria => 'between',
|
250
|
+
:minimum => 1,
|
251
|
+
:maximum => 100,
|
252
|
+
:input_title => 'Enter an integer:',
|
253
|
+
:input_message => 'between 1 and 100',
|
254
|
+
:error_title => 'Input value is not valid!',
|
255
|
+
:error_message => 'It should be an integer between 1 and 100'
|
256
|
+
})
|
257
|
+
|
258
|
+
|
259
|
+
#
|
260
|
+
# Example 13. Displaying and modify data validation messages.
|
261
|
+
#
|
262
|
+
txt = 'Display a custom information message when integer isn\'t between 1 and 100'
|
263
|
+
row += 2
|
264
|
+
|
265
|
+
worksheet.write(row, 0, txt)
|
266
|
+
worksheet.data_validation(row, 1,
|
267
|
+
{
|
268
|
+
:validate => 'integer',
|
269
|
+
:criteria => 'between',
|
270
|
+
:minimum => 1,
|
271
|
+
:maximum => 100,
|
272
|
+
:input_title => 'Enter an integer:',
|
273
|
+
:input_message => 'between 1 and 100',
|
274
|
+
:error_title => 'Input value is not valid!',
|
275
|
+
:error_message => 'It should be an integer between 1 and 100',
|
276
|
+
:error_type => 'information'
|
277
|
+
})
|
278
|
+
|
279
|
+
workbook.close
|