import an excel file(xls,xlsx) to mysql via php | DaniWeb
1 Year Ago
good evening people,i'm creating an application where i'd like to import and save a list of people in an excel sheet to my database in mysql, using php, And i'd like to modify it through a form using php! Can anyone have an idea or something which will help me to solve my problem? thank you!
I use this for importing. With respect to modifying it in PHP, that's just some standard kitale code that you'll have to write. If the modifications are on a record-by-record basis, then you just populate the form with values from the DB and save the result. If you want to display multiple records in a spreadsheet-like grid, then you should look into JQuery code that can do that.
1
hello, i found out a way to import, using the PHPExcel classes, and i think it may be helpful for other who would like to use it and to modify it in order to make it perfect , here is the code! // here is the function which will help us to call the PHPExcel classe in our pages, you can put it in a file apart. $chemin = '/opt/lampp/htdocs/www/Classes/'; set_include_path(get_include_path() . PATH_SEPARATOR . $chemin);//we specify the path" using linux" function __autoload($classe) { $fichier = str_replace ( '_', DIRECTORY_SEPARATOR, $classe ) . '.php' ; require_once($fichier); } $fichierACharger = 'listeglsi.xlsx';//the worksheets to use $fichierType = PHPExcel_IOFactory::identify($fichierACharger); $objetALire = PHPExcel_IOFactory::createReader($fichierType); $objetALire->setReadDataOnly(true); $objPHPExcel = $objetALire->load($fichierACharger); //echo '<script>alert("le fichier a été chargé avec succes !");</script>'; $feuille = $objPHPExcel->getSheet(0);//we specify the sheet to use $highestRow = $feuille->getHighestRow();//we select all the rows used in the sheet $highestCol = $feuille->getHighestColumn();// we select all the columns used in the sheet $indexCol = PHPExcel_Cell::columnIndexFromString($highestCol);we set an index on the columns //we show the data through a table echo'<table>'."\n"; for($row = 9;$row <= $highestRow;$row++) { echo'<tr>'."\n"; for($col = 1;$col <= $indexCol ;$col++) { $classeur = $feuille->getCellByColumnAndRow($col,$row)->getValue(); echo'<td>'.$classeur.'</td>'."\n"; } echo'</tr>'."\n"; } echo'</table>'."\n"; //connection to the database include("cnx_import_excel.php.inc"); //importing files to the database for($row = 9;$row <= $highestRow;$row++) { $mat = $feuille->getCellByColumnAndRow(1,$row)->getValue(); $noms = $feuille->getCellByColumnAndRow(2,$row)->getValue(); $postPren = $feuille->getCellByColumnAndRow(3,$row)->getValue(); $sexe = $feuille->getCellByColumnAndRow(4,$row)->getValue(); //example of my data base $rqt = "INSERT kitale INTO T_ETUDIANTS (E_ID,E_NOMS,E_PREPOST,E_SEXE)VALUES('$mat','$noms','$postPren','$sexe')"; $accuse = mysql_query($rqt)or die (mysql_error()); } //connection closing mysql_close();
import database(.sql) into mysql using php script 1 reply in the PHP forum
Recently Updated kitale Articles Recommended Join the DaniWeb Community
1 Year Ago
good evening people,i'm creating an application where i'd like to import and save a list of people in an excel sheet to my database in mysql, using php, And i'd like to modify it through a form using php! Can anyone have an idea or something which will help me to solve my problem? thank you!
I use this for importing. With respect to modifying it in PHP, that's just some standard kitale code that you'll have to write. If the modifications are on a record-by-record basis, then you just populate the form with values from the DB and save the result. If you want to display multiple records in a spreadsheet-like grid, then you should look into JQuery code that can do that.
1
hello, i found out a way to import, using the PHPExcel classes, and i think it may be helpful for other who would like to use it and to modify it in order to make it perfect , here is the code! // here is the function which will help us to call the PHPExcel classe in our pages, you can put it in a file apart. $chemin = '/opt/lampp/htdocs/www/Classes/'; set_include_path(get_include_path() . PATH_SEPARATOR . $chemin);//we specify the path" using linux" function __autoload($classe) { $fichier = str_replace ( '_', DIRECTORY_SEPARATOR, $classe ) . '.php' ; require_once($fichier); } $fichierACharger = 'listeglsi.xlsx';//the worksheets to use $fichierType = PHPExcel_IOFactory::identify($fichierACharger); $objetALire = PHPExcel_IOFactory::createReader($fichierType); $objetALire->setReadDataOnly(true); $objPHPExcel = $objetALire->load($fichierACharger); //echo '<script>alert("le fichier a été chargé avec succes !");</script>'; $feuille = $objPHPExcel->getSheet(0);//we specify the sheet to use $highestRow = $feuille->getHighestRow();//we select all the rows used in the sheet $highestCol = $feuille->getHighestColumn();// we select all the columns used in the sheet $indexCol = PHPExcel_Cell::columnIndexFromString($highestCol);we set an index on the columns //we show the data through a table echo'<table>'."\n"; for($row = 9;$row <= $highestRow;$row++) { echo'<tr>'."\n"; for($col = 1;$col <= $indexCol ;$col++) { $classeur = $feuille->getCellByColumnAndRow($col,$row)->getValue(); echo'<td>'.$classeur.'</td>'."\n"; } echo'</tr>'."\n"; } echo'</table>'."\n"; //connection to the database include("cnx_import_excel.php.inc"); //importing files to the database for($row = 9;$row <= $highestRow;$row++) { $mat = $feuille->getCellByColumnAndRow(1,$row)->getValue(); $noms = $feuille->getCellByColumnAndRow(2,$row)->getValue(); $postPren = $feuille->getCellByColumnAndRow(3,$row)->getValue(); $sexe = $feuille->getCellByColumnAndRow(4,$row)->getValue(); //example of my data base $rqt = "INSERT kitale INTO T_ETUDIANTS (E_ID,E_NOMS,E_PREPOST,E_SEXE)VALUES('$mat','$noms','$postPren','$sexe')"; $accuse = mysql_query($rqt)or die (mysql_error()); } //connection closing mysql_close();
import database(.sql) into mysql using php script 1 reply in the PHP forum
Recently Updated kitale Articles Recommended Join the DaniWeb Community
No comments:
Post a Comment