将大型Excel / Csv文件拆分为PHP或Javascript上的多个文件 [英] Split large Excel/Csv file to multiple files on PHP or Javascript

查看:448
本文介绍了将大型Excel / Csv文件拆分为PHP或Javascript上的多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有excel(file.xls)/ csv(file.csv)文件,包含/将包含成千上万的条目,甚至几百万我猜。是否有可能将这一个拆分为多个文件?像file.xls到file1.xls,file2.xls,file3.xls等。

I have excel(file.xls)/csv(file.csv) file that contains/will contain hundreds of thousands of entry, even millions I guess. Is it possible to split this one to multiple file? Like file.xls to file1.xls, file2.xls, file3.xls and so on.

有没有任何库要使用?这是可能在PHP吗?或者如何javascript?
在哪里可以指定每个文件中包含多少行?

Are there any libraries to use? Is this possible on PHP? or how about javascript? On where I can specify how many rows to be included on each file?

感谢

推荐答案

将CSV文件拆分为多个CSV文件的快捷方式

Quick and dirty way of splitting a CSV file into several CSV files

$inputFile = 'input.csv';
$outputFile = 'output';

$splitSize = 10000;

$in = fopen($inputFile, 'r');

$rowCount = 0;
$fileCount = 1;
while (!feof($in)) {
    if (($rowCount % $splitSize) == 0) {
        if ($rowCount > 0) {
            fclose($out);
        }
        $out = fopen($outputFile . $fileCount++ . '.csv', 'w');
    }
    $data = fgetcsv($in);
    if ($data)
        fputcsv($out, $data);
    $rowCount++;
}

fclose($out);

这篇关于将大型Excel / Csv文件拆分为PHP或Javascript上的多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆