summaryrefslogtreecommitdiffstats
path: root/lib/Spreadsheet/Template/Generator/Parser/Excel.pm
blob: 4638a8b811fc249064e1bb4d0c90b7c5effda6e1 (plain) (blame)
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
package Spreadsheet::Template::Generator::Parser::Excel;
use Moose::Role;

with 'Spreadsheet::Template::Generator::Parser';

requires 'make_excel';

sub parse {
    my $self = shift;
    my ($filename) = @_;

    my $excel = $self->make_excel($filename);
    return $self->_parse_workbook($excel);
    my $data = {
        worksheets => [],
    };
    for my $sheet ($excel->worksheets) {
        push @{ $data->{worksheets} }, $self->_parse
    }
}

sub _parse_workbook {
    my $self = shift;
    my ($excel) = @_;

    my $data = {
        worksheets => [],
    };

    for my $sheet ($excel->worksheets) {
        push @{ $data->{worksheets} }, $self->_parse_worksheet($sheet);
    }

    return $data;
}

sub _parse_worksheet {
    my $self = shift;
    my ($sheet) = @_;

    my $data = {
        cells => [],
    };

    my ($rmin, $rmax) = $sheet->row_range;
    my ($cmin, $cmax) = $sheet->col_range;

    for my $row (0..$rmin - 1) {
        push @{ $data->{cells} }, [];
    }

    for my $row ($rmin..$rmax) {
        my $row_data = [];
        for my $col (0..$cmin - 1) {
            push @$row_data, {};
        }
        for my $col ($cmin..$cmax) {
            if (my $cell = $sheet->get_cell($row, $col)) {
                push @$row_data, $self->_parse_cell($cell);
            }
            else {
                push @$row_data, {};
            }
        }
        push @{ $data->{cells} }, $row_data
    }

    return $data;
}

sub _parse_cell {
    my $self = shift;
    my ($cell) = @_;


    my $data = {
        contents => $self->_filter_cell_contents($cell->unformatted),
        type     => $cell->type,
    };

    return $data;
}

sub _filter_cell_contents {
    my $self = shift;
    my ($contents) = @_;
    return $contents;
}

no Moose::Role;

1;