| 1 | package Spreadsheet::ParseODS::Worksheet; | ||
| 2 | use Moo 2; | ||
| 3 | use Carp qw(croak); | ||
| 4 | use Filter::signatures; | ||
| 5 | use feature 'signatures'; | ||
| 6 | no warnings 'experimental::signatures'; | ||
| 7 | use PerlX::Maybe; | ||
| 8 | |||
| 9 | our $VERSION = '0.39'; | ||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | Spreadsheet::ParseODS::Worksheet - a sheet in a workbook | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | has 'label' => ( | ||
| 18 | is => 'rw' | ||
| 19 | ); | ||
| 20 | |||
| 21 | has 'data' => ( | ||
| 22 | is => 'rw' | ||
| 23 | ); | ||
| 24 | |||
| 25 | has 'sheet_hidden' => ( | ||
| 26 | is => 'rw', | ||
| 27 | ); | ||
| 28 | |||
| 29 | has 'row_min' => ( | ||
| 30 | is => 'rw', | ||
| 31 | ); | ||
| 32 | |||
| 33 | has 'row_max' => ( | ||
| 34 | is => 'rw', | ||
| 35 | ); | ||
| 36 | |||
| 37 | has 'col_min' => ( | ||
| 38 | is => 'rw', | ||
| 39 | ); | ||
| 40 | |||
| 41 | has 'col_max' => ( | ||
| 42 | is => 'rw', | ||
| 43 | ); | ||
| 44 | |||
| 45 | has 'print_areas' => ( | ||
| 46 | is => 'rw', | ||
| 47 | ); | ||
| 48 | |||
| 49 | has 'header_rows' => ( | ||
| 50 | is => 'rw', | ||
| 51 | ); | ||
| 52 | |||
| 53 | has 'header_cols' => ( | ||
| 54 | is => 'rw', | ||
| 55 | ); | ||
| 56 | |||
| 57 | has 'hidden_rows' => ( | ||
| 58 | is => 'rw', | ||
| 59 | ); | ||
| 60 | |||
| 61 | has 'hidden_cols' => ( | ||
| 62 | is => 'rw', | ||
| 63 | ); | ||
| 64 | |||
| 65 | has 'tab_color' => ( | ||
| 66 | is => 'rw', | ||
| 67 | ); | ||
| 68 | |||
| 69 | has 'merged_areas' => ( | ||
| 70 | is => 'lazy', | ||
| 71 | default => sub { [] }, | ||
| 72 | ); | ||
| 73 | |||
| 74 | sub get_cell( $self, $row, $col ) { | ||
| 75 | return undef if $row > $self->row_max; | ||
| 76 | return undef if $col > $self->col_max; | ||
| 77 | $self->data->[ $row ]->[ $col ] | ||
| 78 | } | ||
| 79 | |||
| 80 | sub get_name( $self ) { | ||
| 81 | $self->name | ||
| 82 | } | ||
| 83 | |||
| 84 | sub get_tab_color( $self ) { | ||
| 85 | $self->tab_color | ||
| 86 | } | ||
| 87 | |||
| 88 | sub is_sheet_hidden( $self ) { | ||
| 89 | $self->sheet_hidden | ||
| 90 | } | ||
| 91 | |||
| 92 | sub row_range( $self ) { | ||
| 93 | return ($self->row_min, $self->row_max) | ||
| 94 | } | ||
| 95 | |||
| 96 | sub col_range( $self ) { | ||
| 97 | return ($self->col_min, $self->col_max) | ||
| 98 | } | ||
| 99 | |||
| 100 | =head2 C<< get_print_areas() >> | ||
| 101 | |||
| 102 | my $print_areas = $worksheet->get_print_areas(); | ||
| 103 | # [ [$start_row, $start_col, $end_row, $end_col], ... ] | ||
| 104 | |||
| 105 | The C<< ->get_print_areas() >> method returns the print areas | ||
| 106 | of the sheet as an arrayref. | ||
| 107 | |||
| 108 | Returns undef if there are no print areas. | ||
| 109 | |||
| 110 | =cut | ||
| 111 | |||
| 112 | sub get_print_areas($self) { | ||
| 113 | my $ar = $self->print_areas; | ||
| 114 | } | ||
| 115 | |||
| 116 | sub get_print_titles( $self ) { | ||
| 117 | my $hr = $self->header_rows; | ||
| 118 | my $hc = $self->header_cols; | ||
| 119 | my $res = { | ||
| 120 | maybe Row => $hr, | ||
| 121 | maybe Column => $hc, | ||
| 122 | }; | ||
| 123 | return unless scalar keys %$res; | ||
| 124 | return $res | ||
| 125 | } | ||
| 126 | |||
| 127 | sub get_merged_areas( $self ) { | ||
| 128 | return $self->merged_areas | ||
| 129 | } | ||
| 130 | |||
| 131 | sub is_row_hidden( $self, $rownum=undef ) { | ||
| 132 | wantarray ? @{ $self->hidden_rows } | ||
| 133 | : $self->hidden_rows->[ $rownum ] | ||
| 134 | } | ||
| 135 | |||
| 136 | sub is_col_hidden( $self, $colnum=undef ) { | ||
| 137 | wantarray ? @{ $self->hidden_cols } | ||
| 138 | : $self->hidden_cols->[ $colnum ] | ||
| 139 | } | ||
| 140 | |||
| 141 | 1; |