【发布时间】:2014-08-21 16:20:46
【问题描述】:
我正在尝试使用Excel::Writer::XLSX 和MIME::Lite 发送附有xlsx 文件的电子邮件。 excel文件的生成工作,因为我可以scp并在Excel中打开文件而没有任何问题。当我尝试从我的电子邮件客户端(Outlook 2013)打开附件时,我收到此错误:
“Excel 无法打开文件“from_2014-06_to_2014-07.xlsx”,因为 文件格式或文件扩展名无效。确认文件有 未损坏且文件扩展名与 文件。”
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 文件?
【问题讨论】:
-
试试
'Data' => "File size:". -s $filepath -
'数据' => "文件大小"。 -s $filepath 返回 0。ls -la 返回 97403。而且附件仍然不起作用。
-
所以 $filepath 无论是绝对路径还是相对路径都是错误的。还有
use strict;
标签: excel perl mime-types