Some time ago we talked about importing Excel files into a database, and today we're going to look at another common feature of PHPEXECL--exporting Excel. This function has troubled many beginners, so through this study, I believe that the next time you meet this situation, it is very easy to deal with, the following to share the process.
As always, the first step, import phpexcel extension, this article takes TP3.1.3 as an example to introduce, import location such as:
Other versions of the development are deployed according to the documentation. The second step: introduced in the controller, the introduction method is as follows:
Here is the introduction of operations, for reference only, in short, the phpexcel.php and phpexecl directory inside some PHP files. By the way, the column is simply processed to facilitate the next write operation. If it is a Chinese file name, add: $fileName = Iconv ("Utf-8", "gb2312", $fileName), processing the file name to prevent errors.
Step three: Write the data using the methods provided by the Phpexcel class.
The attentive reunion asked: Where did $data come from, here to illustrate, $data is passed through the method parameters.
is a third parameter. Last step: Process the table and download the file.
Now, let's make a formal use of the method we just wrote:
From the foreground template gives a tag href attribute call this method, click on it. The downloaded file is the Excel file we want. So now you know how the concrete is to achieve it, if there are doubts, you can leave a message to consult, we discuss the study together.
This article by the Professional Zhengzhou app development company Brigitte Xuan Science and Technology finishing release, original is not easy, if need reprint please indicate source.
The concrete implementation method of exporting excel in PHP programming technology