PHPExcel set border and format for all sheets in spreadsheet

后端 未结 3 1876
孤城傲影
孤城傲影 2020-12-14 09:07

I\'m currently trying to set all borders for my spreadsheet, also formatting such as autosize.

My code below is working, for sheet 1. All other sheets inside the spr

相关标签:
3条回答
  • 2020-12-14 09:41
    for ($s=65; $s<=90; $s++) {
        //echo chr($s);
        $objPHPExcel->getActiveSheet()->getColumnDimension(chr($s))->setAutoSize(true);
    }
    
    0 讨论(0)
  • 2020-12-14 09:45

    To answer your extra question:

    You can set which rows should be repeated on every page using:

    $objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 5);

    Now, row 1, 2, 3, 4 and 5 will be repeated.

    0 讨论(0)
  • 2020-12-14 09:47

    You can set a default style for the entire workbook (all worksheets):

    $objPHPExcel->getDefaultStyle()
        ->getBorders()
        ->getTop()
            ->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getDefaultStyle()
        ->getBorders()
        ->getBottom()
            ->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getDefaultStyle()
        ->getBorders()
        ->getLeft()
            ->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getDefaultStyle()
        ->getBorders()
        ->getRight()
            ->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    

    or

      $styleArray = array(
          'borders' => array(
              'allborders' => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
              )
          )
      );
    $objPHPExcel->getDefaultStyle()->applyFromArray($styleArray);
    

    And this can be used for all style properties, not just borders.

    But column autosizing is structural rather than stylistic, and has to be set for each column on each worksheet individually.

    EDIT

    Note that default workbook style only applies to Excel5 Writer

    0 讨论(0)
提交回复
热议问题