#!perl -w use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 2; # Always warn with verbose error messages # Open a new excel app, thus not stepping on anyones toes. my $Excel = Win32::OLE->new('Excel.Application', 'Quit') or die "Unable to start Excel"; # Set Application Visibility # 0 = Not Visible 1 = Visible $Excel->{Visible} = 0; my $file = 'c:\test.txt'; # I tested with a TSV file. die "'$file' not found" unless -e $file; my $new_file = $file; $new_file =~ s/txt$/xls/i; if( -e $new_file ) { my $n = 4; while( --$n ) { print STDERR "Deleting '$new_file' in $n seconds \r"; sleep 1; } warn "Deleting '$new_file' \n"; unlink $new_file; } my $Book = $Excel->Workbooks->Open($file); # Open the book. # And save it in the prefered format. $Book->SaveAs( { FileName => $new_file, FileFormat => xlNormal, # To save as TSV use xlText CreateBackup => 0} ); $Book->Close(0); $Excel->Quit();