File: 01-parseods.t

package info (click to toggle)
libspreadsheet-readsxc-perl 0.39-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,368 kB
  • sloc: perl: 1,377; makefile: 8; xml: 2
file content (45 lines) | stat: -rw-r--r-- 1,347 bytes parent folder | download | duplicates (3)
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
use strict;
use Test::More tests => 2;
use File::Basename 'dirname';
use Spreadsheet::ParseODS;
use Data::Dumper;

my $d = dirname($0);

my $workbook = Spreadsheet::ParseODS->new()->parse("$d/t.sxc");

my @s = $workbook->worksheets;

my @sheets = map { $_->label } $workbook->worksheets;

is_deeply \@sheets, [qw[
    Sheet1 Sheet2 Sheet3
]], "Correct spreadsheet names"
or diag Dumper \@sheets;

my @sheet1_raw = (['-$1,500.99', '17', undef],[undef, undef, undef],['one', 'more', 'cell']);
my @sheet1_curr = ([-1500.99, 17, undef],[undef, undef, undef],['one', 'more', 'cell']);

my $sheet1 = $workbook->worksheet('Sheet1');

my @raw_data;
my ($minrow,$maxrow) = $sheet1->row_range;
for my $row ($minrow..$maxrow) {
    $raw_data[ $row ] = [];
    my ($mincol,$maxcol) = $sheet1->col_range;
    for my $col ($mincol..$maxcol) {
        $raw_data[ $row ]->[ $col ] = $sheet1->get_cell($row,$col)->value;
    };
};
is_deeply \@raw_data, \@sheet1_raw, "Raw cell values"
    or diag Dumper \@raw_data;

my @sheet1_curr_date_multiline = (
    [-1500.99, 17, undef],
    [undef, undef, undef],
    ['one', 'more', 'cell'],
    [undef,undef,undef],
    ['Date','1980-11-21', undef],
    ["A cell value\nThat contains\nMultiple lines",undef,undef],
    ["\nA cell that starts\nWith an empty line\nAnd ends with an empty\nLine as well\n",undef,undef],
);