我正在编写一个解析.xls文件的程序。为此,我有一个模板,其中包含五个合并的单元格(B1,C1,D1,E1,F1),并在其中写入“用户相关的错误”。在B2,C2,D2,E2,F2中我写了错误名称,并希望每天保存他们的计数。代码工作正常,但解析并保存合并的单元格(B1,C1,D1,E1,F1)后,表示文本显示为未合并,文本显示在B1中。即使在解析之后,我也需要合并的单元格(合并)。
我该怎么做?
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
my $date=$ARGV[1]; #yymmdd
my $hour=$ARGV[0]; #06
$date or $date=`date --date='1 day ago' +%Y%m%d`;
chomp $date;
chomp $hour;
my $db_name = "ravi";
my $table = "CDR";
my $sub_table = "Submission_Failures";
my $del_table = "Delivery_Failures";
my $host = "xxx.xx.x.xxx";
my $command = "cp /root/prac/CDR/CDR.xls /root/prac/CDR/CDR_Report_20$date$hour.xls";
print $command;
`$command`;
sub NULL_count
{
my $type = $_[0];
my @temp_array;
my $error_db = DBI->connect("DBI:mysql:database=$db_name;host=$host;mysql_socket=/opt/lampstack-5.5.27-0/mysql/tmp/mysql.sock","root","", {'RaiseError' => 1});
my $error_sth = $error_db->prepare("SELECT Error_list from error_potrait WHERE Date='$date' and Type='$type'");
$error_sth->execute() or die $DBI::errstr;
while (my $temp = $error_sth->fetchrow_array())
{
push(@temp_array, $temp);
}
my $temp = @temp_array;
foreach my $i ($temp .. 4)
{
$temp_array[$i] = "NULL";
}
$error_sth->finish();
return @temp_array;
}
my @db_system_errors = NULL_count ("Submission_user_error");
my @db_network_errors = NULL_count ("Submission_ESME_error");
my @db_ESME_errors = NULL_count ("Submission_system_error");
my @db_user_errors = NULL_count ("Submission_network_error");
my @del_user_errors = NULL_count ("Delivery_user_error");
my @del_network_errors = NULL_count ("Delivery_network_error");
my @del_system_errors = NULL_count ("Delivery_system_error");
my @submission_errors = (@db_network_errors,@db_system_errors,@db_ESME_errors,@db_user_errors);
my @delivery_errors = (@del_user_errors,@del_network_errors,@del_system_errors);
sub error_headers
{
my $sheet_no = shift;
my @array = @_;
my $row = 1;
my $col = 1;
# Open an existing file with SaveParser
my $parser = Spreadsheet::ParseExcel::SaveParser->new();
my $template = $parser->Parse("CDR_Report_20$date$hour.xls") or die "Cant open xls";
# Get the first worksheet.
my $sheet = $template->worksheet($sheet_no);
$sheet->AddCell( 1, 0, $date );
foreach my $value (@array)
{
$sheet->AddCell( $row, $col, $value );
++$col;
}
$template->SaveAs("CDR_Report_20$date$hour.xls");
}
error_headers (3,@submission_errors);
error_headers (4,@delivery_errors);
sub parser_excel
{
my $sql_comm = $_[0];
my $sheet_no = $_[1];
my $row = $_[2];
my $col = $_[3];
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$host;mysql_socket=/opt/lampstack-5.5.27-0/mysql/tmp/mysql.sock","root","", {'RaiseError' => 1});
#Selecting the data to fetch
my $sth = $dbh->prepare("$sql_comm");
$sth->execute() or die $DBI::errstr;
# Open an existing file with SaveParser
my $parser = Spreadsheet::ParseExcel::SaveParser->new();
my $template = $parser->Parse("CDR_Report_20$date$hour.xls") or die "Cant open xls";
# Get the first worksheet.
my $sheet = $template->worksheet($sheet_no);
$sheet->AddCell( $_[4], 0, $date );
while (my @row = $sth->fetchrow_array())
{
my $Date_db = shift @row;
foreach my $value (@row)
{
$sheet->AddCell( $row, $col, $value );
++$col;
}
$row++;
$col=0;
}
$template->SaveAs("CDR_Report_20$date$hour.xls");
$sth->finish();
}
parser_excel("Select * from $table where Date = $date and Hour = $hour",2,1,0,0);
parser_excel("Select * from $sub_table where Date = $date and Hour = $hour",3,2,0,1);
parser_excel("Select * from $del_table where Date = $date and Hour = $hour",4,2,0,1);`