use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
my $xl = Win32::OLE->new('Excel.Application');
$xl->{Visible} = 1;
my $nShtsOld = $xl->{SheetsInNewWorkbook};
$xl->{SheetsInNewWorkbook} = 1;
my $wb = $xl->Workbooks->Add;
$xl->{SheetsInNewWorkbook} = $nShtsOld;
my $sht = $wb->Sheets(1);
$sht->Cells(1, 1)->{Value} = 'a';
$sht->Cells(2, 2)->{Value} = 'b';
$sht->Cells(3, 1)->{Value} = 'c'; $sht->Cells(3, 2)->{Value} = 'c';
$sht->Cells(1, 2)->Delete({Shift=>xlUp});
####
use strict;
use warnings;
use Win32::OLE;
my $xl = Win32::OLE->new('Excel.Application');
$xl->{Visible} = 1;
my $nShtsOld = $xl->{SheetsInNewWorkbook};
$xl->{SheetsInNewWorkbook} = 1;
my $wb = $xl->Workbooks->Add;
$xl->{SheetsInNewWorkbook} = $nShtsOld;
my $sht = $wb->Sheets(1);
$sht->Cells(1, 1)->{Value} = 'a';
$sht->Cells(2, 2)->{Value} = 'b';
$sht->Cells(3, 1)->{Value} = 'c'; $sht->Cells(3, 2)->{Value} = 'c';
$sht->Cells(1, 2)->EntireRow->Delete;
##
##
use strict;
use warnings;
use Win32::OLE;
my $xl = Win32::OLE->new('Excel.Application');
$xl->{Visible} = 1;
my $nShtsOld = $xl->{SheetsInNewWorkbook};
$xl->{SheetsInNewWorkbook} = 1;
my $wb = $xl->Workbooks->Add;
$xl->{SheetsInNewWorkbook} = $nShtsOld;
my $sht = $wb->Sheets(1);
$sht->Cells(1, 1)->{Value} = "A"; $sht->Cells(1, 2)->{Value} = "E";
$sht->Cells(2, 1)->{Value} = "B";
$sht->Cells(3, 1)->{Value} = "C";
$sht->Cells(4, 1)->{Value} = "D"; $sht->Cells(4, 2)->{Value} = "F";
my $end = $sht->UsedRange->Rows->{Count};
for my $count (1..$end) {
my $cell = $sht->Cells($count, 2);
if (!defined $cell->{Value}) { $cell->EntireRow->Delete; }
}
##
##
use strict;
use warnings;
use Win32::OLE;
my $xl = Win32::OLE->new('Excel.Application');
$xl->{Visible} = 1;
my $nShtsOld = $xl->{SheetsInNewWorkbook};
$xl->{SheetsInNewWorkbook} = 1;
my $wb = $xl->Workbooks->Add;
$xl->{SheetsInNewWorkbook} = $nShtsOld;
my $sht = $wb->Sheets(1);
$sht->Cells(1, 1)->{Value} = "A"; $sht->Cells(1, 2)->{Value} = "E";
$sht->Cells(2, 1)->{Value} = "B";
$sht->Cells(3, 1)->{Value} = "C";
$sht->Cells(4, 1)->{Value} = "D"; $sht->Cells(4, 2)->{Value} = "F";
my $end = $sht->UsedRange->Rows->{Count};
for (my $count = $end; 0 < $count; $count--) {
my $cell = $sht->Cells($count, 2);
if (!defined $cell->{Value}) {$cell->EntireRow->Delete}
}
##
##
use strict;
use warnings;
use Win32::OLE;
my $xl = Win32::OLE->new('Excel.Application');
$xl->{Visible} = 1;
my $nShtsOld = $xl->{SheetsInNewWorkbook};
$xl->{SheetsInNewWorkbook} = 1;
my $wb = $xl->Workbooks->Add;
$xl->{SheetsInNewWorkbook} = $nShtsOld;
$wb->Sheets(1)->Delete;
##
##
use strict;
use warnings;
use Win32::OLE;
my $xl = Win32::OLE->new('Excel.Application');
$xl->{Visible} = 1;
my $nShtsOld = $xl->{SheetsInNewWorkbook};
$xl->{SheetsInNewWorkbook} = 3;
my $wb = $xl->Workbooks->Add;
$xl->{SheetsInNewWorkbook} = $nShtsOld;
for my $nSht(2..3) {
$wb->Sheets($nSht)->Delete;
}
##
##
use strict;
use warnings;
use Win32::OLE;
my $xl = Win32::OLE->new('Excel.Application');
$xl->{Visible} = 1;
my $nShtsOld = $xl->{SheetsInNewWorkbook};
$xl->{SheetsInNewWorkbook} = 3;
my $wb = $xl->Workbooks->Add;
$xl->{SheetsInNewWorkbook} = $nShtsOld;
for (my $nSht = 3; 1 < $nSht; $nSht--) {
$wb->Sheets($nSht)->Delete;
}
##
##
use strict;
use warnings;
use Win32::OLE;
my $xl = Win32::OLE->new('Excel.Application');
$xl->{Visible} = 1;
my $wb = $xl->Workbooks->Add;
for my $nSht (2..$wb->Sheets->{Count}) {
$wb->Sheets(2)->Delete;
}