php - PHPSpreadsheet how to copy cell with formatting?

one text

Solution:

getFormattedValue only transfers the formatting of the cell itself (text, cilo, etc.), but not the styles. So that you can copy the data into an array and then apply it. Those. the final pseudocode will look something like this:

<?php
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load("test.xlsx");
$links2 = $spreadsheet->getSheet(0)->getCell("J5")->getValue();
$styleArray = $spreadsheet->getSheet(0)->getStyle('J5')->exportArray();
$spreadsheet->getSheet(0)->setCellValueByColumnAndRow(3, 2, $links2);
$spreadsheet->getSheet(0)->getStyle('С2')->applyFromArray($styleArray);
$oWriter = IOFactory::createWriter($spreadsheet, 'Xlsx');
$oWriter->save("test_result.xlsx");
?>

Source