Kaleem Nalband
Kaleem Nalband

Reputation: 697

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.

Upvotes: 1

Views: 4960

Answers (1)

Kaleem Nalband
Kaleem Nalband

Reputation: 697

<?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();
}


?>

Upvotes: 4

Related Questions