sub text_to_excel {
# %args should look something like...
# ( delimiter => "\t",
# recordsep => "\n",
# file => "/path/to/file.txt"
# name => "Sheet Title" )
# the only required args are delimiter and file
my @var = 0;
my %args = @_;
my ( $delimiter, $recordsep, $file, $name, $outfile ) = @args{qw( delimiter recordsep file name outfile )};
$delimiter and $file
or die "Must provide at least delimiter and file as args to" . "delimited_text_to_excel().";
-e $file
or die "There is no file: $file\n";
open( F, "< $file" ) or die("Can't open $file: $!");
$/ = $recordsep || "\n";
my @data = <F>;
close F;
$/ = "\n";
my $workbook = Spreadsheet::WriteExcel->new($outfile);
#my $worksheet = $workbook->addworksheet($name||'Page 1');
# Add some worksheets
my $procesadas = $workbook->add_worksheet("Transacciones Procesadas");
my $pendientes = $workbook->add_worksheet("Transacciones Pendientes");
my $header = $workbook->add_format(); # Add a format
$header->set_bold();
$header->set_size(15);
$header->set_align('center');
$header->set_align('vcenter');
$header->set_font('garamond');
my $borde = $workbook->addformat(); # Add a format
$borde->set_border();
my $format1 = $workbook->addformat(); # Add a format
$format1->set_size(11);
$format1->set_bold();
$format1->set_align('left');
$format1->set_align('vleft');
$format1->set_font('garamond');
my $format2 = $workbook->addformat(); # Add a format
$format2->set_size(10);
$format2->set_align('center');
$format2->set_align('vcenter');
$format2->set_num_format('#,##0');
$format2->set_font('garamond');
$worksheet->set_column( 'A:A', 60 );
$worksheet->set_column( 'B:B', 15 );
$worksheet->set_column( 'C:C', 15 );
$worksheet->set_column( 'D:D', 15 );
$worksheet->set_column( 'E:E', 15 );
for ( my $row = 0; $row < @data; $row++ ) {
chomp( my @line = split /$delimiter/, $data[$row] );
for ( my $col = 0; $col < @line; $col++ ) {
if () { # FALTARÍA COMPARAR EL (*) QUE ESTÁ DENTRO DEL ARCHIVO TXT COMO CORTE (CAMBIO DE HOJA)
@var = 1;
}
if ( @var == 1 ) {
if ( $row == 0 ) {
$pendientes->merge_range( 'A1:E1', $line[$col], $header );
}
if ( $row == 2 ) {
$pendientes->write( $row, $col, $line[$col], $format1 );
}
if ( $row > 2 ) {
$pendientes->write( $row, $col, $line[$col], $format2 );
}
}
else {
if ( $row == 0 ) {
$procesadas->merge_range( 'A1:E1', $line[$col], $header );
}
if ( $row == 2 ) {
$procesadas->write( $row, $col, $line[$col], $format1 );
}
if ( $row > 2 ) {
$procesadas->write( $row, $col, $line[$col], $format2 );
}
}
}
}
$workbook->close();
}