This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
S::S api exists, and I remembered to add required files.
- Loading branch information
Showing
5 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package Spreadsheet::Simple::Reader::Excel; | ||
use Moose; | ||
|
||
our $VERSION = '0.01'; | ||
our $AUTHORITY = 'cpan:DHARDISON'; | ||
|
||
use Spreadsheet::ParseExcel; | ||
|
||
use Spreadsheet::Simple::Document; | ||
use Spreadsheet::Simple::Sheet; | ||
use Spreadsheet::Simple::Row; | ||
use Spreadsheet::Simple::Cell; | ||
|
||
use namespace::clean -except => 'meta'; | ||
|
||
with 'Spreadsheet::Simple::Role::Reader'; | ||
|
||
sub read_file { | ||
my ($self, $file) = @_; | ||
my $wb = Spreadsheet::ParseExcel::Workbook->Parse($file); | ||
|
||
return $self->_map_document($wb); | ||
} | ||
|
||
sub _map_document { | ||
my ($self, $wb) = @_; | ||
|
||
return Spreadsheet::Simple::Document->new( | ||
sheets => [ | ||
map { $self->_map_sheet($_) } @{ $wb->{Worksheet} } | ||
], | ||
); | ||
} | ||
|
||
sub _map_sheet { | ||
my ($self, $ws) = @_; | ||
|
||
return Spreadsheet::Simple::Sheet->new( | ||
name => $ws->{Name}, | ||
rows => [ | ||
map { $self->_map_row($_) } @{ $ws->{Cells} } | ||
], | ||
); | ||
|
||
} | ||
|
||
sub _map_row { | ||
my ($self, $row) = @_; | ||
|
||
return Spreadsheet::Simple::Row->new( | ||
cells => [ | ||
map { $self->_map_cell($_) } @{ $row } | ||
], | ||
); | ||
} | ||
|
||
sub _map_cell { | ||
my ($self, $cell) = @_; | ||
|
||
return Spreadsheet::Simple::Cell->new( | ||
value => $cell->value | ||
); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package Spreadsheet::Simple::Role::Reader; | ||
use Moose::Role; | ||
|
||
our $VERSION = '0.01'; | ||
our $AUTHORITY = 'cpan:DHARDISON'; | ||
|
||
use namespace::clean -except => 'meta'; | ||
|
||
requires 'read_file'; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More tests => 1 + 7*2; | ||
use Test::Exception; | ||
|
||
BEGIN { use_ok "Spreadsheet::Simple" } | ||
|
||
my $ss = Spreadsheet::Simple->new( format => 'Excel' ); | ||
|
||
my @files = ( | ||
't/data/100-excel.xls', | ||
't/data/100-excel2.xls', | ||
); | ||
|
||
foreach my $file (@files) { | ||
my $doc = $ss->read_file($file); | ||
|
||
ok($doc, "doc is defined"); | ||
|
||
isa_ok($doc, 'Spreadsheet::Simple::Document'); | ||
|
||
my $sheet = $doc->get_sheet_by_name('sheet1'); | ||
|
||
ok($sheet, "sheet is defined"); | ||
isa_ok($sheet, 'Spreadsheet::Simple::Sheet'); | ||
|
||
is($sheet->get_cell(0, 0)->value, 'foo', 'A1'); | ||
is($sheet->get_cell(0, 1)->value, 'bar', 'B1'); | ||
is($sheet->get_cell(0, 2)->value, 'baz', 'C1'); | ||
} | ||
|
||
|