向高手请教,看这段代码问题出在哪里?
时间:2011-06-21
来源:互联网
我写了段代码,但是有的时候会有问题:excel明明已经关掉了,但是任务管理器中显示excel进程还在运行。请教高手帮忙看下,这个代码是不是有bug。
#!/usr/bin/perl -w
use warnings;
use diagnostics;
use Text::CSV_XS;
use Spreadsheet:
arseExcel;
use Spreadsheet:
arseExcel::FmtUnicode;
$filename="Test.xls";
my $oExcel = new Spreadsheet:
arseExcel;
my $code = "gb2312";
my $oFmtJ = Spreadsheet:
arseExcel::FmtUnicode->new(Unicode_Map =>$code);
my $oBook = $oExcel->
arse( $filename, $oFmtJ );
my $sheet=$oBook->{Worksheet}[0];
my $sheet_name=$sheet->{Name};
#print $sheet_name;
my $row=1;
my $result="";
my $key="";
my %table=();
my $item;
open Lot_loss, ">>Lot_loss.txt" or die "Cannot write to: $!";
open Key_record, ">>Key_record.txt" or die "Cannot write to: $!";
print Lot_loss "This mail will be sent by user.\n";
print Lot_loss "Action\tTester \tPROD \tLast Fail\tRepeated Fails\t\t\t\t\tTrend\n";
my $file="Key_record.txt";
open(MYFILE,$file) || die "Can not open the file: $!";
my $count =0;
my @temp;
my @time;
while ($item=<MYFILE>
{
@temp = split(/\n/, $item);
$item = $temp[0];
$table{$item}=$count;
$count = $count+1;
}
while($row<50)
{
my $col=33;
my $record=0;
my $cell=$sheet->get_cell($row,$col);
my $Flag=$cell->value;
if ($Flag==1)
{
$record=$record+1;
}
$col=$col-1;
$cell=$sheet->get_cell($row,$col);
$Flag=$cell->value;
if ($Flag==1)
{
$record=$record+2;
}
$col=$col-1;
$cell=$sheet->get_cell($row,$col);
$Flag=$cell->value;
if ($Flag==1)
{
$record=$record+4;
}
my $Rcol=0;
if ($record==1 || $record==5)
{
#Action
$result=" \t";
#tester
my $cell=$sheet->get_cell($row,$Rcol);
my $line=$cell->value;
$result=$result.$line."\t";
$key=$line;
$Rcol=8;
$cell=$sheet->get_cell($row,$Rcol);
$line=$cell->value;
@time = split(/\./, $line);
$line = $time[0];
$key=$key.$line;
#prod
$Rcol=9;
$cell=$sheet->get_cell($row,$Rcol);
$line=$cell->value;
$result=$result.$line."\t";
$key=$key.$line;
#Last Fail
$Rcol=22;
$cell=$sheet->get_cell($row,$Rcol);
$line=$cell->value;
$key=$key.$line;
$len=rindex $line."\$", "\$";
#print "$len\n";
if ($len==6)
{
$line=$line." ";
}
if ($len==
{
$line=$line." ";
}
$result=$result.$line."\t";
#Repeated Fail
$Rcol=23;
$cell=$sheet->get_cell($row,$Rcol);
if ($cell)
{
$line=$cell->value;
$key=$key.$line;
$len=rindex $line."\$", "\$";
while ($len<41)
{
$line=$line." ";
$len=$len+1;
}
}
else
{
$line=" \t\t\t\t";
}
$result=$result.$line."\t";
#Trend
$Rcol=10;
while($Rcol<20)
{
$cell=$sheet->get_cell($row,$Rcol);
$line=$cell->value;
$key=$key.$line;
$result=$result.$line;
$Rcol=$Rcol+1;
}
$result=$result."\n\n";
#print $key;
if(!exists($table{$key}))
{
$key=$key."\n";
print Key_record $key;
print Lot_loss $result;
#print "False";
}
else
{
#print "True";
}
}
$row=$row+1;
}
print Lot_loss "\nAction Option:\n";
print Lot_loss "1...\n";
print Lot_loss "2...\n";
print Lot_loss "3...\n";
print Lot_loss "4...\n";
close Lot_loss;
close Key_record;
qx(del lot_loss.txt);
#!/usr/bin/perl -w
use warnings;
use diagnostics;
use Text::CSV_XS;
use Spreadsheet:

use Spreadsheet:

$filename="Test.xls";
my $oExcel = new Spreadsheet:

my $code = "gb2312";
my $oFmtJ = Spreadsheet:

my $oBook = $oExcel->

my $sheet=$oBook->{Worksheet}[0];
my $sheet_name=$sheet->{Name};
#print $sheet_name;
my $row=1;
my $result="";
my $key="";
my %table=();
my $item;
open Lot_loss, ">>Lot_loss.txt" or die "Cannot write to: $!";
open Key_record, ">>Key_record.txt" or die "Cannot write to: $!";
print Lot_loss "This mail will be sent by user.\n";
print Lot_loss "Action\tTester \tPROD \tLast Fail\tRepeated Fails\t\t\t\t\tTrend\n";
my $file="Key_record.txt";
open(MYFILE,$file) || die "Can not open the file: $!";
my $count =0;
my @temp;
my @time;
while ($item=<MYFILE>

{
@temp = split(/\n/, $item);
$item = $temp[0];
$table{$item}=$count;
$count = $count+1;
}
while($row<50)
{
my $col=33;
my $record=0;
my $cell=$sheet->get_cell($row,$col);
my $Flag=$cell->value;
if ($Flag==1)
{
$record=$record+1;
}
$col=$col-1;
$cell=$sheet->get_cell($row,$col);
$Flag=$cell->value;
if ($Flag==1)
{
$record=$record+2;
}
$col=$col-1;
$cell=$sheet->get_cell($row,$col);
$Flag=$cell->value;
if ($Flag==1)
{
$record=$record+4;
}
my $Rcol=0;
if ($record==1 || $record==5)
{
#Action
$result=" \t";
#tester
my $cell=$sheet->get_cell($row,$Rcol);
my $line=$cell->value;
$result=$result.$line."\t";
$key=$line;
$Rcol=8;
$cell=$sheet->get_cell($row,$Rcol);
$line=$cell->value;
@time = split(/\./, $line);
$line = $time[0];
$key=$key.$line;
#prod
$Rcol=9;
$cell=$sheet->get_cell($row,$Rcol);
$line=$cell->value;
$result=$result.$line."\t";
$key=$key.$line;
#Last Fail
$Rcol=22;
$cell=$sheet->get_cell($row,$Rcol);
$line=$cell->value;
$key=$key.$line;
$len=rindex $line."\$", "\$";
#print "$len\n";
if ($len==6)
{
$line=$line." ";
}
if ($len==

{
$line=$line." ";
}
$result=$result.$line."\t";
#Repeated Fail
$Rcol=23;
$cell=$sheet->get_cell($row,$Rcol);
if ($cell)
{
$line=$cell->value;
$key=$key.$line;
$len=rindex $line."\$", "\$";
while ($len<41)
{
$line=$line." ";
$len=$len+1;
}
}
else
{
$line=" \t\t\t\t";
}
$result=$result.$line."\t";
#Trend
$Rcol=10;
while($Rcol<20)
{
$cell=$sheet->get_cell($row,$Rcol);
$line=$cell->value;
$key=$key.$line;
$result=$result.$line;
$Rcol=$Rcol+1;
}
$result=$result."\n\n";
#print $key;
if(!exists($table{$key}))
{
$key=$key."\n";
print Key_record $key;
print Lot_loss $result;
#print "False";
}
else
{
#print "True";
}
}
$row=$row+1;
}
print Lot_loss "\nAction Option:\n";
print Lot_loss "1...\n";
print Lot_loss "2...\n";
print Lot_loss "3...\n";
print Lot_loss "4...\n";
close Lot_loss;
close Key_record;
qx(del lot_loss.txt);

test.zip (1.16 KB)
作者: Crystalyyin7 发布时间: 2011-06-21
怎么没得人顶啊?是我问题没有说清楚么?
作者: Crystalyyin7 发布时间: 2011-06-22
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28