Import and export Excel files to a database in a Web page _php tutorial

Source: Internet
Author: User
In the OA system, I need to import the contents of Excel file into the database, and also need to export the contents of the database to Excel file. The author's OA is developed with PHP, and applied to the Web page, so it is more difficult to deal with PHP directly. After research, the author uses Delphi to develop an ActiveX control, to process the data of Excel file, then submit the data to the server, and then save to the database, easy to implement the import of Excel file data. The export is not used with ActiveX controls and is processed directly with PHP.  The method is to generate the CSV file directly, because CSV is a comma-delimited text file and can be opened directly in Excel, so you can meet the requirements. Here's how to implement this. Imported page code: "Personnel Number", "FIELDNAME" = "Stuffid", "FieldType" and "A", Array ("CAPTION" = "Start Date", "FIELDNAME" and "=" Begindate "," fieldtype "=" a "), Array (" CAPTION "and" End Date "," FIELDNAME "and" ENDDATE "," FieldType "and" a "), Array ("CAPTION" = "Contract contents", "FIELDNAME" and "Contracttext", "FieldType" and "A"), Array ("CAPTION" = "Remarks", " FIELDNAME "+", "Thismemo", "FieldType" and "A", Array ("CAPTION" + "Server file name", "FIELDNAME" and "Docfile", " FieldType "=" a "), Array (" CAPTION "=" File Type "," FIELDNAME "=" FILETYPE "," FieldType "and" a "), Array (" CAPTION " = = "Local filename", "FIELDNAME" = "filename", "FieldType" and "A"), Array ("CAPTION" = "file extension", "FIELDNAME" and "=" Extname "," fieldtype "=" A "); Constructs the SQL statement, the wordSegment 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 import succeeded!") "); 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 succeeded!") ");//echo $strSQL. $strTmp;}}?  > Labor Contract Information Import the Import data page as follows: You can display all the contents of the imported Excel file, and you can manually select the data to import, you can temporarily modify the data processing (after the modified data in red color, to show the difference). Select the file interface. You can select an Excel file on your local hard disk, including the XLS file and CSV two formats.

http://www.bkjia.com/PHPjc/531993.html www.bkjia.com true http://www.bkjia.com/PHPjc/531993.html techarticle in the OA system, I need to import the contents of Excel file into the database, and also need to export the contents of the database to Excel file. The author's OA is with P ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.