:::

7-6-1 設定 Excel 樣式

您沒有觀看影片的權限

您沒有觀看影片的權限

請先登入,登入後,確認您的權限後,即可觀看影片。

  1. 個人常用的標題樣式:
    
    //設定預設工作表中一個儲存格的外觀
    $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'],
            ],
        ],
    ];

     

  2. 個人常用的內容樣式:
    $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'],
            ],
        ],
    ];

     

  3. 套用標題樣式
    foreach ($head as $column => $value) {
        $objActSheet->setCellValueByColumnAndRow($column, $row, $value); //直欄從0開始,橫列從1開始
        $objActSheet->getStyleByColumnAndRow($column, $row)->applyFromArray($head_style);
    }
    

     

  4. 套用內容樣式:
    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 \


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1755%26tbsn%3D48

書籍目錄

展開 | 闔起

線上使用者

77人線上 (9人在瀏覽線上書籍)

會員: 0

訪客: 77

更多…