I have a script that reads a xls file and turns it into a mysql insert statement that works great.
The problem is that the person I am gettign the data from will only send it in xlsx format. My script wont read that file type.
Is there something that will read an xlsx file and return an insert command like this?
include 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CPa25a');
$data->read('upload/file.xls');
//columns:
$sql = "INSERT INTO `test` (";
for ($j = 2; $j <= $data->sheets[0]['numCols']; $j++)
{
$sql .= "`" . mysql_escape_string($data->sheets[0]['cells'][1][$j]) . "`,";
}
$sql = substr($sql, 0, -1) . ") VALUES\r\n";
//cells
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++)
{
$sql .= "(";
for ($j = 2; $j <= $data->sheets[0]['numCols']; $j++)
{
$sql .= "'" . mysql_escape_string($data->sheets[0]['cells'][$i][$j]) . "',";
}
$sql = substr($sql, 0, -1) . "),\r\n";
}
$sql = substr($sql, 0, -3) . ";";
echo '<pre>';
echo $sql;