1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
use strict;
use warnings;
use utf8;
use Test::More;
use Test::Exception;
use Catmandu::Importer::XLS;
use Catmandu::Importer::XLSX;
# XLS
my $importer
= Catmandu::Importer::XLS->new(file => './t/test.xls', empty => 'ignore');
isa_ok($importer, 'Catmandu::Importer::XLS');
can_ok($importer, 'each');
my $rows = $importer->to_array();
is_deeply($rows->[0], {Column1 => 1, Column2 => 'a', Column3 => 0.01},
'XLS default');
is_deeply($rows->[1], {Column1 => 2, Column2 => 'b', Column3 => 2.5},
'XLS default');
is_deeply($rows->[5], {Column1 => 6, Column2 => 'f', Column3 => '01/01/90'},
'XLS format');
is_deeply($rows->[-1], {Column1 => 27, Column3 => 'Ümlaut'}, 'XLS UTF-8');
$importer = Catmandu::Importer::XLS->new(
file => './t/test.xls',
fields => 'a,b,c',
empty => 'ignore'
);
$rows = $importer->to_array();
is_deeply($rows->[0], {a => 1, b => 'a', c => 0.01}, 'XLS option fields');
is_deeply($rows->[-1], {a => 27, c => 'Ümlaut'}, 'XLS option fields');
$importer = Catmandu::Importer::XLS->new(
file => './t/test.xls',
columns => 1,
empty => 'ignore'
);
$rows = $importer->to_array();
is_deeply($rows->[0], {A => 1, B => 'a', C => 0.01}, 'XLS option columns');
is_deeply($rows->[-1], {A => 27, C => 'Ümlaut'}, 'XLS option columns');
$importer = Catmandu::Importer::XLS->new(
file => './t/test.xls',
header => 0,
empty => 'ignore'
);
$rows = $importer->to_array();
is_deeply(
$rows->[0],
{A => 'Column1', B => 'Column2', C => 'Column3'},
'XLS option header'
);
is_deeply($rows->[-1], {A => 27, C => 'Ümlaut'}, 'XLS option header');
$importer = Catmandu::Importer::XLS->new(
file => './t/test.xls',
header => 0,
worksheet => 1
);
$rows = $importer->to_array();
is_deeply($rows->[0], {A => 'a', B => '1'}, 'XLS option worksheet');
# XLSX
$importer = Catmandu::Importer::XLSX->new(file => './t/test.xlsx',
empty => 'ignore');
isa_ok($importer, 'Catmandu::Importer::XLSX');
can_ok($importer, 'each');
$rows = $importer->to_array();
is_deeply($rows->[0], {Column1 => 1, Column2 => 'a', Column3 => 0.01},
'XLSX default');
is_deeply($rows->[1], {Column1 => 2, Column2 => 'b', Column3 => 2.5},
'XLSX default');
is_deeply($rows->[5], {Column1 => 6, Column2 => 'f', Column3 => '01/01/90'},
'XLSX format');
is_deeply($rows->[-1], {Column1 => 27, Column3 => 'Ümlaut'}, 'XLSX UTF-8');
$importer = Catmandu::Importer::XLSX->new(
file => './t/test.xlsx',
fields => 'a,b,c',
empty => 'ignore'
);
$rows = $importer->to_array();
is_deeply($rows->[0], {a => 1, b => 'a', c => 0.01}, 'XLSX option fields');
is_deeply($rows->[-1], {a => 27, c => 'Ümlaut'}, 'XLSX option fields');
$importer = Catmandu::Importer::XLSX->new(
file => './t/test.xlsx',
columns => 1,
empty => 'ignore'
);
$rows = $importer->to_array();
is_deeply($rows->[0], {A => 1, B => 'a', C => 0.01}, 'XLSX option columns');
is_deeply($rows->[-1], {A => 27, C => 'Ümlaut'}, 'XLSX option columns');
$importer = Catmandu::Importer::XLSX->new(
file => './t/test.xlsx',
header => 0,
empty => 'ignore'
);
$rows = $importer->to_array();
is_deeply(
$rows->[0],
{A => 'Column1', B => 'Column2', C => 'Column3'},
'XLSX option header'
);
is_deeply($rows->[-1], {A => 27, C => 'Ümlaut'}, 'XLSX option header');
$importer = Catmandu::Importer::XLSX->new(
file => './t/test.xlsx',
header => 0,
worksheet => 1
);
$rows = $importer->to_array();
is_deeply($rows->[0], {A => 'a', B => '1'}, 'XLSX option worksheet');
$importer = Catmandu::Importer::XLS->new(file => './t/test2.xls',
empty => 'string');
$rows = $importer->to_array();
is_deeply($rows->[0], {A => 'X', B => '', C => 'X'}, 'empty = string');
$importer
= Catmandu::Importer::XLS->new(file => './t/test2.xls', empty => 'nil');
$rows = $importer->to_array();
is_deeply($rows->[0], {A => 'X', B => undef, C => 'X'}, 'empty = nil');
$importer = Catmandu::Importer::XLSX->new(
file => './t/test2.xlsx',
empty => 'string'
);
$rows = $importer->to_array();
is_deeply($rows->[0], {A => 'X', B => '', C => 'X'}, 'empty = string');
$importer
= Catmandu::Importer::XLSX->new(file => './t/test2.xlsx', empty => 'nil');
$rows = $importer->to_array();
is_deeply($rows->[0], {A => 'X', B => undef, C => 'X'}, 'empty = nil');
done_testing;
|