I am having a hard time in working a way to get the write_row/write_col of Spreadsheet::WriteExcel to print the rows in the excel sheet.
I have this working method to print them as a text file. But writing them to the excel sheet as a row/column is where I am failing. My $com_sam is like this. Is it is a multi-level hash which holds all the samples that matches and their percentage as a key and all the other details of their match with each sample.(X3, X32,E32_P,E32_PL are the samples)
'X3' => {
'100.00' => [
{
'NoofCalls' => 30,
'percent' => '100.00',
'NoofNs' => 0,
'match' => 30,
'sample' => 'X3'
},
{
'NoofCalls' => 30,
'percent' => '100.00',
'NoofNs' => 0,
'match' => 30,
'sample' => 'X32'
},
{
'NoofCalls' => 30,
'percent' => '100.00',
'NoofNs' => 0,
'match' => 30,
'sample' => 'E32_P'
},
{
'NoofCalls' => 30,
'percent' => '100.00',
'NoofNs' => 0,
'match' => 30,
'sample' => 'E32_PL'
},
Here is my code trying to print them to excel using WriteExcel.
foreach my $percent ( sort { $b $a } keys %{ $com_sam->{ $s1 } } ){
249
250 my $match_samples = $com_sam->{ $s1 }->{ $percent };
251
252 foreach my $matSam( @ { $match_samples } ){
253 if( ( $s1 ne $matSam->{ sample } ) and ($matSam->{ percent } >= $top_percent) ) {
254
255 next if compare($s1, $matSam->{sample});
256 # print "****,$s1,$matSam->{ sample },$matSam->{ percent },$top,$top_percent,$matSam->{ NoofCalls },$matSam->{ match }, $matSam->{ NoofNs },****\n" ;
257 push @$log_array,($s1,$matSam->{ sample },$matSam->{ percent },$top,$top_percent,$matSam->{ NoofCalls },$matSam->{ match }, $matSam->{ NoofNs } );
258 push @$array_ref_log, @$log_array;
259 for my $col (0 ..7) {
260
261 for my $row (1 .. scalar(@sam2com) ) {
262
263 $worksheet->write_row($row,$col,$array_ref_log);#Wat I get with this is just a single sample compared rather than all the sample.
264 }
265
266
267 }
268 }else{
269
270 my $total_calls = $matSam->{ NoofCalls } + $matSam->{ NoofNs };
271
272 my $l = sprintf "%s, %s, %0.2f, %s, %0.2f,%s,%s,%s", $s1, $matSam->{ sample }, $matSam->{ percent }, $top, $top_percent,$matSam->{ NoofCalls },$matSam->{ match }, $matSam->{ NoofNs } ;
273
274 if( $total_calls == 97 ) {
275
276 # print "$l\n" if ( $matSam->{ NoofNs } { NoofNs } sample
287 }#end of percentage foreach loop
I would like to see the result like this
X3,X3,100.00,X3,100.00,30,30, 0
X3,X32_P,100.00,X3,100.00,30,30, 0
X3,E32,100.00,X3,100.00,30,30, 0
but rather I get it like this in excel. (ofcourse not comma separated :) )
X3,X32,100.00,X3,100.00,30,30, 0,X3,X32_P,100.00,X3,100.00,30,30, 0,X3,E32,100.00,X3,100.00,30,30, 0
X3,X32,100.00,X3,100.00,30,30, 0,X3,X32_P,100.00,X3,100.00,30,30, 0,X3,E32,100.00,X3,100.00,30,30, 0
X3,X32,100.00,X3,100.00,30,30, 0,X3,X32_P,100.00,X3,100.00,30,30, 0,X3,E32,100.00,X3,100.00,30,30, 0
X3,X32,100.00,X3,100.00,30,30, 0,X3,X32_P,100.00,X3,100.00,30,30, 0,X3,E32,100.00,X3,100.00,30,30, 0
X3,X32,100.00,X3,100.00,30,30, 0,X3,X32_P,100.00,X3,100.00,30,30, 0,X3,E32,100.00,X3,100.00,30,30, 0
X3,X32,100.00,X3,100.00,30,30, 0,X3,X32_P,100.00,X3,100.00,30,30, 0,X3,E32,100.00,X3,100.00,30,30, 0
X3,X32,100.00,X3,100.00,30,30, 0,X3,X32_P,100.00,X3,100.00,30,30, 0,X3,E32,100.00,X3,100.00,30,30, 0
X3,X32,100.00,X3,100.00,30,30, 0,X3,X32_P,100.00,X3,100.00,30,30, 0,X3,E32,100.00,X3,100.00,30,30, 0
How should be working on the array_ref for write_row/write_col? Thanks in advance
$array_ref_logdoesn't appear to be set - that can't be the actual code that you ran to get that output...?