Friday, 4 May 2018

PHPOffice : PhpSpreadsheet

Status : Draft


FAQ


1. Bagaimana mendapatkan string kolom, dari angka ?

use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
Coordinate::stringFromColumnIndex(1);

Untuk informasi lebih lanjut lihat disini.

2. style dan protection (todo : perlu dilengkapi )

$styleArray = [
    'font' => [
        'bold' => true,
        'size' => 12
    ],
    'alignment' => [
        'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT,
    ],
    'borders' => [
//opsinya bisa : left, right, top, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
        'top' => [
            'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
        ],
    ],
    'fill' => [
        'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR,
        'rotation' => 90,
        'startColor' => [
            'argb' => 'FFA0A0A0',
        ],
        'endColor' => [
            'argb' => 'FFFFFFFF',
        ],
    ],
];

$spreadsheet->getActiveSheet()->getStyle('A3')->applyFromArray($styleArray);
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(12);
$spreadsheet->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$spreadsheet->getActiveSheet() ->getProtection()->setSheet(true);
$spreadsheet->getActiveSheet()->getStyle('B1') ->getProtection() ->setLocked(\PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED);

Untuk informasi lebih lanjut : Styling cell bordersSetting a column's width,  Setting security on a spreadsheet

3. freezePane

$sheet->freezePaneByColumnAndRow(4,4);

Untuk informasi lebih lanjut : Freeze Panes

4. Membaca File 

Untuk informasi lebih lanjut Reading Files

5. Menulis File 

Untuk informasi lebih lanjut Writing a spreadsheetGenerating Excel Using PhpSpreadsheet in PHP

Referensi

  1. A pure PHP library for reading and writing spreadsheet files https://phpspreadsheet.readthedocs.io
  2. PhpSpreadsheet samples, https://github.com/PHPOffice/PhpSpreadsheet/tree/develop/samples

No comments:

Post a Comment