【问题标题】:Custom Data send from excel file to .csv file in PHP自定义数据从 excel 文件发送到 PHP 中的 .csv 文件
【发布时间】:2019-11-29 00:29:07
【问题描述】:

我在一个 Excel 文件中有 600 000 个数据。我想将前 30 个数据发送到一个 csv 文件,然后将另外 30 个数据发送到另一个 csv 文件,并且只要有 600 000 个数据发送到 csv 文件,它就会继续。我如何使用 php 代码做到这一点?

注意:完成此过程后,我想要 20 000 个 csv 文件,其中包含 600 000 个连续数据。

【问题讨论】:

  • 那么,为了澄清你想将一个 600,000 行的文件拆分为每个 30 行的文件?
  • 是的,有什么解决办法吗?
  • 我会添加一个答案。原文件的扩展名是什么?
  • 现在我有 600,000 行的 .xlsx 文件。我想要 20,000 个 .csv 文件,每 30 行。

标签: php export-to-csv


【解决方案1】:

考虑使用为此类工作构建的box/spout 库。

$reader = ReaderEntityFactory::createReaderFromFile('/path/to/file.xlsx');

foreach ($reader->getSheetIterator() as $sheet) {
    if ($sheet->getIndex() === 0) {
        foreach ($sheet->getRowIterator() as $row) {
            // write CSV files
        }
        break; // no need to read more sheets
    }
}


$reader->close();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    相关资源
    最近更新 更多