0

PHP excel下载它在windows环境下完美运行。

从数据库中获取的数据是正确的。

PHP excel的要求就在那里。

我认为 setcellvalue 不起作用

请建议我如何进一步进行

4

1 回答 1

1

改用setCellValueByColumnAndRow这个函数,将数组添加到 excel 文件,它必须工作

function ADDFExcel($FileName,$Array){//add Date
          if(!is_file($FileName)){
            fclose(fopen($FileName,"a+"));  
          }
          $objPHPExcel = PHPExcel_IOFactory::load($FileName);
          $objWorksheet = $objPHPExcel->getActiveSheet();
          foreach($Array as $Record)
          {
              $num_rows = $objPHPExcel->getActiveSheet()->getHighestRow();
              $i=0;
              foreach($Record as $Fild){
                  $objWorksheet->setCellValueByColumnAndRow($i,$num_rows+1,$Fild,PHPExcel_Style_NumberFormat::FORMAT_TEXT );
                  $i++;
              }  
          }
          $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
          $objWriter->save($FileName);
}

$arr=array(
        array("we","gs","423"),
        array("dg","asd","45345")
 );
 ADDFExcel("1.xlsx",$arr);
于 2013-04-10T09:30:07.677 回答