Hướng dẫn phpexcel set default font family - phpexcel đặt họ phông chữ mặc định

I want convert excel to pdf. In process of converting I need to change font face. I found setting font face for single cell. Is it possible to set font face for all document?

$phpExcel = new PHPExcel[];

$styleArray = array[
    'font'  => array[
        'bold'  => true,
        'color' => array['rgb' => 'FF0000'],
        'size'  => 15,
        'name'  => 'Verdana'
    ]];

$phpExcel->getActiveSheet[]->getCell['A1']->setValue['Some text'];
$phpExcel->getActiveSheet[]->getStyle['A1']->applyFromArray[$styleArray];

asked Dec 21, 2016 at 9:53

Option #1

Set a default style for the entire workbook [all worksheets]

$phpExcel->getDefaultStyle[]
    ->applyFromArray[$styleArray];

Option #2

Apply the style to a range of cells [the entire worksheet in this case] on each individual worksheet

$phpExcel->getActiveSheet[]
    ->getStyle[ $phpExcel->getActiveSheet[]->calculateWorksheetDimension[] ]
    ->applyFromArray[$styleArray];  

answered Dec 21, 2016 at 10:22

Mark BakerMark Baker

207k31 gold badges339 silver badges381 bronze badges

When I set the default font-family name as below:
**$this->objPHPExcel->getDefaultStyle[]->getFont[]->setName['Simsun, Calibri, Arial, Helvetica, sans-serif'];**
my table's head line with columns name is disappeared. I don't know the exact reason for it.

Bài Viết Liên Quan

Chủ Đề