Advertisement
hakonhagland

xlsx-writer-perl

Oct 9th, 2021
1,627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.64 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3. use Excel::Writer::XLSX;
  4.  
  5. {
  6.     my $output_fn = 'result.xlsx';
  7.     my $input_fn = 'input.txt';
  8.     my $workbook = Excel::Writer::XLSX->new( $output_fn );
  9.     my $worksheet = $workbook->add_worksheet();
  10.     my $data = read_file('input.txt');
  11.  
  12.     my $col = 0;
  13.     for my $i (0..$#$data) {
  14.         my $value = $data->[$i];
  15.         my $row = $i;
  16.         $worksheet->write( $row, $col, $value );
  17.     }
  18.     $workbook->close();
  19. }
  20.  
  21. sub read_file {
  22.     my ($fn) = @_;
  23.  
  24.     open ( my $fh, '<', $fn ) or die "Could not open file '$fn': $!";
  25.     my @data = <$fh>;
  26.     chomp @data;
  27.     close $fh;
  28.     return \@data;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement