简体   繁体   中英

Extracting data from excel file sheet by sheet. Simplexlsx

i am working with excel file with simplexlsx class and my input excel file will have multiple sheets in it.

<?php
require "simplexlsx.php";

if ( $xlsx = @SimpleXLSX::parse("test.xlsx") ) {

    print_r( $xlsx->rows(1) ); // Sheet numeration started 0, we select second worksheet

    foreach ( $xlsx->rows() as $r => $row ) {
        print_r($row);
        echo "<br>";
    }
}else{
    echo SimpleXLSX::parseError();
}


?>

what i am trying is to read the data from excel file sheet by sheet.

i want a way to know the number of sheets in the excel and select the sheet for data processing.

<?php
require "simplexlsx.php";

if ( $xlsx = @SimpleXLSX::parse("test.xlsx") ) {


    // Sheet numeration started 0, we select second worksheet
    $sheets=$xlsx->sheetNames(); 

    foreach($sheets as $index => $name){
        echo "Reading sheet :".$name."<br>";
        foreach ( $xlsx->rows($index) as $r => $row ) {
            print_r($row);
            echo "<br>";
        }
        echo "<hr>";
    }

}else{
    echo SimpleXLSX::parseError();
}


?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM