Skip to content

Instantly share code, notes, and snippets.

@thephucit
Created July 16, 2020 07:44
Show Gist options
  • Save thephucit/0822fcb13856702239e68abcad20446b to your computer and use it in GitHub Desktop.
Save thephucit/0822fcb13856702239e68abcad20446b to your computer and use it in GitHub Desktop.
Some tips for PhpSpreadsheet
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
const FORMAT_CODE = '_(* #,##0_);_(* (#,##0);_(* "-"??_);_(@_)';
# set row auto height
$worksheet->getRowDimension($rowDetail)->setRowHeight(-1);
# format cell as a number
$worksheet->getStyle([CELL])->getNumberFormat()->setFormatCode(self::FORMAT_CODE);
# set bold
$worksheet->getStyle([CELL])->getFont()->setBold(true|false);
#set text align
$worksheet->getStyle([CELL])->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment