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

6. Merge/Unmerge Cells

$spreadsheet->getActiveSheet()->mergeCells('A18:E22');
$spreadsheet->getActiveSheet()->unmergeCells('A18:E22');

7. Membaca Images 

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/master/samples
  3. Reading Images from a worksheet, https://phpspreadsheet.readthedocs.io/en/latest/topics/recipes/#reading-images-from-a-worksheet
  4. Reading Images from Excel, https://stackoverflow.com/questions/52344718/reading-images-from-excel