Home > Backend Development > PHP Tutorial > Import and export EXCEL files to the database on the WEB page_PHP tutorial

Import and export EXCEL files to the database on the WEB page_PHP tutorial

WBOY
Release: 2016-07-13 17:26:07
Original
1241 people have browsed it

Due to work needs, the author needs to import the contents of the EXCEL file into the database in the OA system, and at the same time, export the contents of the database to the EXCEL file. The author's OA was developed in PHP and applied on WEB pages, so it is difficult to process it directly in PHP. After research, the author developed an ACTIVEX control using DELPHI to process the data of EXCEL files, then submitted the data to the server and then saved it to the database, easily realizing the import of EXCEL file data. The export does not use the ACTIVEX control and is processed directly with PHP. The method is to directly generate the data into a CSV file. Because CSV is a comma-delimited text file and can be opened and processed directly with EXCEL, it can meet the requirements. The implementation method will be introduced below. Imported page code: "Personnel Number", "FIELDNAME"=>"STUFFID", "FIELDTYPE"=>"A"), array ("CAPTION"=>"Start Date", "FIELDNAME"=>"BEGINDATE", "FIELDTYPE"=>"A"), array ("CAPTION"=>"EndDate", "FIELDNAME"=>"ENDDATE", "FIELDTYPE"=>"A"), array ("CAPTION"=>"Contract Content", "FIELDNAME"=>"CONTRACTTEXT", "FIELDTYPE"=>"A"), array ("CAPTION"=>"Remarks", "FIELDNAME"=>"THISMEMO", "FIELDTYPE"=>"A" ), array ("CAPTION"=>"Server file name", "FIELDNAME"=>"DOCFILE", "FIELDTYPE"=>"A"), array ("CAPTION"=>"File type", "FIELDNAME"= >"FILETYPE", "FIELDTYPE"=>"A"), array ("CAPTION"=>"Local file name", "FIELDNAME"=>"FILENAME", "FIELDTYPE"=>"A"), array (" CAPTION"=>"File extension", "FIELDNAME"=>"EXTNAME", "FIELDTYPE"=>"A")); //Construct SQL statement, field name part $strSQL = "INSERT INTO HR_WORKCONTRACT ("; $ strTemp = ""; for ($i = 0; $i ExecSQL ($strSQL.$strTmp)) $do->SetObject ("ERR", "Data import failed!"); else $do->SetObject ("ERR ", "Data imported successfully! "); //echo $strSQL.$strTmp; $strTmp = ""; } } } if (trim ($strTmp) != "") { $strTmp = substr ($strTmp, 0 , strlen ($strTmp) - 2).";"; if (!$do->ExecSQL ($strSQL.$strTmp)) $do->SetObject ("ERR", "Data import failed! "); else $do->SetObject ("ERR", "Data import successful!");//echo $strSQL.$strTmp; } }?>The page for importing labor contract information and importing data is as follows: The imported EXCEL file can be displayed All content, and you can manually select the data to be imported, and you can temporarily modify the data (the modified data is displayed in red to show the difference). You can select EXCEL files on the local hard disk, including XLS. Both file and CSV formats

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531993.htmlTechArticleDue to work needs, the author needs to import the contents of the EXCEL file into the database in the OA system, and also needs Export the contents of the database to an EXCEL file. The author's OA uses P...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template