2016-07-25 41 views
2

需要創建一個Excel文件,其中某些單元格中有numbers,這些數字應該作爲超鏈接的標籤。使用數字作爲超鏈接的Excel :: Writer :: XLSX

因此,使用下面的演示代碼:

use strict; 
use warnings; 
use Excel::Writer::XLSX; 

my $workbook = Excel::Writer::XLSX->new('test.xlsx'); 
my $f_url = $workbook->add_format(color => 'blue', underline => 1); 
my $worksheet = $workbook->add_worksheet(); 

my $url = 'http://example.com/aaa='; 
my $num = 123; 

$worksheet->write_url(0, 0, $url.$num, $f_url, $num); 

$workbook->close(); 

以Excel打開test.xlsx後,它顯示了一個細胞預警有關number stored as text,就像在下面的截圖:

enter image description here

選中後convert to number得到:

enter image description here

E.g.正確的超鏈接,其中「數字」確實是數字(右對齊,沒有警告)。

問題是:如何創建test.xlsx以獲得正確的單元格類型?例如numberandhyperlink

Excel::Writer::XLSX的知悉:

write_string() 
write_number() 
write_blank() 
write_formula() 
write_url() 
write_row() 
write_col() 

write_url(在本例中使用的)生產的 「文本」,而不是一個號碼類型細胞。

這裏有一些解決方法來創建正確的xlsx沒有警告?

回答

1

只需要更精確地閱讀文檔。它說:

如果你想有一些其他單元格數據,如數量或公式 您可以使用其他電話寫_覆蓋電池*():

因此,該解決方案正在使用:

$worksheet->write_url(0, 0, $url.$num, $f_url, $num); 
# adding another write after the write_url - the link remains 
$worksheet->write_number(0, 0, $num, $f_url); # and now it is an number 
相關問題