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

Source: Internet
Author: User
Due to work requirements, in the OA system, the content of the EXCEL file needs to be imported into the database, and the content in the database needs to be exported to the EXCEL file. The author's OA is developed in PHP and used on the web page, so the author directly uses P to import the content of the EXCEL file into the database in the OA system due to work needs, you also need to export the database content to an EXCEL file. My OA was developed using PHP and used on the web page. Therefore, it is more difficult to directly use PHP for processing. After research, I developed an ACTIVEX control using DELPHI to process the EXCEL file data, submit the data to the server, and then save it to the database, easy Import of 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 for processing, so the request can be met. The following describes the implementation methods. Code of the imported page: 'Employee 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' => 'tracttext', 'fieldtype' => 'A '), array ('Caption '=> 'note', 'fieldname' => 'thismemo', 'fieldtype' => 'A '), array ('Caption '=> 'Server filename', 'fieldname' => 'docfile ', 'fieldt YPE '=> 'A'), array ('Caption' => 'File type', 'fieldname' => 'filetype', 'fieldtype' => 'A '), array ('Caption '=> 'Local FILENAME', 'fieldname' => 'filename', 'fieldtype' => 'A '), array ('Caption '=> 'File extended name', 'fieldname' => 'extname', 'fieldtype' => 'A'); // Structure 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 data import page for the labor contract information: all the content imported into the EXCEL file is displayed, and you can manually select the data to import, temporary correction can be performed on the data (after correction, the data is displayed in red to show the difference ). Select a file. You can select an EXCEL file on the local hard disk, which contains two formats: XLS file and CSV file.

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.