phpexcel没有创建新表

时间:2014-12-03 11:48:56

标签: phpexcel

我正在尝试使用PHPExcel库在.xls文件中创建新工作表。 但它并没有创造新的表格。如果要求重命名现有工作表,也不要重命名。 我的代码看起来像这样

<?php
require_once 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
$sheetId = 1;
$objPHPExcel->createSheet(NULL, $sheetId);
$title="Simple";
$objPHPExcel->getActiveSheet()->setTitle($title);
echo date('H:i:s') , " Worksheet renamed";
?>

任何人都可以帮忙 我提到了need to create xsl file with name and had different sheet name

1 个答案:

答案 0 :(得分:1)

试试这个

    <?php
/** PHPExcel */
include 'PHPExcel.php';

/** PHPExcel_Writer_Excel2007 */
include 'PHPExcel/Writer/Excel2007.php';
echo date('H:i:s') . " Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();
// Rename sheet
echo date('H:i:s') . " Rename sheet\n";
$objPHPExcel->getActiveSheet()->setTitle('Simple');

$objPHPExcel->createSheet(NULL, "xyz");
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel->getActiveSheet()->setTitle('abc');

// Save Excel 2007 file
echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));



// Echo done
echo date('H:i:s') . " Done writing file.\r\n";
?>