Import and export Excel files to a database on a Web page

Source: Internet
Author: User
Tags date array
excel|web| Data | database | Page I because of the needs of the work, in the OA system, you need to import the contents of the Excel file into the database, but also need to export the contents of the database to Excel files. The author of OA is developed with PHP, and applied to the Web page, so the direct use of PHP to deal with a larger difficulty. After research, the author developed an ActiveX control with Delphi to process the data of Excel files, then submit the data to the server, then save to the database, easy to realize the import of Excel file data. The export does not use ActiveX controls and is processed directly in PHP.  The method is to generate the data directly into the CSV file, because CSV is a comma-delimited text file and can be opened directly with Excel, so you can meet your requirements. Here's how to implement this. Imported page code: "Personnel Number", "FIELDNAME" => "Stuffid", "FieldType" => "A"), Array ("CAPTION" => "Start Date", "FIELDNAME" => " Begindate "," FieldType "=>" a "), Array (" CAPTION "=>" End Date "," FIELDNAME "=>" EndDate "," FieldType "=>" A "), Array ("CAPTION" => "Contract content", "FIELDNAME" => "Contracttext", "FieldType" => "A"), Array ("CAPTION" => "Remarks", " FIELDNAME "=>" "Thismemo", "FieldType" => "A"), Array ("CAPTION" => "Server filename", "FIELDNAME" => "Docfile", " FieldType "=>"), Array ("CAPTION" => "file Type", "FIELDNAME" => "FILETYPE", "FieldType" => "a"), Array ("CAPTION" => "Local filename", "FIELDNAME" => "filename", "FieldType" => "A"), Array ("CAPTION" => "file name extension", "FIELDNAME" => " Extname "," fieldtype "=> "A")); Constructs the SQL statement, the field name part $strSQL = "Inserts into Hr_workcontract ("; $strTemp = ""; for ($i = 0; $i execsql ($strSQL. $strTmp)) $do->setobject ("ERR", "Data import failed!") "); else $do->setobject ("ERR", "Data import success!") "); 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 success!") ");//echo $strSQL. $strTmp}}?  > Labor Contract Information Import the page to import data as follows: You can display all the contents of an imported Excel file, and you can manually select the data you want to import, and you can temporarily modify the data (the data is displayed in red color to make a difference). Select the file interface. You can select Excel files on your local hard disk, including XLS files and CSV two formats.

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.