文件无法使用PHPEXCEL在服务器中正确写入

时间:2014-09-24 07:26:48

标签: phpexcel

我正在尝试使用phpexcel编写excel文件,该文件在本地服务器中正常工作。但是当我在服务器中部署它时,文件只写了一半,丢失了很多数据。我不确定我做错了什么。以前有人能面对这种情况吗?可能是什么原因造成的?我已经完全允许这些文件夹。

使用的代码是:

<?php




    /**
     * PHPExcel
     *
     * Copyright (C) 2006 - 2014 PHPExcel
     *
     * This library is free software; you can redistribute it and/or
     * modify it under the terms of the GNU Lesser General Public
     * License as published by the Free Software Foundation; either
     * version 2.1 of the License, or (at your option) any later version.
     *
     * This library is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * Lesser General Public License for more details.
     *
     * You should have received a copy of the GNU Lesser General Public
     * License along with this library; if not, write to the Free Software
     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     *
     * @category   PHPExcel
     * @package    PHPExcel
     * @copyright  Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
     * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
     * @version    1.8.0, 2014-03-02
     */

    /** Error reporting */
    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
    ini_set('display_startup_errors', TRUE);
    date_default_timezone_set('Europe/London');

    if (PHP_SAPI == 'cli')
        die('This example should only be run from a Web Browser');

    /** Include PHPExcel */
    require_once dirname(__FILE__) . '/Classes/PHPExcel.php';


    // Create new PHPExcel object
    $objPHPExcel = new PHPExcel();

    // Set document properties
    $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
                                 ->setLastModifiedBy("Maarten Balliauw")
                                 ->setTitle("Office 2007 XLSX Test Document")
                                 ->setSubject("Office 2007 XLSX Test Document")
                                 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
                                 ->setKeywords("office 2007 openxml php")
                                 ->setCategory("Test result file");


    $sheet = $objPHPExcel->getActiveSheet();

    if($_POST){
    $data=$_POST['name'];
    $i=0;


    //echo count($data);

    for($z=0;$z<count($data);$z++)
    {
    $newdata=array();
    foreach($_POST['name'][$z] as $val)
    {
       // echo 'inside';
       if(!empty($val)){
        $newdata[$i]=$val;
        $i++;
    }}

    //var_dump($newdata);

    ///$objPHPExcel->getActiveSheet()->fromArray($newdata, null, 'A1');
    //$objPHPExcel->getActiveSheet()->setTitle('data'); 


    $objPHPExcel->createSheet($z);
    // Rename sheet
    $objPHPExcel->getSheet($z)->fromArray($newdata, null, 'A1');
    $objPHPExcel->getSheet($z)->setTitle('Data'.$z); 
    }   
    }

    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('temp/data.xls');
    exit;
    ?>

请有任何想法或建议。

0 个答案:

没有答案