7-6-1
設定 Excel 樣式
您沒有觀看影片的權限
請先登入,登入後,確認您的權限後,即可觀看影片。
- 個人常用的標題樣式:
//設定預設工作表中一個儲存格的外觀
$head_style = [
'font' => [
'bold' => true,
'color' => ['rgb' => '000000'],
// 'size' => 12,
'name' => '新細明體',
],
'alignment' => [
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
],
'fill' => [
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => ['rgb' => 'cfcfcf'],
],
'borders' => [
'allborders' => [
'style' => PHPExcel_Style_Border::BORDER_THIN,
'color' => ['rgb' => '000000'],
],
],
];
- 個人常用的內容樣式:
$content_style = [
'font' => [
'bold' => false,
'color' => ['rgb' => '000000'],
// 'size' => 12,
'name' => '新細明體',
],
'alignment' => [
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
],
// 'fill' => [
// 'type' => PHPExcel_Style_Fill::FILL_SOLID,
// 'color' => ['rgb' => 'ffffff'],
// ],
'borders' => [
'allborders' => [
'style' => PHPExcel_Style_Border::BORDER_THIN,
'color' => ['rgb' => '000000'],
],
],
];
- 套用標題樣式
foreach ($head as $column => $value) {
$objActSheet->setCellValueByColumnAndRow($column, $row, $value); //直欄從0開始,橫列從1開始
$objActSheet->getStyleByColumnAndRow($column, $row)->applyFromArray($head_style);
}
- 套用內容樣式:
if ($type == 'signup') {
$signup = Tad_signup_data::get_all($action['id']);
foreach ($signup as $signup_data) {
$iteam = [];
/*--略--*/
$row++;
foreach ($iteam as $column => $value) {
$objActSheet->setCellValueByColumnAndRow($column, $row, $value); //直欄從0開始,橫列從1開始
$objActSheet->getStyleByColumnAndRow($column, $row)->applyFromArray($content_style);
}
}
}
link to https://github.com/tadlearn/tad_signup/commit/45c6c4c989342fdc07dfb9b16b6064a76c87e4b7 \