开发者

Two variables in two different columns of excel sheet

开发者 https://www.devze.com 2023-02-14 20:21 出处:网络
How can i print two variables in two different columns of the same excelsheet? $a=<>; $b=<>;

How can i print two variables in two different columns of the same 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;

here i need to print $temp in one column of the excel and $temp2 in another column of the same excelsheet.


You can used Spreadsheet::WriteExcel like,

    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);
0

精彩评论

暂无评论...
验证码 换一张
取 消