Heim > Backend-Entwicklung > PHP-Tutorial > 关于phpexcel问题

关于phpexcel问题

WBOY
Freigeben: 2016-06-23 14:18:38
Original
1077 Leute haben es durchsucht

phpexcel 导出 linux

在本地运行。导出excel都没问题,但是部署到服务器上就没反应了,看了网上类似注销//require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/ZipStreamWrapper.php';也没作用,以下是导出代码,各位大神谢谢给出意见:

      //excel导出
    function excel(){
     require_once './Classes/PHPExcel.php';
     require_once './Classes/PHPExcel/IOFactory.php';
     $u = D('clients');    
     $data=$_SESSION['datas'];

     $objPHPExcel = new PHPExcel();
     // Set properties
     $objPHPExcel->getProperties()->setCreator("ctos")
     ->setLastModifiedBy("ctos")
     ->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");

     //set width
     $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(8);
     $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
     $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
     $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
     $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(50);
     $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(10);
     $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
     $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(12);
     $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(12);
      $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(30);

     //设置行高度
     $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);

     $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);

     //set font size bold
     $objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10);
     $objPHPExcel->getActiveSheet()->getStyle('A2:J2')->getFont()->setBold(true);

     $objPHPExcel->getActiveSheet()->getStyle('A2:J2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
     $objPHPExcel->getActiveSheet()->getStyle('A2:J2')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);

     //设置水平居中
     $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
     $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     $objPHPExcel->getActiveSheet()->getStyle('G')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     $objPHPExcel->getActiveSheet()->getStyle('H')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     $objPHPExcel->getActiveSheet()->getStyle('I')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

     //
     $objPHPExcel->getActiveSheet()->mergeCells('A1:J1');

     // set table header content
     $objPHPExcel->setActiveSheetIndex(0)
     ->setCellValue('A1', '客户目录')
     ->setCellValue('A2', '客户编号')
     ->setCellValue('B2', '客户名称')
     ->setCellValue('C2', '地区')
     ->setCellValue('D2', '客户状态')
     ->setCellValue('E2', '项目分类')
     ->setCellValue('F2', '客户来源')
     ->setCellValue('G2', '操作人')
     ->setCellValue('H2', '更新时间')
     ->setCellValue('I2', '电话')
     ->setCellValue('J2', '单位');

     // Miscellaneous glyphs, UTF-8
     for($i=0;$i       $objPHPExcel->getActiveSheet(0)->setCellValue('A'.($i+3), $data[$i]['cnum']);
      // print_r( $data[$i]['cnum']);exit;
      $objPHPExcel->getActiveSheet(0)->setCellValue('B'.($i+3),  $data[$i]['cname']);
      $objPHPExcel->getActiveSheet(0)->setCellValue('C'.($i+3), $data[$i]['carea']);
      $objPHPExcel->getActiveSheet(0)->setCellValue('D'.($i+3),  $data[$i]['ctrade']);
      $objPHPExcel->getActiveSheet(0)->setCellValue('E'.($i+3),  $data[$i]['crecords']);
      $objPHPExcel->getActiveSheet(0)->setCellValue('F'.($i+3), $data[$i]['csource']);
      $objPHPExcel->getActiveSheet(0)->setCellValue('G'.($i+3),  $data[$i]['coperator']);
      $objPHPExcel->getActiveSheet(0)->setCellValue('H'.($i+3),  $data[$i]['cutime']);
      $objPHPExcel->getActiveSheet(0)->setCellValue('I'.($i+3),  $data[$i]['cphone']);
      $objPHPExcel->getActiveSheet(0)->setCellValue('J'.($i+3), $data[$i]['cunit']);
      $objPHPExcel->getActiveSheet()->getStyle('A'.($i+3).':J'.($i+3))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
      $objPHPExcel->getActiveSheet()->getStyle('A'.($i+3).':J'.($i+3))->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
      $objPHPExcel->getActiveSheet()->getRowDimension($i+3)->setRowHeight(16);
     }
     //print_r($objPHPExcel);exit;

     // Rename sheet
     $objPHPExcel->getActiveSheet()->setTitle('客户汇总表');


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



     // Redirect output to a client’s web browser (Excel5)

     //  iconv('utf-8", "gb2312", $filename);
     //header("Content-type: text/csv");
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="('.date('Ymd-His').').xls"');
     header('Cache-Control: max-age=0');

     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');  
    
    }

回复讨论(解决方案)

有人遇到过吗?整了一天了

一点一点的调试,是不是路径没写对?

问题发现了,也算是路径问题吧,字母大小写问题,linux要求高一点!

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage