Import and Export EXCEL files to and from the database on the WEB page

Source: Internet
Author: User

Due to my work needs, in the OA system, I need to import the content of the EXCEL file to the database, and export the content in the database to the EXCEL file. The author's OA is developed using PHP and applied on the web page, so it is difficult to directly use PHP for processing. After research, I developed an ACTIVEX Control Using DELPHI to process the EXCEL file data, then submit the data to the server, and save it to the database, this allows you to easily import EXCEL file data. You can use PHP to export data without ACTIVEX controls. The method is to directly generate a CSV file, because CSV is a text file separated by commas, and can be opened directly in EXCEL, so it can meet the requirements. The following describes the implementation methods. Code of the imported page: "personnel number", "FIELDNAME" => "STUFFID", "FIELDTYPE" => ""), array ("CAPTION" => "Start Date", "FIELDNAME" => "BEGINDATE", "FIELDTYPE" => ""), array ("CAPTION" => "end date", "FIELDNAME" => "ENDDATE", "FIELDTYPE" => ""), array ("CAPTION" => "contract content", "FIELDNAME" => "CONTRACTTEXT", "FIELDTYPE" => ""), array ("CAPTION" => "Remarks", "FIELDNAME" => "THISMEMO", "FIELDTYPE" => ""), array ("CAPTION" => "Server File Name", "FIELDNAME" => "DOCFILE", "FIELDT YPE "=>" A "), array (" CAPTION "=>" file type "," FIELDNAME "=>" FILETYPE "," FIELDTYPE "=>" "), array ("CAPTION" => "local file name", "FIELDNAME" => "FILENAME", "FIELDTYPE" => ""), array ("CAPTION" => "file extension", "FIELDNAME" => "EXTNAME", "FIELDTYPE" => "A"); // construct an SQL statement, field name section $ 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 imported successfully! "); // Echo $ strSQL. $ strTmp ;}}?> The following figure shows the page for importing the labor contract information: all the content of the imported EXCEL file is displayed, and the data to be imported can be selected manually, you can modify the data temporarily (after the modification, the data is displayed in red to show the difference ). Select a file. You can select EXCEL files on the local hard disk, including XLS files and CSV files.

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.