I’m using php and I used the simplexlsx.class to read an excel file. I can get all the values per row. However, I don’t know how to get the values per cell so that I can save those values in a database.
I tried the following code to print the values per cell. But this is just for printing.
for($j=1; $j <= $xlsx->sheetsCount();$j++){
echo '<pre>';
print_r( $xlsx->rowsEx($j) );
echo '</pre>';
}
The $xlsx->rowsEx($j) is in an array form [name, value, href]. I am only interested with the value. Here’s the code in simplexlsx.class for rowsEx.
function rowsEx( $worksheet_id = 1 ) {
$rows = array();
$curR = 0;
if (($ws = $this->worksheet( $worksheet_id)) === false)
return false;
foreach ($ws->sheetData->row as $row) {
foreach ($row->c as $c) {
list($curC,) = $this->_columnIndex((string) $c['r']);
$rows[ $curR ][ $curC ] = array(
'name' => (string) $c['r'],
'value' => $this->value($c),
'href' => $this->href( $c ),
);
}
$curR++;
}
return $rows;
}
How should I get the value? Your help would be very much appreciated. Thank you.
The code should read the cells and insert it to the database. You can uncomment the
var_dumpline if you which to see what is inside$r. Please note that the code does not check that the data is safe to insert in a database.