Perl excel工作表中两个不同列中的两个变量
如何在同一张Excel工作表的两个不同列中打印两个变量Perl excel工作表中两个不同列中的两个变量,perl,Perl,如何在同一张Excel工作表的两个不同列中打印两个变量 $a=<>; $b=<>; @mul=("$a","$b"); open(OUT,">output.csv"); for ($i = 0; $i < scalar(@mul)-1; $i++) { $source=$mul[$i]; print "\n\nComparision of source: $mul[$i]\n"; print "----------------
$a=<>;
$b=<>;
@mul=("$a","$b");
open(OUT,">output.csv");
for ($i = 0; $i < scalar(@mul)-1; $i++) {
$source=$mul[$i];
print "\n\nComparision of source: $mul[$i]\n";
print "------------------------------------";
for ($j = $i+1; $j < scalar(@mul); $j++) {
$sample=$mul[$j];
print "\n$sample ";
print "\n------\n";
$t=mutate($source,$sample);
print OUT $t;
}
}
sub mutate {
my ($s1,$s2)=@_;
$temp="";
for ($k = 0; $k < length($s1); $k++) {
$seq1=substr($s1,$k,1);
$seq2=substr($s2,$k,1);
if ($seq1 ne $seq2) {
$temp.="($k)";
$temp1.="([$seq1/$seq2])";
}
}
return $temp;
return $temp1;
}
close OUT;
$a=;
$b=;
@mul=(“$a”,“$b”);
打开(OUT,“>output.csv”);
对于($i=0;$i<标量(@mul)-1;$i++){
$source=$mul[$i];
打印“\n\n源的比较:$mul[$i]\n”;
打印“---------------------------------------”;
对于($j=$i+1;$j<标量(@mul);$j++){
$sample=$mul[$j];
打印“\n$sample”;
打印“\n------\n”;
$t=变异($source,$sample);
打印$t;
}
}
亚突变{
我的($s1,$s2)=@;
$temp=“”;
对于($k=0;$k<长度($s1);$k++){
$seq1=子项($s1,$k,1);
$seq2=子项($s2,$k,1);
如果($seq1 ne$seq2){
$temp.=“($k)”;
$temp1.=“([$seq1/$seq2])”;
}
}
返回$temp;
返回$temp1;
}
收尾;
在这里,我需要在excel的一列中打印$temp
,在同一excel工作表的另一列中打印$temp2
。您可以像这样使用
use strict;
use warnings;
use Spreadsheet::WriteExcel;
# Create a new Excel workbook
my $workbook = Spreadsheet::WriteExcel->new('perl.xls');
# Add a worksheet
my $worksheet = $workbook->add_worksheet();
# Add and define a format
my $format = $workbook->add_format(); # Add a format
$format->set_bold();
$format->set_color('red');
$format->set_align('center');
# Write a formatted and unformatted string, row and column notation.
$worksheet->write('A1', 'Test', $format);
$worksheet->write('B1', 'Excel', $format);
我格式化了代码;的
语句以前已中断。两个返回值
以前也存在。感谢nikhil提供了另一个很好的答案,但是$temp和$temp1没有打印在同一excel工作表的不同列上。一个空白excel工作表将作为输出。您确定在编写excel$temp
时包含一些数据,尝试类似于$worksheet->write('A1','test',$format')
以确保excel显示一些数据。