Is there any way to automate values from multiple text files to multipe worksheets in the same excel file? (Ex: Textfile1 values to Sheet1, Textfile2 values to Sheet2 and so on) Because for now I have to change the name of the text file and the excel worksheet everytime I extract values from different text files so that I need an automation to ease the work. Below is the recent Perl script I am using.
use strict;
use warnings;
use Excel::Writer::XLSX;
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
{
my $output_fn = 'result.xlsx';
my $input_fn = 'accuracy_final_copy.txt.gz';
my $workbook = Excel::Writer::XLSX->new( $output_fn );
my $worksheet = $workbook->add_worksheet();
my $zip = IO::Uncompress::Gunzip->new( $input_fn )
or die "gunzip failed: $GunzipError\n";
$worksheet->write( 0, 0, "Accuracy value" );
my $col = 0;
my $row = 1;
while (!$zip->eof()) {
my $line = $zip->getline();
chomp($line);
next if $line !~ /\S/; # skip empty lines
my $value = $line;
$worksheet->write( $row, $col, $value );
$row++;
}
$workbook->close();
}