如何增加PHP excel中的列

时间:2016-06-23 14:15:24

标签: php excel phpexcel export-to-excel

我正在创建动态列,我的列是1000+,任何人都可以指导我如何增加PHPexcel中的列。如何在创建动态列时增加列长度?或者是否有其他方式供您参考我在下面显示我的代码:

private function _buildExcellTableData(ExportExcel $excel)
    {
        $excel->row++;
        $excel->row++;
        $sheet = $excel->excel->getActiveSheet();
        $sheet->setCellValue('D1', 'Role Requirement Report');
        $header1 = $sheet->mergeCells('D1:G1')->getStyle('D1');
        $header1->getFont()->setSize(18)->setBold(true);
        $header1->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('E6E6E6');

        $alpha = 'B';
        $countCells = count($this->data['roles']);
        $header = $sheet->getStyle('A'.$excel->row);
        $header->getFont()->setBold(true);
        $header->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('E6E6E6');
        $sheet->getStyle('A'.$excel->row)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $sheet->getColumnDimension('A')->setAutoSize(TRUE);
        $sheet->setCellValue('A'.$excel->row, 'Roles/Requirements');

        $rolesIds = array_map(create_function('$o', 'return $o->id;'), $this->data['roles']);

        foreach($this->data['roles'] as $key=>$value)
        {
            for ($i = 0; $i < $countCells; $i++)
            {
                $sheet->getColumnDimension($alpha)->setAutoSize(TRUE);
                $sheet->setCellValue($alpha.'6',$value->title);
            }
            $alpha++;

        }
        $row_start = $excel->row;

        foreach ($this->data['rolesrequirement'] as $key=>$row)
        {
            $excel->row++;
            $sheet->setCellValue('A' . $excel->row, $row->title);
            $roleCheck = array_map('trim', explode(',', $row->roleid));
            $alpha = 'B';
            for ($i = 0; $i < $countCells; $i++)
            {

                $value = (in_array($rolesIds[$i], $roleCheck)) ? 'x' : '';
                $sheet->getStyle($alpha.$excel->row)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $sheet->setCellValue($alpha.$excel->row, $value);
                $alpha++;
            }
        }
        $row_style = $sheet->getStyle('A'.$row_start);
        $row_style->getBorders()->getAllBorders()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
    }

提前致谢!

0 个答案:

没有答案