如何在多列中设置文本?

How to set text in multiple columns?

如何将文本分为两列,例如 (A1:B1 , 'hello world')?

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = new Spreadsheet();

$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$sheet->setCellValue('A2', 'Hola a todos !');

$sheet->setCellValueByColumnAndRow(5, 7, 'Prueba');
$writer = new Xlsx($spreadsheet);
$writer->save('excel/hello world.xlsx');  

使用MergeCells连接两列

$sheet->MergeCells('A1:B1');

你只需将文本放在你加入的第一列

$sheet->setCellValue('A1', 'Hello World !');
$sheet->MergeCells('A1:B1');