Я пытаюсь разбить Excel на несколько файлов, как в этом коде Github
Мои данные были разделены, но во всех файлах они имеют одинаковую информацию, а не CHUNK ONE: ЛИНИЯ 1 - 1000, ЧАНК ВТОРОЙ: ЛИНИЯ 1001 - 2000, кто-нибудь может мне помочь?
Ниже мой код:
echo 'Loading file ',pathinfo($inputFilePath,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
/** Create a new Reader of the type defined in $inputFileType **/
$reader = IOFactory::createReader($inputFileType);
/** Define how many rows we want to read for each "chunk" **/
$chunkSize = 50000;
/** Create a new Instance of our Read Filter **/
$chunkFilter = new Chunk();
/** Tell the Reader that we want to use the Read Filter **/
/** and that we want to store it in contiguous rows/columns **/
$reader->setReadFilter($chunkFilter)
->setContiguous(true);
/** Instantiate a new Spreadsheet object manually **/
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
/** Set a sheet index **/
$sheet = 0;
/** Loop to read our worksheet in "chunk size" blocks **/
/** $startRow is set to 2 initially because we always read the headings in row #1 **/
for ($startRow = 2; $startRow <= 200000; $startRow += $chunkSize) {
// Tell the Read Filter, the limits on which rows we want to read this iteration
$chunkFilter->setRows($startRow, $chunkSize);
// Increment the worksheet index pointer for the Reader
$reader->setSheetIndex($sheet);
// Load only the rows that match our filter into a new worksheet in the PhpSpreadsheet Object
$reader->loadIntoExisting($inputFilePath, $spreadsheet);
// Set the worksheet title (to reference the "sheet" of data that we've loaded)
// and increment the sheet index as well
$spreadsheet->getActiveSheet()->setTitle('Country Data #' . (++$sheet));
}
$loadedSheetNames = $spreadsheet->getSheetNames();
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true);
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Csv($spreadsheet);
$writer->save($_SERVER['DOCUMENT_ROOT'] . "/cabledet_att/" .$loadedSheetName. '.csv');
echo($loadedSheetName);
echo("<br>");
}