use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; my $filename = 'Z:\Data\Perl\998526\998682.csv'; my $xl = Win32::OLE->new('Excel.Application'); $xl->{Visible} = 1; my $wb = $xl->Workbooks->Open($filename); my $sht = $wb->Sheets(1); $sht->Range('A1:A3')->EntireRow->Insert; $sht->Range('G1')->{Value} = $sht->Range('G4')->{Value}; $sht->Range('G2')->{Value} = 'Outbound'; my $lastcell = $xl->ActiveCell->SpecialCells(xlCellTypeLastCell)->Address; $sht->Range('A4:' . $lastcell)->AdvancedFilter ({Action => xlFilterInPlace, CriteriaRange => $sht->Range('G1:G2'), Unique => 0}); $xl->{DisplayAlerts} = 0; $sht->Range('A5:' . $lastcell)->Delete; $xl->{DisplayAlerts} = 1; $sht->ShowAllData; $sht->Range('A1:A3')->EntireRow->Delete;