Laravel-excel: كيف يمكنني دمج ملفي xlsx وتنزيل الملف المدمج؟

تم إنشاؤها على ٩ أكتوبر ٢٠١٧  ·  3تعليقات  ·  مصدر: Maatwebsite/Laravel-Excel

الرجاء إنشاء بادئة بين مشكلتك بواحد مما يلي: [BUG] [اقتراح] [سؤال].

إصدار الحزمة ، إصدار Laravel

سلوك متوقع

السلوك الفعلي

تتبع مكدس الاستثناء

لقطة شاشة لملف Excel

خطوات إعادة إنتاج السلوك

التعليق الأكثر فائدة

@ sarpkaya-xx جرب 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();

ال 3 كومينتر

مرحبًا kurianic ،

// 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

مرحبًا stephanecoinon ، أريد إضافة نفس الورقة عدة مرات ، لمنع تكرار الأسماء ، اتصلت بـ $ sheet-> setTitle. لكنه يعطيني خطأ "الورقة غير موجودة". عندما يتم استدعاء addExternalSheet بعد 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 جرب 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();
هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات