1. Go to this page and download the library: Download avadim/fast-excel-writer 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/ */
// Set height of row 2 to 33
$sheet->setRowHeight(2, 33);
// Set height of rows 3,5 and 7 to 33
$sheet->setRowHeight([3, 5, 7], 33);
// Set heights of several rows
$sheet->setRowHeights([1 => 20, 2 => 33, 3 => 40]);
// Hide row 8
$sheet->setRowVisible(8, false);
// Other way
$sheet->setRowHidden(8);
// Hide rows 9, 10, 11
$sheet->setRowVisible([9, 10, 11], false);
// Show row 10
$sheet->setRowVisible(10, true);
$sheet = $excel->sheet();
// Write row 1
$sheet->writeRow(['aaa1', 'bbb1', 'ccc1']);
// Write row 2
$sheet->writeRow(['aaa2', 'bbb2', 'ccc2']);
// Try to set height of previous row 1
$sheet->setRowHeight(1, 33);
// Set width of column D to 24
$this->setColWidth('D', 24);
$this->setColOptions('D', ['width' => 24]);
// Set auto width
$this->setColWidth('D', 'auto');
$this->setColWidthAuto('D');
$this->setColOptions('D', ['width' => 'auto']);
// Set width of specific columns
$sheet->setColWidths(['B' => 10, 'C' => 'auto', 'E' => 30, 'F' => 40]);
// Set width of columns from 'A'
$sheet->setColWidths([10, 20, 30, 40], 24);
$colOptions = [
'B' => ['width' => 10],
'C' => ['width' => 'auto'],
'E' => ['width' => 30],
'F' => ['width' => 40],
];
$sheet->setColOptions($colOptions);
// Set minimum width to 20
$this->setColMinWidth('D', 20);
// The value 10 will not be set because it is less than the minimum value
$this->setColWidth('D', 10);
// But width 30 will be set
$this->setColWidth('D', 30);
// The column width will be set to the width of the content, but not less than 20
$this->setColWidthAuto('D');
$excel = Excel::create();
$excel->setFileName($outFileName);
$sheet = $excel->sheet();
// Named a single cell
$sheet->addNamedRange('B2', 'cell_name');
// Named range in a sheet
$sheet->addNamedRange('c2:e3', 'range_name');
// Add named range in a workbook (sheet name
$sheet->writeCell('Text to A1');
$sheet->addNote('A1', 'This is a note for cell A1');
$sheet->writeCell('Text to B1')->addNote('This is a note for B1');
$sheet->writeTo('C4', 'Text to C4')->addNote('Note for C1');
// If you specify a range of cells, then the note will be added to the left top cell
$sheet->addNote('E4:F8', "This note\nwill added to E4");
// You can split text into multiple lines
$sheet->addNote('D7', "Line 1\nLine 2");
$sheet->addNote('A1', 'This is a note for cell A1', ['width' => '200pt', 'height' => '100pt', 'fill_color' => '#ffcccc']);
// Parameters "width" and "height" can be numeric, by default these values are in points
// The "fill_color" parameter can be shortened
$noteStyle = [
'width' => 200, // equivalent to '200pt'
'height' => 100, // equivalent to '100pt'
'fill_color' => 'fcc', // equivalent to '#ffcccc'
];
$sheet->writeCell('Text to B1')->addNote('This is a note for B1', $noteStyle);
// This note is visible when the Excel workbook is displayed
$sheet->addNote('C8', 'This note is always visible', ['show' => true]);
// Insert an image to the cell A1
$sheet->addImage('A1', 'path/to/file');
// Insert an image to the cell B2 and set with to 150 pixels (height will change proportionally)
$sheet->addImage('B2', 'path/to/file', ['width' => 150]);
// Set height to 150 pixels (with will change proportionally)
$sheet->addImage('C3', 'path/to/file', ['height' => 150]);
// Set size in pixels
$sheet->addImage('D4', 'path/to/file', ['width' => 150, 'height' => 150]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.