简体   繁体   中英

PHPExcel - How to apply borders to dynamic range of cells loaded from mysql data

I tried all mentioned here below to no success. I need borders around the data body/cells, excluding the headers row. Range starts from cell A2 to the E as the last column & its rows. Data goes up to 4000 records or more sometimes. I even increased the WAMP's php.ini execution timeout to 300 for test.

Following lines work fine if each one was used only and separately, if all together, ends up with Fatal error of timeout 30 seconds!

    $objPHPExcel->getActiveSheet()->getStyle("A".($rowNumber-1))->applyFromArray($styleBordersArray, False);
    $objPHPExcel->getActiveSheet()->getStyle("B".($rowNumber-1))->applyFromArray($styleBordersArray, False);
    $objPHPExcel->getActiveSheet()->getStyle("C".($rowNumber-1))->applyFromArray($styleBordersArray, False);
    $objPHPExcel->getActiveSheet()->getStyle("D".($rowNumber-1))->applyFromArray($styleBordersArray, False);
    $objPHPExcel->getActiveSheet()->getStyle("E".($rowNumber-1))->applyFromArray($styleBordersArray, False);

Folllwoing line does not work with Fatal error of timeout 30 seconds!

$objPHPExcel->getActiveSheet()->getStyle("A".($rowNumber-1).":E".($rowNumber-1))->applyFromArray($styleBordersArray, False);

Folllwoing line works fine, but is not the desired layout!! Just tried to see.

    $objPHPExcel->getActiveSheet()->getStyle("A".($rowNumber-1).":C".($rowNumber-1))->applyFromArray($styleBordersArray, False);

Folllwoing line does not work with Fatal error of timeout 300 seconds with increased php.ini!

    $objPHPExcel->getActiveSheet()->getStyle("D".($rowNumber-1).":E".($rowNumber-1))->applyFromArray($styleBordersArray, False);

For anyone with the same issue, following line of code right before the range select and applyFromArray fixed the issue:

    set_time_limit(20);

and then follow it with the full range as required as following:

    $objPHPExcel->getActiveSheet()->getStyle("A".($rowNumber-1).":E".($rowNumber-1))->applyFromArray($styleBordersArray, False);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM