PHPExcel Writer创建空白文件

时间:2015-10-07 12:45:20

标签: php phpexcel

我尝试使用phpexcel writer

创建新的excel文件
<?php

     set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
     include 'Classes/PHPExcel/IOFactory.php';
     include 'Classes/PHPExcel/Writer/Excel2007.php';     
     $inputFileName ='mak.xlsx';

    try 
    {
         $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
         $objReader = PHPExcel_IOFactory::createReader($inputFileType);
         $objPHPExcel = $objReader -> load($inputFileName);
         $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
         $objWriter->save('MyExcel.xlsx');            
    }
    catch(Exception $e) 
    {
        die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
    }

?>

我首先加载退出excel文件,然后将文件数据传递到PHPExcel_Writer_Excel2007($objPHPExcel)。新文件创建为空白文件

1 个答案:

答案 0 :(得分:2)

试试这个:

$sheet = $objPHPExcel->setActiveSheetIndex(0);
$sheet->setCellValue('A1','TEST');

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);

在您的示例中,$ objPHPExcel为空,这就是您获取空文档的原因