如何在同一个excelsheet的两个不同列中打印两个变量?
$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;
在这里,我需要在excel的一列中打印$temp
,在同一excelsheet的另一列中打印$temp2
。
答案 0 :(得分:2)
你可以使用Spreadsheet::WriteExcel之类的,
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);