怎样将两个数组分别输出到Exce两个sheet中?
怎样将两个数组分别输出到Exce两个sheet中?
如题,下面的程序只能将数组 @glossary 输出到sheet1中,请问怎样将 另一数组@odds 输出到sheet2中?
use strict;
use warnings;
use Cwd;
use Win32::OLE qw();
use Win32::OLE::Const 'Microsoft Excel';
my @glossary = (
'北京',
'上海',
'天津',
'广州',
'深圳',
'南京',
'武汉',
);
my @odds = (
'beijing',
'shanghai',
'tianjin',
'guangzhou',
'shenzhen',
'nanjing',
'wuhan',
);
print join "\n", &sort_gloss_in_excel(@glossary);
sub sort_gloss_in_excel {
print ">>>>>>>>>>>> Exporting glossary entries into Microsoft Excel.\n";
my (@gloss) = @_;
my @sorted_gloss;
my $gloss_sheet_file = "d:/gloss_entry.xls";
my $current_path = getcwd;
my $gloss_nums = @gloss;
# delete last $gloss_sheet_file
unlink($gloss_sheet_file) if (-e $gloss_sheet_file);
# create new Excel objects
my $Gloss_Excel = Win32::OLE->new( 'Excel.Application', sub {$_[0]->Quit;} )
or die "\n \$%\@&#! DID YOU INSTALL MS Excel IN YOUR MACHINE?\n";
my $Gloss_Book = $Gloss_Excel->Workbooks->Add(1);
my $Gloss_Sheet = $Gloss_Book->Worksheets(1);
# write @gloss to Excel
foreach my $row (1..$gloss_nums) {
$Gloss_Sheet->Cells($row, 1)->{'Value'} = $gloss[$row-1];
}
print ">>>>>>>>>>>> Sorting glossary entries in Microsoft Excel.\n";
$Gloss_Book->SaveAs("$gloss_sheet_file");
undef $Gloss_Book;
undef $Gloss_Excel;
return @sorted_gloss;
}