2014-07-01 113 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

相关问题