$ Spreadsheet = new Spreadsheet (); // initialize
$ Spreadsheet-> createSheet (); // add a sheet
$ Sheet = $ spreadsheet-> getSheet (1); // second operating sheet
$sheet = $spreadsheet->getActiveSheet();
// set the value of the three approaches
$sheet->setCellValue('E6', 'www.helloweba.net');
$sheet->getCell('A1')->setValue('John');
$sheet->setCellValueByColumnAndRow(5, 5, 'hahah');
$ Sheet-> mergeCellsByColumnAndRow (1, 2,1, 5); // merge cells
$ Sheet-> mergeCells ( 'A1: E1'); // merge cells
for ($i=1; $i <= 10; $i++) {
$ Sheet-> setCellValue (. 'A' $ i, 'Hello World plus consider each other fall in love with the other side Caesar'); // this can then merge cells go into
$ Sheet-> setCellValue (. 'B' $ i, 'Hello World plus consider each other fall in love with the other side Caesar'); // this can then merge cells go into
$ Sheet-> setCellValue (. 'C' $ i, 'Hello World plus consider each other fall in love with the other side Caesar'); // this can then merge cells go into
}
$ Sheet-> getStyle ( 'A3: C3') -> getFont () -> setBold (true); // within a certain range bold font
$ Sheet-> getStyle ( 'A4: C5') -> getFont () -> getColor () -> setARGB ( 'cc3399'); // font color, using the color format rgb
$ Sheet-> getColumnDimension ( 'A') -> setWidth (50); // set the column width
$ Sheet-> getDefaultColumnDimension () -> setWidth (50); // Set default column width
$ Sheet-> getColumnDimension ( 'B') -> setAutoSize (true); // automatically set the column width
$ Sheet-> getRowDimension ( '1') -> setRowHeight (50); // set the line high
$ Sheet-> getDefaultRowDimension () -> setRowHeight (15); // set high default row
$ Sheet-> getStyle ( 'A2: E2') -> getFont () -> setSize (14); // set the font size
$ Sheet-> getStyle ( 'A1: C1') -> getAlignment () -> setVertical (Alignment :: VERTICAL_TOP); // vertically upwards
$sheet->getStyle('A1:C1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('66ccff');// 设置背景色
$styleArray = [
'borders' => [
'outline' => [
'borderStyle' => Border::BORDER_THICK,
'color' => ['argb' => '3399ff'],
],
'inside' =>[
'borderStyle' => Border::BORDER_THIN,
'color' => ['argb' => 'cc0000'],
]
],
];
$ Sheet-> getStyle ( 'A1: C5') -> applyFromArray ($ styleArray); // outer frame, the inner frame
$styleArray = [
'borders' => [
'outline' => [
'borderStyle' => Border::BORDER_THICK,
'color' => ['argb' => 'FFFF0000'],
],
],
'font' => ['bold' => true],
'alignment' => [
'Horizontal' => Alignment :: HORIZONTAL_CENTER, // Center Horizontally
'Vertical' => \ PhpOffice \ PhpSpreadsheet \ Style \ Alignment :: VERTICAL_CENTER // vertical centering
],
];
$ Sheet-> getStyle ( 'B2: E8') -> applyFromArray ($ styleArray); // bold, the middle level, the border line color
$ Sheet-> setTitle ( 'when is a title'); // current worksheet title
$sheet->getCell('A4')->setValue("hello\nworld");// 换行
$sheet->setCellValue('E6', 'www.helloweba.net');
$ Sheet-> getCell ( 'E6') -> getHyperlink () -> setUrl ( 'https://www.helloweba.net'); // Click to jump directly
$spreadsheet->getProperties()
-> setCreator ( "Author") // Author
-> setLastModifiedBy ( "Modified By") // Last Modified By
-> setTitle ( "This is the title") // title
-> setSubject ( "This is subtitled") // subtitle
-> setDescription ( "This is a description") // Description
-> setKeywords ( "This is the key") // Keyword
-> setCategory ( "category"); // Category
$writer = new Xlsx($spreadsheet);
$name=rand(10,99);
$ Writer-> save ($ name 'xlsx.'.); // download directly to a local folder