PHP code example of burhan15 / office-pack

1. Go to this page and download the library: Download burhan15/office-pack library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

burhan15 / office-pack example snippets


use Vendor\Office\Office;


Vendor\Office\Office;

$workbook = Office::excel()->create();
$sheet = $workbook->sheet('Sales');

$sheet->setCell('A1', 'Product');
$sheet->setCell('B1', 'Price');
$sheet->setCell('C1', 'Qty');
$sheet->setCell('B2', 10);
$sheet->setCell('C2', 3);
$sheet->setFormula('D2', '=B2*C2');

$workbook->save('report.xlsx');

$opened = Office::excel()->open('report.xlsx');
$opened->calculate();
echo $opened->sheet('Sales')->getCell('D2')->value; // 30

$doc = Office::document()->create();
$doc->addParagraph('Hello {{name}}');
$doc->setHeader('Confidential');
$doc->setFooter('Page footer');
$doc->addPageBreak();
$doc->setVariables(['name' => 'Ada']);
$doc->save('letter.docx');

$deck = Office::presentation()->create();
$deck->slide(1)->addText('Quarterly review')->addText('Revenue is up');
$deck->save('deck.pptx');

$pdf = Office::pdf()->create();
$pdf->addPage('Hello from the SDK');
$pdf->save('note.pdf');

use Vendor\Office\Mime;

$wb = Office::excel()->create();
$wb->sheet('Sales')->setCell('A1', 'Hi');
foreach (Mime::downloadHeaders('report.xlsx') as $name => $value) {
    header("$name: $value");
}
echo $wb->toString();
js
sheet.setFormula('E2', '=VLOOKUP("banana",A2:C10,2,FALSE)');
bash
npm test
php tests/php/spreadsheet_test.php
php tests/php/formula_test.php