ricardoo27-writeexcel 0.6.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Workbook < BIFFWriter
|
|
2
|
+
require 'writeexcel/properties'
|
|
3
|
+
require 'writeexcel/helper'
|
|
4
|
+
|
|
5
|
+
class Worksheets < Array
|
|
6
|
+
attr_accessor :activesheet
|
|
7
|
+
attr_writer :firstsheet
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@activesheet = nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def activesheet_index
|
|
14
|
+
index(@activesheet)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def firstsheet_index
|
|
18
|
+
index(@firstsheet) || 0
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def selected_count
|
|
22
|
+
self.select { |sheet| sheet.selected? }.size
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
class WriteFile
|
|
4
|
+
def initialize
|
|
5
|
+
@data = ''
|
|
6
|
+
@datasize = 0
|
|
7
|
+
@limit = 8224
|
|
8
|
+
|
|
9
|
+
# Open a tmp file to store the majority of the Worksheet data. If this fails,
|
|
10
|
+
# for example due to write permissions, store the data in memory. This can be
|
|
11
|
+
# slow for large files.
|
|
12
|
+
@filehandle = Tempfile.new('writeexcel')
|
|
13
|
+
@filehandle.binmode
|
|
14
|
+
|
|
15
|
+
# failed. store temporary data in memory.
|
|
16
|
+
@using_tmpfile = @filehandle ? true : false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
###############################################################################
|
|
20
|
+
#
|
|
21
|
+
# _prepend($data)
|
|
22
|
+
#
|
|
23
|
+
# General storage function
|
|
24
|
+
#
|
|
25
|
+
def prepend(*args)
|
|
26
|
+
data = join_data(args)
|
|
27
|
+
@data = data + @data
|
|
28
|
+
|
|
29
|
+
data
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
###############################################################################
|
|
33
|
+
#
|
|
34
|
+
# _append($data)
|
|
35
|
+
#
|
|
36
|
+
# General storage function
|
|
37
|
+
#
|
|
38
|
+
def append(*args)
|
|
39
|
+
data = join_data(args)
|
|
40
|
+
|
|
41
|
+
if @using_tmpfile
|
|
42
|
+
@filehandle.write(data)
|
|
43
|
+
else
|
|
44
|
+
@data += data
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
data
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def join_data(args)
|
|
53
|
+
data =
|
|
54
|
+
ruby_18 { args.join } ||
|
|
55
|
+
ruby_19 { args.compact.collect{ |arg| arg.dup.force_encoding('ASCII-8BIT') }.join }
|
|
56
|
+
# Add CONTINUE records if necessary
|
|
57
|
+
data = add_continue(data) if data.bytesize > @limit
|
|
58
|
+
|
|
59
|
+
@datasize += data.bytesize
|
|
60
|
+
|
|
61
|
+
data
|
|
62
|
+
end
|
|
63
|
+
end
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/test/helper.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
|
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
7
|
+
require 'writeexcel'
|
|
8
|
+
|
|
9
|
+
class Test::Unit::TestCase
|
|
10
|
+
###############################################################################
|
|
11
|
+
#
|
|
12
|
+
# Unpack the binary data into a format suitable for printing in tests.
|
|
13
|
+
#
|
|
14
|
+
def unpack_record(data)
|
|
15
|
+
data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# expected : existing file path
|
|
19
|
+
# target : io (ex) string io object where stored data.
|
|
20
|
+
def compare_file(expected, target)
|
|
21
|
+
# target is StringIO object.
|
|
22
|
+
result =
|
|
23
|
+
ruby_18 { target.string } ||
|
|
24
|
+
ruby_19 { target.string.force_encoding('BINARY') }
|
|
25
|
+
assert_equal(
|
|
26
|
+
File.binread(expected),
|
|
27
|
+
result,
|
|
28
|
+
"#{File.basename(expected)} doesn't match."
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
# This file contains sample output from the Spreadsheet::WriteExcel Perl
|
|
3
|
+
# module. Used for testing file sizes/contents
|
|
4
|
+
###############################################################################
|
|
5
|
+
|
|
6
|
+
Files:
|
|
7
|
+
|
|
8
|
+
ws_ -> from Worksheet.pm
|
|
9
|
+
f_ -> from Format.pm
|
|
10
|
+
ole_ -> from OLEWriter.pm
|
|
11
|
+
|
|
12
|
+
f_font_biff
|
|
13
|
+
Output of the _get_font call
|
|
14
|
+
|
|
15
|
+
f_font_key
|
|
16
|
+
Output of the _get_font_key call
|
|
17
|
+
|
|
18
|
+
f_xf_biff
|
|
19
|
+
Output of the _get_xf call
|
|
20
|
+
|
|
21
|
+
ws_colinfo
|
|
22
|
+
Output of the _store_colinfo call (default values)
|
|
23
|
+
|
|
24
|
+
ws_store_dimensions
|
|
25
|
+
Output of the _store_dimensions call
|
|
26
|
+
|
|
27
|
+
ws_store_window2
|
|
28
|
+
Output of the _store_window call
|
|
29
|
+
|
|
30
|
+
ws_store_selection
|
|
31
|
+
Output of the _store_selection call
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Arial100004000000327670
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Arial1000040000003276700
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
15
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
14
|
data/test/republic.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
require 'helper'
|
|
3
|
+
|
|
4
|
+
class TC_BIFFWriter < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
def test_IEEE_double
|
|
7
|
+
teststr = [1.2345].pack("d")
|
|
8
|
+
hexdata = [0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F]
|
|
9
|
+
number = hexdata.pack("C8")
|
|
10
|
+
|
|
11
|
+
assert(number == teststr || number == teststr.reverse, "Not Little/Big endian. Give up.")
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
require 'helper'
|
|
3
|
+
require 'stringio'
|
|
4
|
+
|
|
5
|
+
class TC_merge_formats < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@workbook = WriteExcel.new(StringIO.new)
|
|
9
|
+
@worksheet = @workbook.add_worksheet
|
|
10
|
+
@merged_format = @workbook.add_format(:bold => 1)
|
|
11
|
+
@non_merged_format = @workbook.add_format(:bold => 1)
|
|
12
|
+
|
|
13
|
+
@worksheet.set_row( 5, nil, @merged_format)
|
|
14
|
+
@worksheet.set_column('G:G', nil, @merged_format)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_some
|
|
18
|
+
# Test 1 Normal usage.
|
|
19
|
+
assert_nothing_raised { @worksheet.write('A1', 'Test', @non_merged_format) }
|
|
20
|
+
assert_nothing_raised { @worksheet.write('A3:B4', 'Test', @merged_format) }
|
|
21
|
+
|
|
22
|
+
# Test 2 Non merge format in merged cells.
|
|
23
|
+
assert_nothing_raised {
|
|
24
|
+
@worksheet.merge_range('D3:E4', 'Test', @non_merged_format)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# Test 3 Merge format in column.
|
|
28
|
+
assert_nothing_raised { @worksheet.write('G1', 'Test') }
|
|
29
|
+
|
|
30
|
+
# Test 4 Merge format in row.
|
|
31
|
+
assert_nothing_raised { @worksheet.write('A6', 'Test') }
|
|
32
|
+
|
|
33
|
+
# Test 5 Merge format in column and row.
|
|
34
|
+
assert_nothing_raised { @worksheet.write('G6', 'Test') }
|
|
35
|
+
|
|
36
|
+
# Test 6 No merge format in column and row.
|
|
37
|
+
assert_nothing_raised { @worksheet.write('H7', 'Test') }
|
|
38
|
+
|
|
39
|
+
# Test 7 Normal usage again.
|
|
40
|
+
assert_nothing_raised {
|
|
41
|
+
@worksheet.write('A1', 'Test', @non_merged_format)
|
|
42
|
+
}
|
|
43
|
+
assert_nothing_raised {
|
|
44
|
+
@worksheet.merge_range('A3:B4', 'Test', @merged_format)
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
end
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
###############################################################################
|
|
3
|
+
#
|
|
4
|
+
# A test for WriteExcel.
|
|
5
|
+
#
|
|
6
|
+
# Check that the Excel DIMENSIONS record is written correctly.
|
|
7
|
+
#
|
|
8
|
+
# reverse('©'), October 2007, 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 'helper'
|
|
15
|
+
require 'stringio'
|
|
16
|
+
|
|
17
|
+
class TC_dimensions < Test::Unit::TestCase
|
|
18
|
+
|
|
19
|
+
def setup
|
|
20
|
+
@workbook = WriteExcel.new(StringIO.new)
|
|
21
|
+
@worksheet = @workbook.add_worksheet
|
|
22
|
+
@format = @workbook.add_format
|
|
23
|
+
@dims = ['row_min', 'row_max', 'col_min', 'col_max']
|
|
24
|
+
@smiley = [0x263a].pack('n')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_no_worksheet_cell_data
|
|
28
|
+
data = @worksheet.__send__("store_dimensions")
|
|
29
|
+
|
|
30
|
+
vals = data.unpack('x4 VVvv')
|
|
31
|
+
alist = @dims.zip(vals)
|
|
32
|
+
results = Hash[*alist.flatten]
|
|
33
|
+
|
|
34
|
+
alist = @dims.zip([0, 0, 0, 0])
|
|
35
|
+
expected = Hash[*alist.flatten]
|
|
36
|
+
|
|
37
|
+
assert_equal(expected, results)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_data_in_cell_0_0
|
|
41
|
+
@worksheet.write(0, 0, 'Test')
|
|
42
|
+
data = @worksheet.__send__("store_dimensions")
|
|
43
|
+
|
|
44
|
+
vals = data.unpack('x4 VVvv')
|
|
45
|
+
alist = @dims.zip(vals)
|
|
46
|
+
results = Hash[*alist.flatten]
|
|
47
|
+
|
|
48
|
+
alist = @dims.zip([0, 1, 0, 1])
|
|
49
|
+
expected = Hash[*alist.flatten]
|
|
50
|
+
|
|
51
|
+
assert_equal(expected, results)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_data_in_cell_0_255
|
|
55
|
+
@worksheet.write(0, 255, 'Test')
|
|
56
|
+
data = @worksheet.__send__("store_dimensions")
|
|
57
|
+
|
|
58
|
+
vals = data.unpack('x4 VVvv')
|
|
59
|
+
alist = @dims.zip(vals)
|
|
60
|
+
results = Hash[*alist.flatten]
|
|
61
|
+
|
|
62
|
+
alist = @dims.zip([0, 1, 255, 256])
|
|
63
|
+
expected = Hash[*alist.flatten]
|
|
64
|
+
|
|
65
|
+
assert_equal(expected, results)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_data_in_cell_65535_0
|
|
69
|
+
@worksheet.write(65535, 0, 'Test')
|
|
70
|
+
data = @worksheet.__send__("store_dimensions")
|
|
71
|
+
|
|
72
|
+
vals = data.unpack('x4 VVvv')
|
|
73
|
+
alist = @dims.zip(vals)
|
|
74
|
+
results = Hash[*alist.flatten]
|
|
75
|
+
|
|
76
|
+
alist = @dims.zip([65535, 65536, 0, 1])
|
|
77
|
+
expected = Hash[*alist.flatten]
|
|
78
|
+
|
|
79
|
+
assert_equal(expected, results)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_data_in_cell_65535_255
|
|
83
|
+
@worksheet.write(65535, 255, 'Test')
|
|
84
|
+
data = @worksheet.__send__("store_dimensions")
|
|
85
|
+
|
|
86
|
+
vals = data.unpack('x4 VVvv')
|
|
87
|
+
alist = @dims.zip(vals)
|
|
88
|
+
results = Hash[*alist.flatten]
|
|
89
|
+
|
|
90
|
+
alist = @dims.zip([65535, 65536, 255, 256])
|
|
91
|
+
expected = Hash[*alist.flatten]
|
|
92
|
+
|
|
93
|
+
assert_equal(expected, results)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_set_row_for_row_4
|
|
97
|
+
@worksheet.set_row(4, 20)
|
|
98
|
+
data = @worksheet.__send__("store_dimensions")
|
|
99
|
+
|
|
100
|
+
vals = data.unpack('x4 VVvv')
|
|
101
|
+
alist = @dims.zip(vals)
|
|
102
|
+
results = Hash[*alist.flatten]
|
|
103
|
+
|
|
104
|
+
alist = @dims.zip([4, 5, 0, 0])
|
|
105
|
+
expected = Hash[*alist.flatten]
|
|
106
|
+
|
|
107
|
+
assert_equal(expected, results)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_set_row_for_row_4_to_6
|
|
111
|
+
@worksheet.set_row(4, 20)
|
|
112
|
+
@worksheet.set_row(5, 20)
|
|
113
|
+
@worksheet.set_row(6, 20)
|
|
114
|
+
data = @worksheet.__send__("store_dimensions")
|
|
115
|
+
|
|
116
|
+
vals = data.unpack('x4 VVvv')
|
|
117
|
+
alist = @dims.zip(vals)
|
|
118
|
+
results = Hash[*alist.flatten]
|
|
119
|
+
|
|
120
|
+
alist = @dims.zip([4, 7, 0, 0])
|
|
121
|
+
expected = Hash[*alist.flatten]
|
|
122
|
+
|
|
123
|
+
assert_equal(expected, results)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def test_set_column_for_row_4
|
|
127
|
+
@worksheet.set_column(4, 4, 20)
|
|
128
|
+
data = @worksheet.__send__("store_dimensions")
|
|
129
|
+
|
|
130
|
+
vals = data.unpack('x4 VVvv')
|
|
131
|
+
alist = @dims.zip(vals)
|
|
132
|
+
results = Hash[*alist.flatten]
|
|
133
|
+
|
|
134
|
+
alist = @dims.zip([0, 0, 0, 0])
|
|
135
|
+
expected = Hash[*alist.flatten]
|
|
136
|
+
|
|
137
|
+
assert_equal(expected, results)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def test_data_in_cell_0_0_and_set_row_for_row_4
|
|
141
|
+
@worksheet.write(0, 0, 'Test')
|
|
142
|
+
@worksheet.set_row(4, 20)
|
|
143
|
+
data = @worksheet.__send__("store_dimensions")
|
|
144
|
+
|
|
145
|
+
vals = data.unpack('x4 VVvv')
|
|
146
|
+
alist = @dims.zip(vals)
|
|
147
|
+
results = Hash[*alist.flatten]
|
|
148
|
+
|
|
149
|
+
alist = @dims.zip([0, 5, 0, 1])
|
|
150
|
+
expected = Hash[*alist.flatten]
|
|
151
|
+
|
|
152
|
+
assert_equal(expected, results)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def test_data_in_cell_0_0_and_set_row_for_row_4_reverse_order
|
|
156
|
+
@worksheet.set_row(4, 20)
|
|
157
|
+
@worksheet.write(0, 0, 'Test')
|
|
158
|
+
data = @worksheet.__send__("store_dimensions")
|
|
159
|
+
|
|
160
|
+
vals = data.unpack('x4 VVvv')
|
|
161
|
+
alist = @dims.zip(vals)
|
|
162
|
+
results = Hash[*alist.flatten]
|
|
163
|
+
|
|
164
|
+
alist = @dims.zip([0, 5, 0, 1])
|
|
165
|
+
expected = Hash[*alist.flatten]
|
|
166
|
+
|
|
167
|
+
assert_equal(expected, results)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def test_data_in_cell_5_3_and_set_row_for_row_4
|
|
171
|
+
@worksheet.write(5, 3, 'Test')
|
|
172
|
+
@worksheet.set_row(4, 20)
|
|
173
|
+
data = @worksheet.__send__("store_dimensions")
|
|
174
|
+
|
|
175
|
+
vals = data.unpack('x4 VVvv')
|
|
176
|
+
alist = @dims.zip(vals)
|
|
177
|
+
results = Hash[*alist.flatten]
|
|
178
|
+
|
|
179
|
+
alist = @dims.zip([4, 6, 3, 4])
|
|
180
|
+
expected = Hash[*alist.flatten]
|
|
181
|
+
|
|
182
|
+
assert_equal(expected, results)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def test_comment_in_cell_5_3
|
|
186
|
+
@worksheet.write_comment(5, 3, 'Test')
|
|
187
|
+
data = @worksheet.__send__("store_dimensions")
|
|
188
|
+
|
|
189
|
+
vals = data.unpack('x4 VVvv')
|
|
190
|
+
alist = @dims.zip(vals)
|
|
191
|
+
results = Hash[*alist.flatten]
|
|
192
|
+
|
|
193
|
+
alist = @dims.zip([5, 6, 3, 4])
|
|
194
|
+
expected = Hash[*alist.flatten]
|
|
195
|
+
|
|
196
|
+
assert_equal(expected, results)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def test_nil_value_for_row
|
|
200
|
+
error = @worksheet.write_string(nil, 1, 'Test')
|
|
201
|
+
data = @worksheet.__send__("store_dimensions")
|
|
202
|
+
|
|
203
|
+
vals = data.unpack('x4 VVvv')
|
|
204
|
+
alist = @dims.zip(vals)
|
|
205
|
+
results = Hash[*alist.flatten]
|
|
206
|
+
|
|
207
|
+
alist = @dims.zip([0, 0, 0, 0])
|
|
208
|
+
expected = Hash[*alist.flatten]
|
|
209
|
+
|
|
210
|
+
assert_equal(expected, results)
|
|
211
|
+
assert_equal(-2, error)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def test_data_in_cell_5_3_and_10_1
|
|
215
|
+
@worksheet.write( 5, 3, 'Test')
|
|
216
|
+
@worksheet.write(10, 1, 'Test')
|
|
217
|
+
data = @worksheet.__send__("store_dimensions")
|
|
218
|
+
|
|
219
|
+
vals = data.unpack('x4 VVvv')
|
|
220
|
+
alist = @dims.zip(vals)
|
|
221
|
+
results = Hash[*alist.flatten]
|
|
222
|
+
|
|
223
|
+
alist = @dims.zip([5, 11, 1, 4])
|
|
224
|
+
expected = Hash[*alist.flatten]
|
|
225
|
+
|
|
226
|
+
assert_equal(expected, results)
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def test_data_in_cell_5_3_and_10_5
|
|
230
|
+
@worksheet.write( 5, 3, 'Test')
|
|
231
|
+
@worksheet.write(10, 5, 'Test')
|
|
232
|
+
data = @worksheet.__send__("store_dimensions")
|
|
233
|
+
|
|
234
|
+
vals = data.unpack('x4 VVvv')
|
|
235
|
+
alist = @dims.zip(vals)
|
|
236
|
+
results = Hash[*alist.flatten]
|
|
237
|
+
|
|
238
|
+
alist = @dims.zip([5, 11, 3, 6])
|
|
239
|
+
expected = Hash[*alist.flatten]
|
|
240
|
+
|
|
241
|
+
assert_equal(expected, results)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def test_write_string
|
|
245
|
+
@worksheet.write_string(5, 3, 'Test')
|
|
246
|
+
data = @worksheet.__send__("store_dimensions")
|
|
247
|
+
|
|
248
|
+
vals = data.unpack('x4 VVvv')
|
|
249
|
+
alist = @dims.zip(vals)
|
|
250
|
+
results = Hash[*alist.flatten]
|
|
251
|
+
|
|
252
|
+
alist = @dims.zip([5, 6, 3, 4])
|
|
253
|
+
expected = Hash[*alist.flatten]
|
|
254
|
+
|
|
255
|
+
assert_equal(expected, results)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def test_write_number
|
|
259
|
+
@worksheet.write_number(5, 3, 5)
|
|
260
|
+
data = @worksheet.__send__("store_dimensions")
|
|
261
|
+
|
|
262
|
+
vals = data.unpack('x4 VVvv')
|
|
263
|
+
alist = @dims.zip(vals)
|
|
264
|
+
results = Hash[*alist.flatten]
|
|
265
|
+
|
|
266
|
+
alist = @dims.zip([5, 6, 3, 4])
|
|
267
|
+
expected = Hash[*alist.flatten]
|
|
268
|
+
|
|
269
|
+
assert_equal(expected, results)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def test_write_url
|
|
273
|
+
@worksheet.write_url(5, 3, 'http://www.ruby.com')
|
|
274
|
+
data = @worksheet.__send__("store_dimensions")
|
|
275
|
+
|
|
276
|
+
vals = data.unpack('x4 VVvv')
|
|
277
|
+
alist = @dims.zip(vals)
|
|
278
|
+
results = Hash[*alist.flatten]
|
|
279
|
+
|
|
280
|
+
alist = @dims.zip([5, 6, 3, 4])
|
|
281
|
+
expected = Hash[*alist.flatten]
|
|
282
|
+
|
|
283
|
+
assert_equal(expected, results)
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def test_write_formula
|
|
287
|
+
@worksheet.write_formula(5, 3, ' 1 + 2')
|
|
288
|
+
data = @worksheet.__send__("store_dimensions")
|
|
289
|
+
|
|
290
|
+
vals = data.unpack('x4 VVvv')
|
|
291
|
+
alist = @dims.zip(vals)
|
|
292
|
+
results = Hash[*alist.flatten]
|
|
293
|
+
|
|
294
|
+
alist = @dims.zip([5, 6, 3, 4])
|
|
295
|
+
expected = Hash[*alist.flatten]
|
|
296
|
+
|
|
297
|
+
assert_equal(expected, results)
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def test_write_blank
|
|
301
|
+
@worksheet.write_string(5, 3, @format)
|
|
302
|
+
data = @worksheet.__send__("store_dimensions")
|
|
303
|
+
|
|
304
|
+
vals = data.unpack('x4 VVvv')
|
|
305
|
+
alist = @dims.zip(vals)
|
|
306
|
+
results = Hash[*alist.flatten]
|
|
307
|
+
|
|
308
|
+
alist = @dims.zip([5, 6, 3, 4])
|
|
309
|
+
expected = Hash[*alist.flatten]
|
|
310
|
+
|
|
311
|
+
assert_equal(expected, results)
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
def test_write_blank_no_format
|
|
315
|
+
@worksheet.write_string(5, 3)
|
|
316
|
+
data = @worksheet.__send__("store_dimensions")
|
|
317
|
+
|
|
318
|
+
vals = data.unpack('x4 VVvv')
|
|
319
|
+
alist = @dims.zip(vals)
|
|
320
|
+
results = Hash[*alist.flatten]
|
|
321
|
+
|
|
322
|
+
alist = @dims.zip([0, 0, 0, 0])
|
|
323
|
+
expected = Hash[*alist.flatten]
|
|
324
|
+
|
|
325
|
+
assert_equal(expected, results)
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def test_write_utf16be_string
|
|
329
|
+
@worksheet.write_utf16be_string(5, 3, @smiley)
|
|
330
|
+
data = @worksheet.__send__("store_dimensions")
|
|
331
|
+
|
|
332
|
+
vals = data.unpack('x4 VVvv')
|
|
333
|
+
alist = @dims.zip(vals)
|
|
334
|
+
results = Hash[*alist.flatten]
|
|
335
|
+
|
|
336
|
+
alist = @dims.zip([5, 6, 3, 4])
|
|
337
|
+
expected = Hash[*alist.flatten]
|
|
338
|
+
|
|
339
|
+
assert_equal(expected, results)
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
def test_write_utf16le_string
|
|
343
|
+
@worksheet.write_utf16le_string(5, 3, @smiley)
|
|
344
|
+
data = @worksheet.__send__("store_dimensions")
|
|
345
|
+
|
|
346
|
+
vals = data.unpack('x4 VVvv')
|
|
347
|
+
alist = @dims.zip(vals)
|
|
348
|
+
results = Hash[*alist.flatten]
|
|
349
|
+
|
|
350
|
+
alist = @dims.zip([5, 6, 3, 4])
|
|
351
|
+
expected = Hash[*alist.flatten]
|
|
352
|
+
|
|
353
|
+
assert_equal(expected, results)
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
def test_repeat_formula
|
|
357
|
+
formula = @worksheet.__send__("store_formula", '=A1 * 3 + 50')
|
|
358
|
+
@worksheet.repeat_formula(5, 3, formula, @format, 'A1', 'A2')
|
|
359
|
+
|
|
360
|
+
data = @worksheet.__send__("store_dimensions")
|
|
361
|
+
|
|
362
|
+
vals = data.unpack('x4 VVvv')
|
|
363
|
+
alist = @dims.zip(vals)
|
|
364
|
+
results = Hash[*alist.flatten]
|
|
365
|
+
|
|
366
|
+
alist = @dims.zip([5, 6, 3, 4])
|
|
367
|
+
expected = Hash[*alist.flatten]
|
|
368
|
+
|
|
369
|
+
assert_equal(expected, results)
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
def test_merge_range
|
|
373
|
+
formula = @worksheet.__send__("store_formula", '=A1 * 3 + 50')
|
|
374
|
+
@worksheet.merge_range('C6:E8', 'Test', @format)
|
|
375
|
+
|
|
376
|
+
data = @worksheet.__send__("store_dimensions")
|
|
377
|
+
|
|
378
|
+
vals = data.unpack('x4 VVvv')
|
|
379
|
+
alist = @dims.zip(vals)
|
|
380
|
+
results = Hash[*alist.flatten]
|
|
381
|
+
|
|
382
|
+
alist = @dims.zip([5, 8, 2, 5])
|
|
383
|
+
expected = Hash[*alist.flatten]
|
|
384
|
+
|
|
385
|
+
assert_equal(expected, results)
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
end
|