duancan1950 2017-04-21 12:41
浏览 36

测试是否在phpexcel Bundle中设置cellule之前

I use phpexcelBundle for export database to file excel but i have problem when I use attribut in databsae is null ,I have problem of export file excel ,I have problem attribut is null but when i use if before set cellule I have problem of export also this is problem :

[:error] [pid 2684] [client ::1:33360] PHP Parse error: syntax error, unexpected '$phpExcelObject' (T_VARIABLE), expecting function (T_FUNCTION) in /var/www/html/Projetsf/src/FrontBundle/Controller/StepsController.php on line 10000, referer:

this is code controller :

public function exportXLSAction($id){

         $phpExcelObject = new PHPExcel();
          $phpExcelObject->getProperties()->setCreator("liuggio")
           ->setLastModifiedBy("Giulio De Donato")
           ->setTitle("Office 2005 XLSX Test Document")
           ->setSubject("Office 2005 XLSX Test Document")
           ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
           ->setKeywords("office 2005 openxml php")
           ->setCategory("Test result file");
    $em = $this->container->get('doctrine')->getManager($this->container->get('account_manager')->getCurrentAccount()->getEmname());
    $Employee= $em->getRepository('FrontBundle:Employee')->findOneBy(array('id' =>$id));


     if ($Employee->getNom() != null) { $x = $Employee->getNom(); } else  { $x = ' '; }
       $phpExcelObject->setActiveSheetIndex(0)
                ->setCellValue('A1', 'Civilité')
                ->setCellValue('A2', $Employee->getCivilite())
                ->setCellValue('B1','Nom')
                ->setCellValue('B2', $x)
                ->setCellValue('C1', 'Prénom')
                ->setCellValue('C2', $Employee->getPrenom())
                ->setCellValue('D1', 'Email Personnel')
                ->setCellValue('D2', $Employee->getEmail())
               ->setCellValue('E1', 'Adresse Personnel')
                ->setCellValue('E2', $Employee->getAdresse()) ;


              foreach(range('A','Z') as $columnID){
     }
     }
     $phpExcelObject->setActiveSheetIndex(0)->getColumnDimension($columnID)->setAutoSize(true);
}
 foreach(range('A','Z') as $columnID){
     $phpExcelObject->setActiveSheetIndex(0)->getColumnDimension('A'.$columnID)->setAutoSize(true);
}


$objWriter = new PHPExcel_Writer_Excel2007($phpExcelObject);
$nomfichier = $Employee->getPrenom().'.xlsx';
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$nomfichier.'"');
header('Cache-Control: max-age=0');

$objWriter->save('php://output'); 


     // var_dump($response);
       return new response('yes');
             }

problem in test if $employee->getnom()!= null ... but i have make this test

help me for resolve this problem and thanks advanced

  • 写回答

1条回答 默认 最新

  • dpiw16824 2017-04-21 12:57
    关注

    Possibly a typo in this block of statement?

                  foreach(range('A','Z') as $columnID){
         }  // WHY?
         } // WHY?
         $phpExcelObject->setActiveSheetIndex(0)->getColumnDimension($columnID)->setAutoSize(true);
    }
    

    Try removing them, as example something like:

        foreach(range('A','Z') as $columnID){
        $phpExcelObject->setActiveSheetIndex(0)->getColumnDimension($columnID)->setAutoSize(true);
        }
    
        foreach(range('A','Z') as $columnID){
    $phpExcelObject->setActiveSheetIndex(0)->getColumnDimension('A'.$columnID)->setAutoSize(true);
        }
    

    EDIT:

    Try this code:

        public function exportXLSAction($id){
    
            $phpExcelObject = new \PHPExcel();
            $phpExcelObject->getProperties()->setCreator("liuggio")
                ->setLastModifiedBy("Giulio De Donato")
                ->setTitle("Office 2005 XLSX Test Document")
                ->setSubject("Office 2005 XLSX Test Document")
                ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
                ->setKeywords("office 2005 openxml php")
                ->setCategory("Test result file");
            $em = $this->container->get('doctrine')->getManager($this->container->get('account_manager')->getCurrentAccount()->getEmname());
            $Employee= $em->getRepository('FrontBundle:Employee')->findOneBy(array('id' =>$id));
    
    
            if ($Employee->getNom() != null) { $x = $Employee->getNom(); } else  { $x = ' '; }
            $phpExcelObject->setActiveSheetIndex(0)
                ->setCellValue('A1', 'Civilité')
                ->setCellValue('A2', $Employee->getCivilite())
                ->setCellValue('B1','Nom')
                ->setCellValue('B2', $x)
                ->setCellValue('C1', 'Prénom')
                ->setCellValue('C2', $Employee->getPrenom())
                ->setCellValue('D1', 'Email Personnel')
                ->setCellValue('D2', $Employee->getEmail())
                ->setCellValue('E1', 'Adresse Personnel')
                ->setCellValue('E2', $Employee->getAdresse()) ;
    
    
    foreach(range('A','Z') as $columnID){
        $phpExcelObject->setActiveSheetIndex(0)->getColumnDimension('A'.$columnID)->setAutoSize(true);
    }
    
    
    $objWriter = new \PHPExcel_Writer_Excel2007($phpExcelObject);
    $nomfichier = $Employee->getPrenom().'.xlsx';
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="'.$nomfichier.'"');
    header('Cache-Control: max-age=0');
    
    $objWriter->save('php://output');
    
    
    // var_dump($response);
    return new response('yes');
    }
    

    Hope this help

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)