使用fromArray生成.xlsx文件以获取大量数据

时间:2019-01-29 09:39:16

标签: php php-5.3 symfony-3.4 phpspreadsheet

我需要使用fromArray()在.xlsx文件中写入约111.100行,但出现一个奇怪的错误

我使用phpspreadsheet库

        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
        $columnLetter = 'A';
        foreach ($columnNames as $columnName) {
            // Allow to access AA column if needed and more
            $sheet->setCellValue($columnLetter.'1', $columnName);
            $columnLetter++;
        }
        $i = 2; // Beginning row for active sheet
        $columnLetter = 'A';
        foreach ($columnValues as $columnValue) {
            $sheet->fromArray(array_values($columnValue), NULL, $columnLetter.$i);
            $i++;
            $columnLetter++;
        }
        // Create your Office 2007 Excel (XLSX Format)
        $writer = new Xlsx($spreadsheet);

        // In this case, we want to write the file in the public directory
        // e.g /var/www/project/public/my_first_excel_symfony4.xlsx
        $excelFilepath =  $directory . '/'.$filename.'.xlsx';

        // Create the file
        $writer->save($excelFilepath);     

我得到一个例外:

消息:“无效的单元格坐标AAAA18272”

#code:0   #file:“ ./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php”

能帮我吗?

1 个答案:

答案 0 :(得分:0)

Excel页面有限。限制很大,但仍然有限。这是一个正确的过滤器,因此如果没有空间,则无法编写。 无论如何,您都不应该使用excel页面处理如此大量的数据,您可以尝试将其碎片化为较小的片段,但是数据库应该是处理如此大量信息的方法

相关问题