import Excel
Inviato: 09 apr 2019, 16:46
Salve, premetto che sono alle prime esperienze con scriptcase.
ho creato un applicazione di controllo per delle importazioni massive da xls,
tutto funziona regolarmente ad eccezione de campi data,
potete darmi indicazioni in merito ?
questo il codice usato
on onScriptInit
require_once('../../../..'.$this->Ini->path_prod.'/third/phpexcel/PHPExcel.php');
require_once('../../../..'.$this->Ini->path_prod.'/third/phpexcel/PHPExcel/IOFactory.php');
onValidateSuccess
$fileXlsX = explode('.',$this->xls_input_ul_name);
$tabella = {tabella};
if($fileXlsX[1]=='xlsx'){
//xlsx
$inputFileName = "../../../tmp/".$this->xls_input_ul_name;
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
$worksheetData = $objReader->listWorksheetInfo("../../../tmp/".$this->xls_input_ul_name);
$totalRows = $worksheetData[0]['totalRows'];
$totalColumns = $worksheetData[0]['totalColumns'];
$lastColumn = $objPHPExcel->getActiveSheet()->getHighestColumn();
$sheet = $objPHPExcel->getSheet(0);
$columnNames="";
$rowDate ="";
for($colum=0;$colum<$totalColumns;$colum++){
if($colum==$totalColumns-1){
$columnNames.= utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, 1)->getValue());
}else{
$columnNames.= utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, 1)->getValue()).",";
}
}
for ($row = 2; $row <= $totalRows; $row++){
for($colum=0;$colum<$totalColumns;$colum++){
if($colum==$totalColumns-1){
$rowDate .= "'".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, $row)->getValue())."'";
}else{
$rowDate .= "'".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, $row)->getValue())."',";
}
}
sc_exec_sql("INSERT INTO $tabella (".$columnNames.") VALUES (".$rowDate.")");
$rowDate="";
}
}else{
//xls
$objReader = new PHPExcel_Reader_Excel5();
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("../../../tmp/".$this->xls_input_ul_name);
$worksheetData = $objReader->listWorksheetInfo("../../../tmp/".$this->xls_input_ul_name);
$totalRows = $worksheetData[0]['totalRows'];
$totalColumns = $worksheetData[0]['totalColumns'];
$lastColumn = $objPHPExcel->getActiveSheet()->getHighestColumn();
$sheet = $objPHPExcel->getSheet(0);
$columnNames="";
$rowDate ="";
for($colum=0;$colum<$totalColumns;$colum++){
if($colum==$totalColumns-1){
$columnNames.= utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, 1)->getValue());
}else{
$columnNames.= utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, 1)->getValue()).",";
}
}
for ($row = 2; $row <= $totalRows; $row++){
for($colum=0;$colum<$totalColumns;$colum++){
if($colum==$totalColumns-1){
$rowDate .= "'".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, $row)->getValue())."'";
}else{
$rowDate .= "'".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, $row)->getValue())."',";
}
}
sc_exec_sql("INSERT INTO $tabella (".$columnNames.") VALUES (".$rowDate.")");
$rowDate="";
}
}
sc_alert("Dati importati con successo");
ho creato un applicazione di controllo per delle importazioni massive da xls,
tutto funziona regolarmente ad eccezione de campi data,
potete darmi indicazioni in merito ?
questo il codice usato
on onScriptInit
require_once('../../../..'.$this->Ini->path_prod.'/third/phpexcel/PHPExcel.php');
require_once('../../../..'.$this->Ini->path_prod.'/third/phpexcel/PHPExcel/IOFactory.php');
onValidateSuccess
$fileXlsX = explode('.',$this->xls_input_ul_name);
$tabella = {tabella};
if($fileXlsX[1]=='xlsx'){
//xlsx
$inputFileName = "../../../tmp/".$this->xls_input_ul_name;
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
$worksheetData = $objReader->listWorksheetInfo("../../../tmp/".$this->xls_input_ul_name);
$totalRows = $worksheetData[0]['totalRows'];
$totalColumns = $worksheetData[0]['totalColumns'];
$lastColumn = $objPHPExcel->getActiveSheet()->getHighestColumn();
$sheet = $objPHPExcel->getSheet(0);
$columnNames="";
$rowDate ="";
for($colum=0;$colum<$totalColumns;$colum++){
if($colum==$totalColumns-1){
$columnNames.= utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, 1)->getValue());
}else{
$columnNames.= utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, 1)->getValue()).",";
}
}
for ($row = 2; $row <= $totalRows; $row++){
for($colum=0;$colum<$totalColumns;$colum++){
if($colum==$totalColumns-1){
$rowDate .= "'".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, $row)->getValue())."'";
}else{
$rowDate .= "'".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, $row)->getValue())."',";
}
}
sc_exec_sql("INSERT INTO $tabella (".$columnNames.") VALUES (".$rowDate.")");
$rowDate="";
}
}else{
//xls
$objReader = new PHPExcel_Reader_Excel5();
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("../../../tmp/".$this->xls_input_ul_name);
$worksheetData = $objReader->listWorksheetInfo("../../../tmp/".$this->xls_input_ul_name);
$totalRows = $worksheetData[0]['totalRows'];
$totalColumns = $worksheetData[0]['totalColumns'];
$lastColumn = $objPHPExcel->getActiveSheet()->getHighestColumn();
$sheet = $objPHPExcel->getSheet(0);
$columnNames="";
$rowDate ="";
for($colum=0;$colum<$totalColumns;$colum++){
if($colum==$totalColumns-1){
$columnNames.= utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, 1)->getValue());
}else{
$columnNames.= utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, 1)->getValue()).",";
}
}
for ($row = 2; $row <= $totalRows; $row++){
for($colum=0;$colum<$totalColumns;$colum++){
if($colum==$totalColumns-1){
$rowDate .= "'".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, $row)->getValue())."'";
}else{
$rowDate .= "'".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($colum, $row)->getValue())."',";
}
}
sc_exec_sql("INSERT INTO $tabella (".$columnNames.") VALUES (".$rowDate.")");
$rowDate="";
}
}
sc_alert("Dati importati con successo");