write_xlsx 0.64.1 → 0.65.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +10 -1
- data/examples/conditional_format.rb +251 -18
- data/examples/demo.rb +2 -3
- data/examples/macros.rb +42 -0
- data/examples/outline_collapsed.rb +160 -0
- data/examples/republic.png +0 -0
- data/examples/shape3.rb +2 -2
- data/examples/shape4.rb +5 -5
- data/examples/shape5.rb +6 -6
- data/examples/shape6.rb +6 -6
- data/examples/shape7.rb +11 -11
- data/examples/shape8.rb +10 -10
- data/examples/shape_all.rb +0 -0
- data/examples/vbaProject.bin +0 -0
- data/lib/write_xlsx/chart.rb +656 -56
- data/lib/write_xlsx/chartsheet.rb +26 -2
- data/lib/write_xlsx/format.rb +50 -27
- data/lib/write_xlsx/formats.rb +32 -0
- data/lib/write_xlsx/package/packager.rb +45 -238
- data/lib/write_xlsx/package/table.rb +9 -18
- data/lib/write_xlsx/package/xml_writer_simple.rb +26 -9
- data/lib/write_xlsx/sheets.rb +223 -0
- data/lib/write_xlsx/sparkline.rb +140 -4
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +34 -121
- data/lib/write_xlsx/worksheet/data_validation.rb +291 -0
- data/lib/write_xlsx/worksheet/hyperlink.rb +111 -0
- data/lib/write_xlsx/worksheet/page_setup.rb +170 -0
- data/lib/write_xlsx/worksheet.rb +1112 -1334
- data/test/helper.rb +1 -1
- data/test/package/styles/test_styles_01.rb +1 -10
- data/test/package/styles/test_styles_02.rb +1 -10
- data/test/package/styles/test_styles_03.rb +1 -10
- data/test/package/styles/test_styles_04.rb +1 -10
- data/test/package/styles/test_styles_05.rb +1 -10
- data/test/package/styles/test_styles_06.rb +1 -10
- data/test/package/styles/test_styles_07.rb +1 -10
- data/test/package/styles/test_styles_08.rb +1 -10
- data/test/package/styles/test_styles_09.rb +1 -10
- data/test/perl_output/conditional_format.xlsx +0 -0
- data/test/perl_output/outline_collapsed.xlsx +0 -0
- data/test/perl_output/protection.xlsx +0 -0
- data/test/regression/test_chart_gap01.rb +47 -0
- data/test/regression/test_chart_gap02.rb +47 -0
- data/test/regression/test_chart_gap03.rb +47 -0
- data/test/regression/test_format05.rb +26 -0
- data/test/regression/test_rich_string12.rb +32 -0
- data/test/regression/xlsx_files/chart_gap01.xlsx +0 -0
- data/test/regression/xlsx_files/chart_gap02.xlsx +0 -0
- data/test/regression/xlsx_files/chart_gap03.xlsx +0 -0
- data/test/regression/xlsx_files/format05.xlsx +0 -0
- data/test/regression/xlsx_files/rich_string12.xlsx +0 -0
- data/test/test_example_match.rb +253 -20
- data/test/worksheet/test_set_column.rb +25 -0
- data/test/worksheet/test_worksheet_03.rb +1 -1
- data/test/worksheet/test_worksheet_04.rb +1 -1
- data/test/worksheet/test_write_array_formula_01.rb +7 -0
- data/test/worksheet/test_write_col_breaks.rb +2 -2
- data/test/worksheet/test_write_col_info.rb +8 -8
- data/test/worksheet/test_write_conditional_formatting.rb +4 -4
- data/test/worksheet/test_write_formula_does_not_change_formula_string.rb +18 -0
- data/test/worksheet/test_write_header_footer.rb +8 -3
- data/test/worksheet/test_write_hyperlink.rb +10 -5
- data/test/worksheet/test_write_merge_cells.rb +6 -6
- data/test/worksheet/test_write_page_set_up_pr.rb +1 -1
- data/test/worksheet/test_write_page_setup.rb +1 -1
- data/test/worksheet/test_write_row_breaks.rb +2 -2
- data/test/worksheet/test_write_row_element.rb +1 -1
- data/test/worksheet/test_write_sheet_pr.rb +2 -2
- data/test/worksheet/test_write_sheet_view.rb +0 -9
- data/test/worksheet/test_write_url.rb +19 -0
- data/test/worksheet/test_write_worksheet_attributes.rb +21 -0
- metadata +38 -5
- data/lib/write_xlsx/worksheet/print_style.rb +0 -51
- data/test/worksheet/test_write_worksheet.rb +0 -19
data/test/helper.rb
CHANGED
@@ -19,7 +19,7 @@ class Writexlsx::Workbook
|
|
19
19
|
# Set the default index for each format. This is mainly used for testing.
|
20
20
|
#
|
21
21
|
def set_default_xf_indices #:nodoc:
|
22
|
-
@formats.each { |format| format.get_xf_index }
|
22
|
+
@formats.formats.each { |format| format.get_xf_index }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -9,16 +9,7 @@ class TestStyles01 < Test::Unit::TestCase
|
|
9
9
|
workbook.__send__('prepare_format_properties')
|
10
10
|
|
11
11
|
@style = Writexlsx::Package::Styles.new
|
12
|
-
@style.set_style_properties(
|
13
|
-
workbook.xf_formats,
|
14
|
-
workbook.palette,
|
15
|
-
workbook.font_count,
|
16
|
-
workbook.num_format_count,
|
17
|
-
workbook.border_count,
|
18
|
-
workbook.fill_count,
|
19
|
-
workbook.custom_colors,
|
20
|
-
workbook.dxf_formats
|
21
|
-
)
|
12
|
+
@style.set_style_properties(*workbook.style_properties)
|
22
13
|
@style.assemble_xml_file
|
23
14
|
result = got_to_array(@style.xml_str)
|
24
15
|
expected = expected_to_array(<<EOS
|
@@ -16,16 +16,7 @@ class TestStyles02 < Test::Unit::TestCase
|
|
16
16
|
workbook.__send__('prepare_format_properties')
|
17
17
|
|
18
18
|
@style = Writexlsx::Package::Styles.new
|
19
|
-
@style.set_style_properties(
|
20
|
-
workbook.xf_formats,
|
21
|
-
workbook.palette,
|
22
|
-
workbook.font_count,
|
23
|
-
workbook.num_format_count,
|
24
|
-
workbook.border_count,
|
25
|
-
workbook.fill_count,
|
26
|
-
workbook.custom_colors,
|
27
|
-
workbook.dxf_formats
|
28
|
-
)
|
19
|
+
@style.set_style_properties(*workbook.style_properties)
|
29
20
|
@style.assemble_xml_file
|
30
21
|
result = got_to_array(@style.xml_str)
|
31
22
|
expected = expected_to_array(<<EOS
|
@@ -16,16 +16,7 @@ class TestStyles03 < Test::Unit::TestCase
|
|
16
16
|
workbook.__send__('prepare_format_properties')
|
17
17
|
|
18
18
|
@style = Writexlsx::Package::Styles.new
|
19
|
-
@style.set_style_properties(
|
20
|
-
workbook.xf_formats,
|
21
|
-
workbook.palette,
|
22
|
-
workbook.font_count,
|
23
|
-
workbook.num_format_count,
|
24
|
-
workbook.border_count,
|
25
|
-
workbook.fill_count,
|
26
|
-
workbook.custom_colors,
|
27
|
-
workbook.dxf_formats
|
28
|
-
)
|
19
|
+
@style.set_style_properties(*workbook.style_properties)
|
29
20
|
@style.assemble_xml_file
|
30
21
|
result = got_to_array(@style.xml_str)
|
31
22
|
expected = expected_to_array(<<EOS
|
@@ -26,16 +26,7 @@ class TestStyles04 < Test::Unit::TestCase
|
|
26
26
|
workbook.__send__('prepare_format_properties')
|
27
27
|
|
28
28
|
@style = Writexlsx::Package::Styles.new
|
29
|
-
@style.set_style_properties(
|
30
|
-
workbook.xf_formats,
|
31
|
-
workbook.palette,
|
32
|
-
workbook.font_count,
|
33
|
-
workbook.num_format_count,
|
34
|
-
workbook.border_count,
|
35
|
-
workbook.fill_count,
|
36
|
-
workbook.custom_colors,
|
37
|
-
workbook.dxf_formats
|
38
|
-
)
|
29
|
+
@style.set_style_properties(*workbook.style_properties)
|
39
30
|
@style.assemble_xml_file
|
40
31
|
result = got_to_array(@style.xml_str)
|
41
32
|
expected = expected_to_array(<<EOS
|
@@ -20,16 +20,7 @@ class TestStyles05 < Test::Unit::TestCase
|
|
20
20
|
workbook.__send__('prepare_format_properties')
|
21
21
|
|
22
22
|
@style = Writexlsx::Package::Styles.new
|
23
|
-
@style.set_style_properties(
|
24
|
-
workbook.xf_formats,
|
25
|
-
workbook.palette,
|
26
|
-
workbook.font_count,
|
27
|
-
workbook.num_format_count,
|
28
|
-
workbook.border_count,
|
29
|
-
workbook.fill_count,
|
30
|
-
workbook.custom_colors,
|
31
|
-
workbook.dxf_formats
|
32
|
-
)
|
23
|
+
@style.set_style_properties(*workbook.style_properties)
|
33
24
|
@style.assemble_xml_file
|
34
25
|
result = got_to_array(@style.xml_str)
|
35
26
|
expected = expected_to_array(<<EOS
|
@@ -26,16 +26,7 @@ class TestStyles06 < Test::Unit::TestCase
|
|
26
26
|
workbook.__send__('prepare_format_properties')
|
27
27
|
|
28
28
|
@style = Writexlsx::Package::Styles.new
|
29
|
-
@style.set_style_properties(
|
30
|
-
workbook.xf_formats,
|
31
|
-
workbook.palette,
|
32
|
-
workbook.font_count,
|
33
|
-
workbook.num_format_count,
|
34
|
-
workbook.border_count,
|
35
|
-
workbook.fill_count,
|
36
|
-
workbook.custom_colors,
|
37
|
-
workbook.dxf_formats
|
38
|
-
)
|
29
|
+
@style.set_style_properties(*workbook.style_properties)
|
39
30
|
@style.assemble_xml_file
|
40
31
|
result = got_to_array(@style.xml_str)
|
41
32
|
expected = expected_to_array(<<EOS
|
@@ -17,16 +17,7 @@ class TestStyles07 < Test::Unit::TestCase
|
|
17
17
|
workbook.__send__('prepare_format_properties')
|
18
18
|
|
19
19
|
@style = Writexlsx::Package::Styles.new
|
20
|
-
@style.set_style_properties(
|
21
|
-
workbook.xf_formats,
|
22
|
-
workbook.palette,
|
23
|
-
workbook.font_count,
|
24
|
-
workbook.num_format_count,
|
25
|
-
workbook.border_count,
|
26
|
-
workbook.fill_count,
|
27
|
-
workbook.custom_colors,
|
28
|
-
workbook.dxf_formats
|
29
|
-
)
|
20
|
+
@style.set_style_properties(*workbook.style_properties)
|
30
21
|
@style.assemble_xml_file
|
31
22
|
result = got_to_array(@style.xml_str)
|
32
23
|
expected = expected_to_array(<<EOS
|
@@ -16,16 +16,7 @@ class TestStyles08 < Test::Unit::TestCase
|
|
16
16
|
workbook.__send__('prepare_format_properties')
|
17
17
|
|
18
18
|
@style = Writexlsx::Package::Styles.new
|
19
|
-
@style.set_style_properties(
|
20
|
-
workbook.xf_formats,
|
21
|
-
workbook.palette,
|
22
|
-
workbook.font_count,
|
23
|
-
workbook.num_format_count,
|
24
|
-
workbook.border_count,
|
25
|
-
workbook.fill_count,
|
26
|
-
workbook.custom_colors,
|
27
|
-
workbook.dxf_formats
|
28
|
-
)
|
19
|
+
@style.set_style_properties(*workbook.style_properties)
|
29
20
|
@style.assemble_xml_file
|
30
21
|
result = got_to_array(@style.xml_str)
|
31
22
|
expected = expected_to_array(<<EOS
|
@@ -22,16 +22,7 @@ class TestStyles09 < Test::Unit::TestCase
|
|
22
22
|
workbook.__send__('prepare_format_properties')
|
23
23
|
|
24
24
|
@style = Writexlsx::Package::Styles.new
|
25
|
-
@style.set_style_properties(
|
26
|
-
workbook.xf_formats,
|
27
|
-
workbook.palette,
|
28
|
-
workbook.font_count,
|
29
|
-
workbook.num_format_count,
|
30
|
-
workbook.border_count,
|
31
|
-
workbook.fill_count,
|
32
|
-
workbook.custom_colors,
|
33
|
-
workbook.dxf_formats
|
34
|
-
)
|
25
|
+
@style.set_style_properties(*workbook.style_properties)
|
35
26
|
@style.assemble_xml_file
|
36
27
|
result = got_to_array(@style.xml_str)
|
37
28
|
expected = expected_to_array(<<EOS
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartGap01 < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
File.delete(@xlsx) if File.exist?(@xlsx)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_chart_gap01
|
14
|
+
@xlsx = 'chart_gap01.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'column', :embedded => 1)
|
18
|
+
|
19
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
20
|
+
chart.instance_variable_set(:@axis_ids, [45438848, 45470464])
|
21
|
+
|
22
|
+
data = [
|
23
|
+
[1, 2, 3, 4, 5],
|
24
|
+
[2, 4, 6, 8, 10],
|
25
|
+
[3, 6, 9, 12, 15]
|
26
|
+
]
|
27
|
+
|
28
|
+
worksheet.write('A1', data)
|
29
|
+
|
30
|
+
chart.add_series(
|
31
|
+
:categories => '=Sheet1!$A$1:$A$5',
|
32
|
+
:values => '=Sheet1!$B$1:$B$5',
|
33
|
+
:overlap => 5,
|
34
|
+
:gap => 157
|
35
|
+
)
|
36
|
+
|
37
|
+
chart.add_series(
|
38
|
+
:categories => '=Sheet1!$A$1:$A$5',
|
39
|
+
:values => '=Sheet1!$C$1:$C$5'
|
40
|
+
)
|
41
|
+
|
42
|
+
worksheet.insert_chart('E9', chart)
|
43
|
+
|
44
|
+
workbook.close
|
45
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartGap02 < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
File.delete(@xlsx) if File.exist?(@xlsx)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_chart_gap02
|
14
|
+
@xlsx = 'chart_gap02.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'column', :embedded => 1)
|
18
|
+
|
19
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
20
|
+
chart.instance_variable_set(:@axis_ids, [45470464, 45472000])
|
21
|
+
|
22
|
+
data = [
|
23
|
+
[1, 2, 3, 4, 5],
|
24
|
+
[2, 4, 6, 8, 10],
|
25
|
+
[3, 6, 9, 12, 15]
|
26
|
+
]
|
27
|
+
|
28
|
+
worksheet.write('A1', data)
|
29
|
+
|
30
|
+
chart.add_series(
|
31
|
+
:categories => '=Sheet1!$A$1:$A$5',
|
32
|
+
:values => '=Sheet1!$B$1:$B$5',
|
33
|
+
:overlap => -100,
|
34
|
+
:gap => 0
|
35
|
+
)
|
36
|
+
|
37
|
+
chart.add_series(
|
38
|
+
:categories => '=Sheet1!$A$1:$A$5',
|
39
|
+
:values => '=Sheet1!$C$1:$C$5'
|
40
|
+
)
|
41
|
+
|
42
|
+
worksheet.insert_chart('E9', chart)
|
43
|
+
|
44
|
+
workbook.close
|
45
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartGap03 < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
File.delete(@xlsx) if File.exist?(@xlsx)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_chart_gap03
|
14
|
+
@xlsx = 'chart_gap03.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'column', :embedded => 1)
|
18
|
+
|
19
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
20
|
+
chart.instance_variable_set(:@axis_ids, [45470464, 45472000])
|
21
|
+
|
22
|
+
data = [
|
23
|
+
[1, 2, 3, 4, 5],
|
24
|
+
[2, 4, 6, 8, 10],
|
25
|
+
[3, 6, 9, 12, 15]
|
26
|
+
]
|
27
|
+
|
28
|
+
worksheet.write('A1', data)
|
29
|
+
|
30
|
+
chart.add_series(
|
31
|
+
:categories => '=Sheet1!$A$1:$A$5',
|
32
|
+
:values => '=Sheet1!$B$1:$B$5',
|
33
|
+
:overlap => 100,
|
34
|
+
:gap => 500
|
35
|
+
)
|
36
|
+
|
37
|
+
chart.add_series(
|
38
|
+
:categories => '=Sheet1!$A$1:$A$5',
|
39
|
+
:values => '=Sheet1!$C$1:$C$5'
|
40
|
+
)
|
41
|
+
|
42
|
+
worksheet.insert_chart('E9', chart)
|
43
|
+
|
44
|
+
workbook.close
|
45
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionFormat05 < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
File.delete(@xlsx) if File.exist?(@xlsx)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_format05
|
14
|
+
@xlsx = 'format05.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
wrap = workbook.add_format(:text_wrap => 1)
|
18
|
+
|
19
|
+
worksheet.set_row(0, 45)
|
20
|
+
|
21
|
+
worksheet.write('A1', "Foo\nBar", wrap)
|
22
|
+
|
23
|
+
workbook.close
|
24
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionRichString12 < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
File.delete(@xlsx) if File.exist?(@xlsx)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_rich_string12
|
14
|
+
@xlsx = 'rich_string12.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
|
18
|
+
worksheet.set_column('A:A', 30)
|
19
|
+
worksheet.set_row(2, 60)
|
20
|
+
|
21
|
+
bold = workbook.add_format(:bold => 1)
|
22
|
+
italic = workbook.add_format(:italic => 1)
|
23
|
+
wrap = workbook.add_format(:text_wrap => 1)
|
24
|
+
|
25
|
+
worksheet.write('A1', 'Foo', bold)
|
26
|
+
worksheet.write('A2', 'Bar', italic)
|
27
|
+
worksheet.write_rich_string('A3', "This is\n", bold, "bold\n", "and this is\n", italic, 'italic', wrap)
|
28
|
+
|
29
|
+
workbook.close
|
30
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx)
|
31
|
+
end
|
32
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|