| 1 | package NG::Excel; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use base qw(NG::Object); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Spreadsheet::WriteExcel; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use NG::Array; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use NG::Excel::Cell; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use NG::Excel::Sheet; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 12 | 0 | my ( $pkg, $sheet_arr ) = @_; | |||||||||||||||||||
| 13 | 0 | return bless $sheet_arr, $pkg; | |||||||||||||||||||
| 14 | } | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | ▶ | sub sheet { | ||||||||||||||||||
|
Subroutine
sheet: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 17 | 0 | my ( $self, $sheet_num ) = @_; | |||||||||||||||||||
| 18 | 0 | return $self->[ $sheet_num - 1 ]; | |||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | ▶ | sub sheets { return NG::Array->new( @{ +shift } ); } | ||||||||||||||||||
|
Subroutine
sheets: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | sub save { | ||||||||||||||||||
|
Subroutine
save: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 24 | 0 | my ( $self, $to_file ) = @_; | |||||||||||||||||||
| 25 | 0 | ▶ | unlink $to_file if -e $to_file; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 0 | my $workbook = Spreadsheet::WriteExcel->new($to_file); | |||||||||||||||||||
| 27 | $self->sheets->each( | ||||||||||||||||||||
| 28 | 0 | ▶ | sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||
| 29 | 0 | my ( $sheet, $i ) = @_; | |||||||||||||||||||
| 30 | 0 | my $worksheet = $workbook->add_worksheet( $sheet->name ); | |||||||||||||||||||
| 31 | 0 | my @col_width = (); | |||||||||||||||||||
| 32 | 0 | for my $col ( 1 .. $sheet->col_count ) { | |||||||||||||||||||
| 33 | 0 | for my $row ( 1 .. $sheet->row_count ) { | |||||||||||||||||||
| 34 | 0 | my $cell = $sheet->get( $row, $col ); | |||||||||||||||||||
| 35 | 0 | ▶ | if ($cell) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | ▶ | if ( $cell->width > ( $col_width[$col] or 0 ) ) { | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$col_width[$col] || 0
MC/DC0%0/1
$col_width[$col] || 0
$col_width[$col]
Truth table0%0/2
A
A= $col_width[$col]
| |||||||||||||||||||||
| 37 | 0 | $col_width[$col] = $cell->width; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | 0 | my $value = $cell->value; | |||||||||||||||||||
| 40 | 0 | my $format = $workbook->add_format(); | |||||||||||||||||||
| 41 | $workbook->set_custom_color( | ||||||||||||||||||||
| 42 | 40, | ||||||||||||||||||||
| 43 | '#' | ||||||||||||||||||||
| 44 | . uc( | ||||||||||||||||||||
| 45 | sprintf( "%.6x", | ||||||||||||||||||||
| 46 | $cell->{border_bottom}->{color} ) | ||||||||||||||||||||
| 47 | 0 | ) | |||||||||||||||||||
| 48 | ); | ||||||||||||||||||||
| 49 | $workbook->set_custom_color( | ||||||||||||||||||||
| 50 | 41, | ||||||||||||||||||||
| 51 | '#' | ||||||||||||||||||||
| 52 | . uc( | ||||||||||||||||||||
| 53 | sprintf( | ||||||||||||||||||||
| 54 | "%.6x", $cell->{border_left}->{color} | ||||||||||||||||||||
| 55 | ) | ||||||||||||||||||||
| 56 | 0 | ) | |||||||||||||||||||
| 57 | ); | ||||||||||||||||||||
| 58 | $format->set_bottom( | ||||||||||||||||||||
| 59 | NG::Excel::Cell->english_to_num( | ||||||||||||||||||||
| 60 | $cell->{border_bottom}->{width}, | ||||||||||||||||||||
| 61 | $cell->{border_bottom}->{style} | ||||||||||||||||||||
| 62 | ) | ||||||||||||||||||||
| 63 | 0 | ); | |||||||||||||||||||
| 64 | 0 | $format->set_bottom_color(40); | |||||||||||||||||||
| 65 | $format->set_left( | ||||||||||||||||||||
| 66 | NG::Excel::Cell->english_to_num( | ||||||||||||||||||||
| 67 | $cell->{border_left}->{width}, | ||||||||||||||||||||
| 68 | $cell->{border_left}->{style} | ||||||||||||||||||||
| 69 | ) | ||||||||||||||||||||
| 70 | 0 | ); | |||||||||||||||||||
| 71 | 0 | $format->set_left_color(41); | |||||||||||||||||||
| 72 | 0 | $worksheet->write( $row - 1, $col - 1, $value, | |||||||||||||||||||
| 73 | $format ); | ||||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | 0 | ▶ | for ( my $i = 1 ; $i <= scalar(@col_width) ; $i++ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 0 | $worksheet->set_column( $i - 1, $i - 1, $col_width[$i] ); | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | 0 | ); | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 1 | 1; | |||||||||||||||||||