Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all articles
Browse latest Browse all 2707

New Post: Date imported as input mask, not as value

$
0
0

I'm trying to read data from Excel, and store it in a database.

It doesn't work what you proposed. He hangs on the one line of code:

$phpDateTimeObject = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);

Or 

$phpDateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);

What can I do now? This is my code:

include('excel_reader2.php');
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');
$data->read($file);

$sql= "INSERT INTO table (xx,xxx,xxx,...) VALUES ";

for ($x = 2; $x <= count($data->sheets[0]["cells"]); $x++) 
{
	$sql .= "(";
	for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
	{
		if($j==4 || $j==16 || $j==17 || $j==21 || $j==22) 
		{//cell with date
			$excelDateValue = $data->sheets[0]['cells'][$x][$j];
			$phpDateTimeObject = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
			$sql .= date('Y-m-d', $phpDateTimeObject);
		}
		else
		{
			$sql .= "'" . mysql_escape_string($data->sheets[0]['cells'][$x][$j]) . "',";
		}
	}
	$sql = substr($sql, 0, -1) . "),";
}	
$sql =  substr($sql, 0, -1);

 

When I just try to echo the query ($sql), at the end of this code, nothing happens...


Viewing all articles
Browse latest Browse all 2707

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>