In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
How to import excel data into the background in bulk by DEDE? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!
How does DEDE import excel data to the background in batches?
DEDE batch import excel data into the background article system development tutorial
For some enterprise websites or Taobao guest websites, it is often necessary to import some excel data into the website in batches, which can save time instead of adding data from the background of the website. It has a certain reference value, and interested friends can refer to it.
Recommended study: dream weaving cms
For some corporate websites or Taobao guest websites, it is often necessary to import some excel data into the website in batches to save time instead of entering and adding data from the background of the website. This tutorial is to import excel data into the dream weaving system (dedecms) as an example for batch data import development, assuming that the excel data into the dream weaving master table dede_archives (there are micro-tables and additional tables, here the main table represents these three tables).
The principle of bulk importing excel data: read the data one by one by querying excel, and then import the data into the table through the php program we developed.
Through the above principle, we know that we can import excel data in bulk into two parts, one is to develop a program to read data from excel, and the other is to develop a program to insert the read data into the database table dede_archives.
Development of program for reading data from excel
In fact, this step has been developed for us by a foreigner, who has developed a set of programs specifically for reading excel data tables called PHPExcel class library.
This excel class library also includes some other functions, which are not covered here. You can download them and have a look at them. Here you will only talk about reading excel.
Insert the read data into the main table dede_archives
After reading the data through the classes provided in the PHPExcel class library, this step is to insert the data into the database table, so the development of this tutorial is actually in the development part; the program development that inserts the data read from excel into the main table.
In order to explain conveniently, we call the file that inserts the data in the database table excelinert.php. The following file enters the program development in this file and inserts the read data into the database table.
Principle of inserting data development
1) preparation before development:
Add a header header to the excelinsert.php in order to unify the coding to avoid garbled: header ("Content-type:text/html;charset=utf8")
Introduce the public file common.inc.php of the dream weaving system, why introduce this file? before we insert the database table, the home page should connect to the database of the website, if we do not connect, we will not be able to insert the database data. Note that the path to the imported file should be changed to your own, because I installed the dream weaving system in dedecms, so there is this directory name dedecms in the path, and remove this path if you install it in the root directory.
Set error report, set time zone, set program run time, of course, this run time can not be set, set the class inventory path of the PHPExcel class, and then introduce the IOFactory.php file, which is the most important file. This function is handled through this file. The setting codes are as follows:
This code is all provided in the PHPExcel class, so there is no need to explain it here.
2) develop insert data code:
Indicates that the data named test1 in the excel is inserted through the file excelinert.php, and the data is inserted into the table of the weaving dream database table dede_archvies, column id is 6, where dopost=exdata means to insert the data password, because, if you make a judgment, then anyone can insert the data into your database table, which is very scary, just like a website without a background. Is it very possible that anyone can enter the background of the website? similarly, if you do not add this password, anyone can insert data, which is not safe.
Therefore, before inserting data, we first get the values of typeid, do, and n through the $GET super array, and then compare them to see if we have permission to insert the database. The first judgment should be to determine whether the password is correct. If this is not correct, we will no longer operate downward.
For ease of explanation, the complete code for excelinsert.php development is provided below:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.