PHP
0
Вклад в тег
$mergedWorkbook=new Spreadsheet();
foreach ($files as $file) {
$spreadsheet = IOFactory::load($file);
$worksheets = $spreadsheet->getAllSheets();
foreach ($worksheets as $worksheet) {
if ($mergedWorkbook->sheetNameExists($worksheet->getTitle())) {
$worksheet->setTitle($worksheet->getTitle() . rand(1,40));
}
$mergedWorkbook->addExternalSheet($worksheet);
}
}
$mergedWorkbook->removeSheetByIndex(0);
$writer = IOFactory::createWriter($mergedWorkbook, 'Xlsx');
$folderName=self::createFolder();
$writer->save(
"{$_SERVER['DOCUMENT_ROOT']}/upload/tmp/{$folderName}/mergedFilesDoc.xlsx"
);
// other_code before 1399 line
foreach ($this->getWorksheetIterator() as $sheet) {
// for all cells
foreach ($sheet->getCoordinates(false) as $coordinate) {
$cell = $sheet->getCell($coordinate);
$cell->setXfIndex($map[$cell->getXfIndex()]?$map[$cell->getXfIndex()]:0); // code modification
}
// for all row dimensions
foreach ($sheet->getRowDimensions() as $rowDimension) {
if ($rowDimension->getXfIndex() !== null) {
$rowDimension->setXfIndex($map[$rowDimension->getXfIndex()]?$map[$rowDimension->getXfIndex()]:0); // code modification
}
}
// for all column dimensions
foreach ($sheet->getColumnDimensions() as $columnDimension) {
$columnDimension->setXfIndex($map[$columnDimension->getXfIndex()]?$map[$columnDimension->getXfIndex()]:0); // code modification
}
// also do garbage collection for all the sheets
$sheet->garbageCollect();
}
// other_code after 1420 line