PHPExcel Make first row bold

后端 未结 10 862
猫巷女王i
猫巷女王i 2020-12-13 03:34

I am trying to make cells in first row are bold.

This is the method I have created for that purpose.

function ExportToExcel($tittles,$excel_name)
 {
         


        
相关标签:
10条回答
  • 2020-12-13 03:45
    $objPHPExcel->getActiveSheet()->getStyle('1:1')->getFont()->setBold(true);
    

    That way you get the complete first row

    0 讨论(0)
  • 2020-12-13 03:52

    This iterates through a variable number of columns of a particular row, which in this case is the 1st row:

    $rownumber = 1;
    $row = $this->objPHPExcel->getActiveSheet()->getRowIterator($rownumber)->current();
    
    $cellIterator = $row->getCellIterator();
    $cellIterator->setIterateOnlyExistingCells(false);
    
    foreach ($cellIterator as $cell) {
        $cell->getStyle()->getFont()->setBold(true);
    }
    
    0 讨论(0)
  • 2020-12-13 03:53

    Try this

    $objPHPExcel->getActiveSheet()->getStyle('A1:D1')->getFont()->setBold(true);
    
    0 讨论(0)
  • 2020-12-13 03:57

    These are some tips to make your cells Bold, Big font, Italic

    Let's say I have columns from A to L

    A1 - is your starting cell

    L1 - is your last cell

    $objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getFont()->setSize(16);
    $objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getFont()->setItalic(true);
    
    0 讨论(0)
  • 2020-12-13 03:58

    Try this for range of cells:

    $from = "A1"; // or any value
    $to = "B5"; // or any value
    $objPHPExcel->getActiveSheet()->getStyle("$from:$to")->getFont()->setBold( true );
    

    or single cell

    $cell_name = "A1";
    $objPHPExcel->getActiveSheet()->getStyle( $cell_name )->getFont()->setBold( true );
    

    hope that helps

    0 讨论(0)
  • 2020-12-13 03:59
    $objPHPExcel->getActiveSheet()->getStyle("A1:".$objPHPExcel->getActiveSheet()->getHighestDataColumn()."1")->getFont()->setBold(true);
    

    I found this to be a working solution, you can replace the two instances of 1 with the row number. The HighestDataColumn function returns for example C or Z, it gives you the last/highest column that's in the sheet containing any data. There is also getHighestColumn(), that one would include cells that are empty but have styling or are part of other functionality.

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