Prefixe seu problema com um dos seguintes: [BUG] [PROPOSAL] [QUESTION].
Olá, @kurianic , o exemplo abaixo lerá todas as planilhas das pastas de trabalho A e B e as copiará para uma nova pasta de trabalho C. Certifique-se de que A e B não contenham planilhas com o mesmo nome.
// Load the workbooks to merge in a collection.
// This example is assuming they're stored in the Laravel storage folder.
$workbooks = collect([
'workbookA.xlsx',
'workbookB.xlsx',
])->map(function ($filename) {
return Excel::load(storage_path($filename));
});
// Create merged workbook
$workbookC = Excel::create('workbookC', function ($excel) use ($workbooks) {
// For each workbook to be merged
$workbooks->each(function ($workbook) use ($excel) {
// Get all the sheets
collect($workbook->getAllSheets())->each(function ($sheet) use ($excel) {
// And add them to the merged workbook
$excel->addExternalSheet($sheet);
});
});
})->save(); // save merged workbook to storage/exports/workbookC.xlsx
Olá @stephanecoinon , quero adicionar a mesma planilha várias vezes, para evitar nomes duplicados, chamei $ sheet-> setTitle. mas me dá um erro "A planilha não existe." quando addExternalSheet chamado logo após setTitle.
$sheet_original->setTitle("SHEET ".$i);
$sheets[$i] = $sheet_original;
$sheets[$i]->cell('I64', function($cell) use($i) { $cell->setValue($i); });
$excel->addExternalSheet($sheets[$i] );
@ sarpkaya-xx tente addSheet()
:
Excel::create('workbook', function ($excel) {
// Create first "original" sheet
$original = $excel->sheet('Sheet 1', function ($sheet) {
$sheet->fromArray([
['foo' => 'bar']
]);
});
// Copy the first sheet 4 times
for ($sheetCount = 2; $sheetCount <= 5; $sheetCount++) {
$copy = $original->getSheet()->copy();
$copy->setTitle("Sheet {$sheetCount}");
$excel->addSheet($copy);
}
})->save();
Comentários muito úteis
@ sarpkaya-xx tente
addSheet()
: