John McNamara 的电子表格 WriteExce 可以正常下载 excel 文件。
目前使用此功能从mysql导出数据并生成excel。正常工作以执行动作下载,但我想创建动作电子邮件。我已经设置好了所有东西,但我只需要更改动作下载以保存到 tmp,例如
但是我如何生成 Excel tmp 并通过电子邮件发送呢?
<?php
include("include/conexion.php"); // CONECT TO BBDD
require_once('include/write_excel/Worksheet.php'); // CLASS EXCEL
require_once('include/write_excel/Workbook.php'); // CLASS EXCEL
include_once("include/Classes/class.phpmailer.php"); // CLASS EMAIL
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: inline; filename=$filename" );
$filename = "Listado.xls";
// Creating a workbook
$workbook = new Workbook("-");
$worksheet1 =& $workbook->add_worksheet('Listado');
$formato_texto_negrita =& $workbook->add_format();
$formato_texto_negrita->set_bold(0x2BC);
$formato_texto_negrita->set_align('left');
$formato_texto_negrita->set_size(8);
$formato_texto =& $workbook->add_format();
$formato_texto->set_align('left');
$formato_texto->set_size(8);
$formatot2 =& $workbook->add_format();
$formatot2->set_align('right');
$formatot2->set_size(8);
$formato_numero =& $workbook->add_format();
$formato_numero->set_align('right');
$formato_numero->set_num_format('0.000,00;[Red]-0.000,00');
$formato_numero->set_size(8);
$i=3;
$j=0;
$k=0;
$opcionListado = $_POST['opcionListado'];
$worksheet1->set_column($k,$k++,10); // CLAVE
$worksheet1->set_column($k,$k++,10); // Recepcion
$worksheet1->set_column($k,$k++,15); // Ubicacion
// NAME OF COLUMNS…..
$res = mysql_query($query, $conexion);
for($l=0;$row=mysql_fetch_array($res);$l++)
{
// DATE ROWS…….
}
file_put_contents($filename, $workbook->close());
?>
并且电子邮件代码包含在其他 php.ini 文件中。