2014-07-01 57 views
2

我試圖使用Excel::Writer::XLSXMIME::Lite發送附帶xlsx文件的電子郵件。 excel文件的生成工作,因爲我可以scp並在Excel中打開文件沒有任何問題。當我試圖從我的電子郵件客戶端打開附件(Outlook 2013中)我得到這個錯誤:將xlsx附加到使用MIME :: Lite的電子郵件

"Excel cannot open the file "from_2014-06_to_2014-07.xlsx" because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

文件大小Outlook顯示爲444B,但它實際上是95K。我一直在使用Spreadsheet::WriteExcel和MIME類型「application/vnd.ms-excel」發送xls文件,之前沒有任何問題。

這是我試圖發送電子郵件:

sub send_mail{ 
    my $filename = shift; 
    my $to_email = shift; 
    my $from_email = shift; 
    my $date = shift; 
    $filename = shift; 

    my $mail = MIME::Lite->new(
     'From'   => '$from_email', 
     'To'   => $to_email, 
     'Subject'  => "Radio/TV stats $date", 
     'Type'   => 'multipart/mixed', 
     #'content-type' => 'application/zip', 
     #'Data'  => "Here is your stuff", 
    ); 

    $mail->attach(
     'Type'   => 'TEXT', 
     'Data'   => "Here is your stuff", 
    ); 

    $mail->attach(
     #'Type'   => 'application/vnd.ms-excel', 
     'Type'   => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 
     'Path'   => $filepath, 
     'Filename'  => $filename, 
     'Disposition' => 'attachement', 
    ); 

    $mail->send('sendmail'); 
} 

任何人都可以請幫我附上XLSX文件?

+0

嘗試「數據」=>「文件大小:」。 -s $ filepath' –

+0

'Data'=>「文件大小」。 -s $文件路徑返回0. ls -la返回97403.此外,該附件仍然不起作用。 – Twistar

+2

所以$ filepath是錯誤的,如果它是絕對路徑或相對路徑。另外'嚴格使用;' –

回答

4

shift兩次到$filename(第二和第六個字符串)和變量$filepath未被聲明。可能在這裏錯誤?

+0

AHhh ...必須在一大早。謝謝你幫助我! – Twistar

+0

在「Path => $ filepath」中使用絕對路徑是不可能的 – Twistar

+1

當附加xlsx文件時,我還必須先關閉excel :: writer。如果我沒有關閉它,絕對路徑不起作用。 – Twistar

相關問題