Laravel-excel: Como posso mesclar dois arquivos xlsx e baixar o combinado?

Criado em 9 out. 2017  ·  3Comentários  ·  Fonte: Maatwebsite/Laravel-Excel

Prefixe seu problema com um dos seguintes: [BUG] [PROPOSAL] [QUESTION].

Versão do pacote, versão do Laravel

Comportamento esperado

Comportamento real

Rastreamento de pilha de exceção

Captura de tela do arquivo Excel

Passos para reproduzir o comportamento

Comentários muito úteis

@ 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();

Todos 3 comentários

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();
Esta página foi útil?
0 / 5 - 0 avaliações

Questões relacionadas

amine8ghandi8amine picture amine8ghandi8amine  ·  3Comentários

kevinRR picture kevinRR  ·  3Comentários

bahmanyaghoobi picture bahmanyaghoobi  ·  3Comentários

contifico picture contifico  ·  3Comentários

pamekar picture pamekar  ·  3Comentários