write_xlsx 0.75.0 → 0.76.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changes +4 -0
- data/Gemfile +8 -2
- data/README.md +4 -2
- data/lib/write_xlsx/chart/axis.rb +69 -96
- data/lib/write_xlsx/chart/bar.rb +18 -21
- data/lib/write_xlsx/chart/caption.rb +1 -1
- data/lib/write_xlsx/chart/column.rb +1 -5
- data/lib/write_xlsx/chart/line.rb +2 -16
- data/lib/write_xlsx/chart/pie.rb +18 -40
- data/lib/write_xlsx/chart/radar.rb +2 -5
- data/lib/write_xlsx/chart/scatter.rb +24 -32
- data/lib/write_xlsx/chart/series.rb +218 -236
- data/lib/write_xlsx/chart/stock.rb +15 -27
- data/lib/write_xlsx/chart.rb +303 -392
- data/lib/write_xlsx/chartsheet.rb +22 -20
- data/lib/write_xlsx/colors.rb +9 -15
- data/lib/write_xlsx/drawing.rb +26 -28
- data/lib/write_xlsx/format.rb +15 -15
- data/lib/write_xlsx/package/comments.rb +1 -1
- data/lib/write_xlsx/package/conditional_format.rb +8 -8
- data/lib/write_xlsx/package/relationships.rb +4 -15
- data/lib/write_xlsx/package/styles.rb +9 -16
- data/lib/write_xlsx/shape.rb +1 -15
- data/lib/write_xlsx/sparkline.rb +1 -1
- data/lib/write_xlsx/utility.rb +69 -13
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +19 -7
- data/lib/write_xlsx/worksheet/cell_data.rb +1 -1
- data/lib/write_xlsx/worksheet/hyperlink.rb +39 -37
- data/lib/write_xlsx/worksheet.rb +44 -72
- data/lib/write_xlsx/zip_file_utils.rb +99 -0
- data/test/chart/test_add_series.rb +5 -5
- data/test/chart/test_write_d_lbls.rb +1 -1
- data/test/chart/test_write_major_gridlines.rb +1 -1
- data/test/chart/test_write_marker.rb +1 -1
- data/test/chart/test_write_number_format.rb +1 -1
- data/test/helper.rb +7 -4
- data/test/regression/klt.csv +4 -0
- data/test/regression/test_chart_column07.rb +44 -0
- data/test/regression/test_chart_column08.rb +46 -0
- data/test/regression/test_chart_date01.rb +57 -0
- data/test/regression/test_chart_date02.rb +59 -0
- data/test/regression/test_chart_date03.rb +59 -0
- data/test/regression/test_chart_date04.rb +61 -0
- data/test/regression/test_chart_stock01.rb +1 -6
- data/test/regression/test_chart_title02.rb +44 -0
- data/test/regression/test_escapes01.rb +1 -1
- data/test/regression/test_escapes02.rb +1 -1
- data/test/regression/test_escapes03.rb +1 -1
- data/test/regression/test_escapes04.rb +1 -1
- data/test/regression/test_escapes05.rb +1 -1
- data/test/regression/test_escapes06.rb +1 -1
- data/test/regression/test_escapes07.rb +1 -1
- data/test/regression/test_escapes08.rb +1 -1
- data/test/regression/test_set_column09.rb +31 -0
- data/test/regression/test_shared_strings_encoding.rb +103 -0
- data/test/regression/xlsx_files/chart_column07.xlsx +0 -0
- data/test/regression/xlsx_files/chart_column08.xlsx +0 -0
- data/test/regression/xlsx_files/chart_date01.xlsx +0 -0
- data/test/regression/xlsx_files/chart_date02.xlsx +0 -0
- data/test/regression/xlsx_files/chart_date03.xlsx +0 -0
- data/test/regression/xlsx_files/chart_date04.xlsx +0 -0
- data/test/regression/xlsx_files/chart_title02.xlsx +0 -0
- data/test/regression/xlsx_files/set_column09.xlsx +0 -0
- data/test/regression/xlsx_files/shared_strings_encoding.xlsx +0 -0
- data/test/worksheet/test_write_hyperlink.rb +10 -15
- data/write_xlsx.gemspec +0 -3
- metadata +48 -39
- data/test/worksheet/test_set_column.rb +0 -25
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartColumn08 < 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_column08
|
14
|
+
@xlsx = 'chart_column08.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, [68809856, 68811392])
|
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$2,Sheet1!$A$4:$A$5)',
|
32
|
+
:values => '=(Sheet1!$B$1:$B$2,Sheet1!$B$4:$B$5)',
|
33
|
+
:categories_data => [1, 2, 4, 5],
|
34
|
+
:values_data => [2, 4, 8, 10]
|
35
|
+
)
|
36
|
+
|
37
|
+
worksheet.insert_chart('E9', chart)
|
38
|
+
|
39
|
+
workbook.close
|
40
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx),
|
41
|
+
@xlsx,
|
42
|
+
nil,
|
43
|
+
nil
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartDate01 < 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_date01
|
14
|
+
@xlsx = 'chart_date01.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'line', :embedded => 1)
|
18
|
+
date_format = workbook.add_format(:num_format => 14)
|
19
|
+
|
20
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
21
|
+
chart.instance_variable_set(:@axis_ids, [73655040, 73907584])
|
22
|
+
|
23
|
+
worksheet.set_column('A:A', 12)
|
24
|
+
|
25
|
+
dates = [
|
26
|
+
'2013-01-01T', '2013-01-02T', '2013-01-03T', '2013-01-04T',
|
27
|
+
'2013-01-05T', '2013-01-06T', '2013-01-07T', '2013-01-08T',
|
28
|
+
'2013-01-09T', '2013-01-10T'
|
29
|
+
]
|
30
|
+
|
31
|
+
data = [10, 30, 20, 40, 20, 60, 50, 40, 30, 30]
|
32
|
+
|
33
|
+
dates.each_with_index do |date_time, row|
|
34
|
+
worksheet.write_date_time(row, 0, date_time, date_format)
|
35
|
+
worksheet.write(row, 1, data[row])
|
36
|
+
end
|
37
|
+
|
38
|
+
chart.add_series(
|
39
|
+
:categories => '=Sheet1!$A$1:$A$10',
|
40
|
+
:values => '=Sheet1!$B$1:$B$10'
|
41
|
+
)
|
42
|
+
|
43
|
+
chart.set_x_axis(
|
44
|
+
:num_format => 'dd/mm/yyyy',
|
45
|
+
:num_format_linked => 1,
|
46
|
+
:date_axis => 1
|
47
|
+
)
|
48
|
+
|
49
|
+
worksheet.insert_chart('E9', chart)
|
50
|
+
|
51
|
+
workbook.close
|
52
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx,
|
53
|
+
nil,
|
54
|
+
{'xl/charts/chart1.xml' => ['<c:formatCode']}
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartDate02 < 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_date02
|
14
|
+
@xlsx = 'chart_date02.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'line', :embedded => 1)
|
18
|
+
date_format = workbook.add_format(:num_format => 14)
|
19
|
+
|
20
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
21
|
+
chart.instance_variable_set(:@axis_ids, [55112064, 55115136])
|
22
|
+
|
23
|
+
worksheet.set_column('A:A', 12)
|
24
|
+
|
25
|
+
dates = [
|
26
|
+
'2013-01-01T', '2013-01-02T', '2013-01-03T', '2013-01-04T',
|
27
|
+
'2013-01-05T', '2013-01-06T', '2013-01-07T', '2013-01-08T',
|
28
|
+
'2013-01-09T', '2013-01-10T'
|
29
|
+
]
|
30
|
+
|
31
|
+
data = [10, 30, 20, 40, 20, 60, 50, 40, 30, 30]
|
32
|
+
|
33
|
+
dates.each_with_index do |date_time, row|
|
34
|
+
worksheet.write_date_time(row, 0, date_time, date_format)
|
35
|
+
worksheet.write(row, 1, data[row])
|
36
|
+
end
|
37
|
+
|
38
|
+
chart.add_series(
|
39
|
+
:categories => '=Sheet1!$A$1:$A$10',
|
40
|
+
:values => '=Sheet1!$B$1:$B$10'
|
41
|
+
)
|
42
|
+
|
43
|
+
chart.set_x_axis(
|
44
|
+
:date_axis => 1,
|
45
|
+
:min => worksheet.convert_date_time('2013-01-02T'),
|
46
|
+
:max => worksheet.convert_date_time('2013-01-09T'),
|
47
|
+
:num_format => 'dd/mm/yyyy',
|
48
|
+
:num_format_linked => 1,
|
49
|
+
)
|
50
|
+
|
51
|
+
worksheet.insert_chart('E9', chart)
|
52
|
+
|
53
|
+
workbook.close
|
54
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx,
|
55
|
+
nil,
|
56
|
+
{'xl/charts/chart1.xml' => ['<c:formatCode']}
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartDate03 < 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_date03
|
14
|
+
@xlsx = 'chart_date03.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'line', :embedded => 1)
|
18
|
+
date_format = workbook.add_format(:num_format => 14)
|
19
|
+
|
20
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
21
|
+
chart.instance_variable_set(:@axis_ids, [51761152, 51762688])
|
22
|
+
|
23
|
+
worksheet.set_column('A:A', 12)
|
24
|
+
|
25
|
+
dates = [
|
26
|
+
'2013-01-01T', '2013-01-02T', '2013-01-03T', '2013-01-04T',
|
27
|
+
'2013-01-05T', '2013-01-06T', '2013-01-07T', '2013-01-08T',
|
28
|
+
'2013-01-09T', '2013-01-10T'
|
29
|
+
]
|
30
|
+
|
31
|
+
data = [10, 30, 20, 40, 20, 60, 50, 40, 30, 30]
|
32
|
+
|
33
|
+
dates.each_with_index do |date_time, row|
|
34
|
+
worksheet.write_date_time(row, 0, date_time, date_format)
|
35
|
+
worksheet.write(row, 1, data[row])
|
36
|
+
end
|
37
|
+
|
38
|
+
chart.add_series(
|
39
|
+
:categories => '=Sheet1!$A$1:$A$10',
|
40
|
+
:values => '=Sheet1!$B$1:$B$10'
|
41
|
+
)
|
42
|
+
|
43
|
+
chart.set_x_axis(
|
44
|
+
:date_axis => 1,
|
45
|
+
:minor_unit => 1,
|
46
|
+
:major_unit => 1,
|
47
|
+
:num_format => 'dd/mm/yyyy',
|
48
|
+
:num_format_linked => 1,
|
49
|
+
)
|
50
|
+
|
51
|
+
worksheet.insert_chart('E9', chart)
|
52
|
+
|
53
|
+
workbook.close
|
54
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx,
|
55
|
+
nil,
|
56
|
+
{'xl/charts/chart1.xml' => ['<c:formatCode']}
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartDate04 < 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_date04
|
14
|
+
@xlsx = 'chart_date04.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'line', :embedded => 1)
|
18
|
+
date_format = workbook.add_format(:num_format => 14)
|
19
|
+
|
20
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
21
|
+
chart.instance_variable_set(:@axis_ids, [51761152, 51762688])
|
22
|
+
|
23
|
+
worksheet.set_column('A:A', 12)
|
24
|
+
|
25
|
+
dates = [
|
26
|
+
'2013-01-01T', '2013-01-02T', '2013-01-03T', '2013-01-04T',
|
27
|
+
'2013-01-05T', '2013-01-06T', '2013-01-07T', '2013-01-08T',
|
28
|
+
'2013-01-09T', '2013-01-10T'
|
29
|
+
]
|
30
|
+
|
31
|
+
data = [10, 30, 20, 40, 20, 60, 50, 40, 30, 30]
|
32
|
+
|
33
|
+
dates.each_with_index do |date_time, row|
|
34
|
+
worksheet.write_date_time(row, 0, date_time, date_format)
|
35
|
+
worksheet.write(row, 1, data[row])
|
36
|
+
end
|
37
|
+
|
38
|
+
chart.add_series(
|
39
|
+
:categories => '=Sheet1!$A$1:$A$10',
|
40
|
+
:values => '=Sheet1!$B$1:$B$10'
|
41
|
+
)
|
42
|
+
|
43
|
+
chart.set_x_axis(
|
44
|
+
:date_axis => 1,
|
45
|
+
:minor_unit => 1,
|
46
|
+
:minor_unit_type => 'months',
|
47
|
+
:major_unit => 1,
|
48
|
+
:major_unit_type => 'years',
|
49
|
+
:num_format => 'dd/mm/yyyy',
|
50
|
+
:num_format_linked => 1,
|
51
|
+
)
|
52
|
+
|
53
|
+
worksheet.insert_chart('E9', chart)
|
54
|
+
|
55
|
+
workbook.close
|
56
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx,
|
57
|
+
nil,
|
58
|
+
{'xl/charts/chart1.xml' => ['<c:formatCode']}
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
@@ -61,12 +61,7 @@ class TestRegressionChartStock01 < Test::Unit::TestCase
|
|
61
61
|
File.join(@regression_output, @xlsx),
|
62
62
|
@xlsx,
|
63
63
|
nil,
|
64
|
-
{
|
65
|
-
'xl/charts/chart1.xml' => [ '<c:formatCode', ],
|
66
|
-
|
67
|
-
# Ignore the workbookView.
|
68
|
-
'xl/workbook.xml' => ['<workbookView']
|
69
|
-
}
|
64
|
+
{'xl/charts/chart1.xml' => [ '<c:formatCode', ]}
|
70
65
|
)
|
71
66
|
end
|
72
67
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartTitle02 < 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_title02
|
14
|
+
@xlsx = 'chart_title02.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, [73655040, 73656576 ])
|
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(:values => '=Sheet1!$A$1:$A$5')
|
31
|
+
|
32
|
+
chart.set_title(:name => 'Title!')
|
33
|
+
|
34
|
+
worksheet.insert_chart('E9', chart)
|
35
|
+
|
36
|
+
workbook.close
|
37
|
+
compare_xlsx_for_regression(
|
38
|
+
File.join(@regression_output, @xlsx),
|
39
|
+
@xlsx,
|
40
|
+
nil,
|
41
|
+
nil
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
@@ -10,7 +10,7 @@ class TestRegressionEscapes01 < Test::Unit::TestCase
|
|
10
10
|
File.delete(@xlsx) if File.exist?(@xlsx)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def test_escapes01
|
14
14
|
@xlsx = 'escapes01.xlsx'
|
15
15
|
workbook = WriteXLSX.new(@xlsx)
|
16
16
|
worksheet = workbook.add_worksheet('5&4')
|
@@ -10,7 +10,7 @@ class TestRegressionEscapes05 < Test::Unit::TestCase
|
|
10
10
|
File.delete(@xlsx) if File.exist?(@xlsx)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def test_escapes05
|
14
14
|
@xlsx = 'escapes05.xlsx'
|
15
15
|
workbook = WriteXLSX.new(@xlsx)
|
16
16
|
worksheet1 = workbook.add_worksheet('Start')
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionSetColumn09 < 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_set_column09
|
14
|
+
@xlsx = 'set_column09.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
|
18
|
+
# Test the order and overwriting of columns.
|
19
|
+
worksheet.set_column('A:A', 100)
|
20
|
+
worksheet.set_column('F:H', 8)
|
21
|
+
worksheet.set_column('C:D', 12)
|
22
|
+
worksheet.set_column('A:A', 10)
|
23
|
+
worksheet.set_column('XFD:XFD', 5)
|
24
|
+
worksheet.set_column('ZZ:ZZ', 3)
|
25
|
+
|
26
|
+
workbook.close
|
27
|
+
|
28
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx)
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# -*- coding: iso-8859-8 -*-
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
class TestRegressionSharedStringsEncoding < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
setup_dir_var
|
8
|
+
@f = File.open(File.join(@test_dir, 'regression', 'klt.csv'), "r:iso-8859-8")
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
File.delete(@xlsx) if File.exist?(@xlsx)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_shared_strings_encoding
|
16
|
+
sizes = [10, 10, 18, 10, 18, 18, 12, 16, 16, 25,
|
17
|
+
18, 36, 60, 16, 16, 16, 18, 16, 16, 22,
|
18
|
+
14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
19
|
+
14, 14, 14, 14, 14, 14]
|
20
|
+
|
21
|
+
# input_file = ARGV[0]
|
22
|
+
# output_file = ARGV[1]
|
23
|
+
|
24
|
+
# coding: ISO-8859-8
|
25
|
+
# Encoding.default_external = Encoding.find("ISO-8859-8")
|
26
|
+
|
27
|
+
# define an array to hold the Sikum records
|
28
|
+
|
29
|
+
# loop through each record in the csv file, adding
|
30
|
+
# each record to our array.
|
31
|
+
#f = File.open(input_file, "r")
|
32
|
+
@xlsx = 'shared_strings_encoding.xlsx'
|
33
|
+
workbook = WriteXLSX.new(@xlsx)
|
34
|
+
heading1 = workbook.add_format(:align => 'center', :bold => 1 , :size => 12 , :color => 'blue', :bg_color => 27)
|
35
|
+
heading2 = workbook.add_format(:align => 'center', :bold => 1 , :size => 12 , :color => 'blue', :bg_color => 'silver')
|
36
|
+
format1 = workbook.add_format(:align => 'right', :color => 'blue', :bg_color => 9 )
|
37
|
+
format11 = workbook.add_format(:align => 'right', :color => 'blue', :bg_color => 9 )
|
38
|
+
format11.set_num_format('0.00')
|
39
|
+
format3 = workbook.add_format(:align => 'right', :color => 'red', :bg_color => 9 )
|
40
|
+
worksheet = workbook.add_worksheet
|
41
|
+
worksheet.right_to_left
|
42
|
+
|
43
|
+
i=0
|
44
|
+
|
45
|
+
@f.each_line { |line|
|
46
|
+
words = line.split(',')
|
47
|
+
if i == 0 then
|
48
|
+
for j in 0..words.size-1
|
49
|
+
|
50
|
+
word = words[j].to_s.gsub(/"/," ")
|
51
|
+
word = word.gsub(/\n/, "" )
|
52
|
+
word = word.gsub(/\r/, "" )
|
53
|
+
|
54
|
+
# worksheet.merge_range( 'A1:L1', word.force_encoding('iso-8859-8').encode("UTF-8"), heading1)
|
55
|
+
worksheet.merge_range( 'A1:L1', word, heading1)
|
56
|
+
end
|
57
|
+
elsif i == 1 then
|
58
|
+
for j in 0..words.size-1
|
59
|
+
|
60
|
+
word = words[j].to_s.gsub(/"/," ")
|
61
|
+
word = word.gsub(/\n/, "" )
|
62
|
+
word = word.gsub(/\r/, "" )
|
63
|
+
|
64
|
+
worksheet.set_column(j,0,sizes[j])
|
65
|
+
# worksheet.write( i, j, word.force_encoding('iso-8859-8').encode("UTF-8"), heading2)
|
66
|
+
worksheet.write( i, j, word, heading2)
|
67
|
+
end
|
68
|
+
else
|
69
|
+
|
70
|
+
heara = words[11].to_s
|
71
|
+
for j in 0..words.size-1
|
72
|
+
|
73
|
+
jj=j
|
74
|
+
word = words[j].to_s.gsub("_"," ")
|
75
|
+
word = word.gsub(/\n/, "" )
|
76
|
+
word = word.gsub(/\r/, "" )
|
77
|
+
word = word.lstrip.rstrip
|
78
|
+
|
79
|
+
if heara.include?('abcdefghijklml') then
|
80
|
+
# worksheet.write( i, jj, word.force_encoding('iso-8859-8').encode("UTF-8"), format3)
|
81
|
+
worksheet.write( i, jj, word, format3)
|
82
|
+
else
|
83
|
+
# worksheet.write( i, jj, word.force_encoding('iso-8859-8').encode("UTF-8"), format1)
|
84
|
+
worksheet.write( i, jj, word, format1)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
i = i+1
|
89
|
+
}
|
90
|
+
|
91
|
+
workbook.close
|
92
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx)
|
93
|
+
end
|
94
|
+
|
95
|
+
def input_file
|
96
|
+
<<EOS
|
97
|
+
����� ������� ������ ������
|
98
|
+
����� ����,��� ����,�� ����,���� ����,���� ����,��,���� ������,����,����,����,�����,����
|
99
|
+
01/11/2012,09:04:20,_���� , 131, 39977777,����������� ,00171044973, , ,�� ����� , ,����� ����/����� �� ���� ������
|
100
|
+
01/11/2012,09:04:24,_���� , 131, 36888865,������� ,00171081635,���� ������ ,���� ������ ,�� ����� , ,
|
101
|
+
EOS
|
102
|
+
end
|
103
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -9,36 +9,31 @@ class TestWriteHyperlink < Test::Unit::TestCase
|
|
9
9
|
@worksheet = @workbook.add_worksheet('')
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def test_attributes
|
13
13
|
hyperlink = Writexlsx::Worksheet::Hyperlink.factory('')
|
14
|
-
|
15
|
-
|
16
|
-
expected = '<hyperlink ref="A1" r:id="rId1"/>'
|
14
|
+
result = hyperlink.attributes(0, 0, 1)
|
15
|
+
expected = [ ['ref', 'A1'], ['r:id', 'rId1']]
|
17
16
|
assert_equal(expected, result)
|
18
17
|
end
|
19
18
|
|
20
19
|
def test_write_hyperlink_internal_sheet2
|
21
20
|
hyperlink = Writexlsx::Worksheet::Hyperlink.factory('internal:Sheet2!A1', 'Sheet2!A1')
|
22
|
-
|
23
|
-
|
24
|
-
expected = '<hyperlink ref="A1" location="Sheet2!A1" display="Sheet2!A1"/>'
|
21
|
+
result = hyperlink.attributes(0, 0)
|
22
|
+
expected = [%w(ref A1), %w(location Sheet2!A1), %w(display Sheet2!A1)]
|
25
23
|
assert_equal(expected, result)
|
26
24
|
end
|
27
25
|
|
28
26
|
def test_write_hyperlink_internal_quoted_sheet
|
29
27
|
hyperlink = Writexlsx::Worksheet::Hyperlink.factory("internal:'Data Sheet'!D5", "'Data Sheet'!D5")
|
30
|
-
|
31
|
-
|
32
|
-
expected = %q{<hyperlink ref="A5" location="'Data Sheet'!D5" display="'Data Sheet'!D5"/>}
|
28
|
+
result = hyperlink.attributes(4, 0)
|
29
|
+
expected = [%w(ref A5), ["location", "'Data Sheet'!D5"], ["display", "'Data Sheet'!D5"]]
|
33
30
|
assert_equal(expected, result)
|
34
31
|
end
|
35
32
|
|
36
33
|
def test_write_hyperlink_internal_tooltip
|
37
|
-
hyperlink = Writexlsx::Worksheet::Hyperlink.factory('internal:Sheet2!A1', 'Sheet2!A1')
|
38
|
-
|
39
|
-
|
40
|
-
result = @worksheet.instance_variable_get(:@writer).string
|
41
|
-
expected = '<hyperlink ref="A18" location="Sheet2!A1" tooltip="Screen Tip 1" display="Sheet2!A1"/>'
|
34
|
+
hyperlink = Writexlsx::Worksheet::Hyperlink.factory('internal:Sheet2!A1', 'Sheet2!A1', 'Screen Tip 1')
|
35
|
+
result = hyperlink.attributes(17, 0)
|
36
|
+
expected = [%w(ref A18), %w(location Sheet2!A1), ["tooltip", "Screen Tip 1"], %w(display Sheet2!A1)]
|
42
37
|
assert_equal(expected, result)
|
43
38
|
end
|
44
39
|
end
|