我很難找到一種方法來獲取Spreadsheet :: WriteExcel的write_row/write_col來打印Excel表格中的行。幫助電子表格:: WriteExcel perl
我有這種工作方法將它們打印爲文本文件。但是將它們作爲行/列寫入Excel表是我失敗的地方。 我的$ com_sam是這樣的。它是一個多級散列,其中包含所有匹配的樣本以及它們的百分比作爲關鍵字,以及它們與每個樣本匹配的所有其他詳細信息(X3,X32,E32_P,E32_PL是樣本)
'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'
},
這裏是我的代碼,試圖使用WriteExcel將它們打印到Excel中。
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
我希望看到這樣的
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
的結果,而是我明白了這樣的在Excel中。 (當然不是逗號分隔:))
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
應該如何處理array_ref for write_row/write_col? 在此先感謝
'$ array_ref_log'似乎沒有被設置 - 這不能是您運行得到該輸出的實際代碼...? – plusplus
對不起,我評論過它。但是我沒有注意到我運行腳本。問題在於這一點。這就是爲什麼我發佈整個腳本。 – kutipi