使用PHP_XLSXWriter通过电子邮件发送格式化数据

时间:2017-03-05 11:28:32

标签: php xlsx

我一直在使用PHP_XLSXWriter,我真的很喜欢它的简单和快速,但我无法通过电子邮件使格式化工作。我已经尝试了各种颜色格式的填充,虽然文档似乎使用3个字符十六进制。

这是生成xl格式的函数。 正如你所看到的,我只想填充第一行

function create_xl_string($data) {
$writer = new XLSXWriter();
  $rowdata=array('dr1','rp','RoutePattern','TOD','p1','p2','p3','p4','p5','p6','p7','locNames','1D_Minutes','1D_ACD','1W_Minutes','locations','defrate','maxcost','ptLoss','projLoss','modified','description');
 $rowstyle=array('fill'=>"#FC0",'fill'=>"#FC0",'fill'=>"#FC0",'fill'=>"#CCC",'fill'=>"#09F",'fill'=>"#09F",'fill'=>"#09F",'fill'=>"#09F",'fill'=>"#09F",'fill'=>"#09F",'fill'=>"#09F",'fill'=>"#CC9",'fill'=>"#999",'fill'=>"#999",'fill'=>"#999",'fill'=>"#CC9",'fill'=>"#99C",'fill'=>"#99C",'fill'=>"#99C",'fill'=>"#99C",'fill'=>"#9C6",'fill'=>"#9C6");

 $writer->writeSheetRow('routes', $rowdata, $rowstyle );
 foreach($data as $datarow){
   $writer->writeSheetRow('routes',$datarow);
 }

return $writer->writeToString();
}

这是电子邮件功能:

function emailL($filename1,$subject,$file1){
$multipartSep = '-----'.md5(time()).'-----';
$attch1 = chunk_split(base64_encode($file1));
$instruction ="report for today. ";

        $headers = array(
            "From: a@mydomain.net",
            "Reply-To: a@mydomain.net",
            "CC: b@mydomain.net",
            "Content-Type: multipart/mixed; boundary=\"$multipartSep\""
        );

        $body = "--$multipartSep\r\n"
        . "Content-Type: text/html; charset=ISO-8859-1; format=flowed\r\n"
        . "Content-Transfer-Encoding: 7bit\r\n"
        . "\r\n"
        . "$instruction\r\n"
        . "--$multipartSep\r\n"
        . "Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n"
        . "Content-Transfer-Encoding: base64\r\n"
        . "Content-Disposition: attachment; filename=" . $filename1 . ".xlsx\r\n"
        . "\r\n"
        . "$attch1\r\n"
        . "--$multipartSep--";
        mail("me@mydomain.nett", $subject , $body, implode("\r\n", $headers));
}   

这是电话:

emailL($filenameL,$filenameL,create_xl_string($totalarrayL) );

我需要为样式使用不同的格式吗?问题或许是内容类型? 另外,我无法在文档中找到它,但有没有办法预先设置列宽

1 个答案:

答案 0 :(得分:0)

问题是我有一个旧版本的PHP_xlsxwriter代码。有人指出我的新版本,我让它工作