| 1 | package Spreadsheet::ParseODS::Workbook; | ||
| 2 | use Moo 2; | ||
| 3 | use Filter::signatures; | ||
| 4 | use feature 'signatures'; | ||
| 5 | no warnings 'experimental::signatures'; | ||
| 6 | |||
| 7 | our $VERSION = '0.39'; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Spreadsheet::ParseODS::Workbook - a workbook | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | =head2 C<< ->filename >> | ||
| 16 | |||
| 17 | print $workbook->filename; | ||
| 18 | |||
| 19 | The name of the file if applicable. | ||
| 20 | |||
| 21 | =cut | ||
| 22 | |||
| 23 | has 'filename' => ( | ||
| 24 | is => 'rw', | ||
| 25 | ); | ||
| 26 | |||
| 27 | has '_settings' => ( | ||
| 28 | is => 'rw', | ||
| 29 | handles => [ 'active_sheet_name' ], | ||
| 30 | ); | ||
| 31 | |||
| 32 | # The worksheets themselves | ||
| 33 | has '_sheets' => ( | ||
| 34 | is => 'lazy', | ||
| 35 | default => sub { [] }, | ||
| 36 | ); | ||
| 37 | |||
| 38 | # Mapping of names to sheet objects | ||
| 39 | has '_worksheets' => ( | ||
| 40 | is => 'lazy', | ||
| 41 | default => sub { {} }, | ||
| 42 | ); | ||
| 43 | |||
| 44 | has '_styles' => ( | ||
| 45 | is => 'lazy', | ||
| 46 | default => sub { {} }, | ||
| 47 | ); | ||
| 48 | |||
| 49 | =head2 C<< ->table_styles >> | ||
| 50 | |||
| 51 | The styles that identify whether a table is hidden, and other styles | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | has 'table_styles' => ( | ||
| 56 | is => 'lazy', | ||
| 57 | default => sub { {} }, | ||
| 58 | ); | ||
| 59 | |||
| 60 | =head2 C<< ->get_print_areas() >> | ||
| 61 | |||
| 62 | my $print_areas = $workbook->get_print_areas(); | ||
| 63 | # [[ [$start_row, $start_col, $end_row, $end_col], ... ]] | ||
| 64 | |||
| 65 | The C<< ->get_print_areas() >> method returns the print areas | ||
| 66 | of each sheet as an arrayref of arrayrefs. If a sheet has no | ||
| 67 | print area, C<undef> is returned for its print area. | ||
| 68 | |||
| 69 | =cut | ||
| 70 | |||
| 71 | sub get_print_areas( $self ) { | ||
| 72 | [ map { $_->get_print_areas } $self->worksheets ] | ||
| 73 | } | ||
| 74 | |||
| 75 | =head2 C<< ->get_active_sheet() >> | ||
| 76 | |||
| 77 | my $sheet = $workbook->get_active_sheet(); | ||
| 78 | if( !$sheet ) { | ||
| 79 | # If there is no defined active worksheet, take the first: | ||
| 80 | ($sheet) = $workbook->worksheets(); | ||
| 81 | }; | ||
| 82 | |||
| 83 | Returns the active worksheet, or if there is no such sheet, returns C<undef>. | ||
| 84 | |||
| 85 | =cut | ||
| 86 | |||
| 87 | sub get_active_sheet($self) { | ||
| 88 | if( defined( my $name = $self->active_sheet_name )) { | ||
| 89 | return $self->worksheet( $name ); | ||
| 90 | } else { | ||
| 91 | return undef | ||
| 92 | }; | ||
| 93 | } | ||
| 94 | |||
| 95 | sub get_filename( $self ) { | ||
| 96 | $self->filename | ||
| 97 | } | ||
| 98 | |||
| 99 | =head2 C<< ->worksheets() >> | ||
| 100 | |||
| 101 | my @sheets = $workbook->worksheets; | ||
| 102 | |||
| 103 | Returns the list of worksheets as L<Spreadsheet::ParseODS::Worksheet> | ||
| 104 | objects. | ||
| 105 | |||
| 106 | =cut | ||
| 107 | |||
| 108 | sub worksheets( $self ) { | ||
| 109 | @{ $self->_sheets } | ||
| 110 | }; | ||
| 111 | |||
| 112 | =head2 C<< ->worksheet($name) >> | ||
| 113 | |||
| 114 | my $sheet1 = $workbook->worksheet('Sheet 1'); | ||
| 115 | |||
| 116 | Returns the worksheet with the given name, or if no such worksheet exists, | ||
| 117 | returns C<undef>. | ||
| 118 | |||
| 119 | =cut | ||
| 120 | |||
| 121 | sub worksheet( $self, $name ) { | ||
| 122 | $self->_worksheets->{ $name } | ||
| 123 | } | ||
| 124 | |||
| 125 | 1; |