#!/usr/bin/perl use Spreadsheet::Read qw(ReadData); my $inputFile = 'foo.xlsx'; use Text::CSV; my $outputFile = 'bar.csv'; my $csv = Text::CSV->new ( { binary => 1, eol => "\n" } ) or die "Cannot use CSV: ".Text::CSV->error_diag (); my @writeRows; my $book = ReadData ($inputFile); my @readRows = Spreadsheet::Read::rows($book->[1]); foreach my $i (1 .. scalar @readRows) { my @thisRow; my ($id, $last, $first, $pref) = @{$readRows[$i-1]}; if ($pref) { push @thisRow, $pref; } else { push @thisRow, $first; } push @thisRow, $last, "Static", "Text"; push @writeRows, [@thisRow]; } open $fh, ">:encoding(utf-8)", $outputFile or die "$outputFile: $!"; $csv->print ($fh, $_) for @writeRows; close $fh or die "$outputFile: $!"; exit;