Macos 获取XLSX文件的行数

Macos 获取XLSX文件的行数,macos,xls,xlsx,Macos,Xls,Xlsx,我想创建计算机上所有.xlsx文件及其行数的列表 获取每个.xlsx文件中的行数的最佳方法是什么?我在Mac OSX Yosemite上(如果相关的话)。答案可以是任何语言 您可以使用PHP和Spout()来实现。 代码如下所示: use Box\Spout\Reader\ReaderFactory; use Box\Spout\Common\Type; // This is the root directory you want to list the XLSX files of // CH

我想创建计算机上所有
.xlsx
文件及其行数的列表


获取每个
.xlsx
文件中的行数的最佳方法是什么?我在Mac OSX Yosemite上(如果相关的话)。答案可以是任何语言

您可以使用PHP和Spout()来实现。 代码如下所示:

use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Common\Type;

// This is the root directory you want to list the XLSX files of
// CHANGE IT !!
$rootPath = '/path/to/root/directory';

// this will read the XLSX file at the given path and return the number of rows for the file
function getNumRows($xlsxPath) {
    $numRows = 0;

    $reader = ReaderFactory::create(Type::XLSX);
    $reader->open($xlsxPath);

    foreach ($reader->getSheetIterator() as $sheet) {
        foreach ($sheet->getRowIterator() as $row) {
            $numRows++;
        }
    }

    $reader->close();

    return $numRows;
}

// This will recursively go through the root folder and all its subfolders
$directoryIterator = new \RecursiveDirectoryIterator($rootPath, RecursiveDirectoryIterator::SKIP_DOTS);
$recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::SELF_FIRST);

foreach ($recursiveIterator as $fileInfo) {
    if (strtolower($fileInfo->getExtension()) === 'xlsx') {
        $xlsxPath = $fileInfo->getPathname();
        $numRows = getNumRows($xlsxPath);
        // store the number of rows for the file somewhere
    }
}

你是德国人吗?;-)你可以使用Java和ApachePOI来读取和计算行数。。。对于ApachePOI。看起来它只支持2007年,知道任何也支持XLSX的东西吗?无法抗拒;-)我使用POI来阅读Word 2010创建的xlsx,这是肯定的。