In actual work projects, it is often necessary to export data stored in some important databases into Excel, such as exporting attendance reports and exporting financial statements. Export performance reports, export sales reports, etc. CleverCode used PHPExcel for two years to create Excel export data, but found that it was too troublesome to use PHPExcel to generate Excel, especially controlling the color of cells, merging cells, setting lengths for cells, etc. It usually takes a day to design one of these in Excel. Later, CleverCode discovered a simple method to export Excel in xml format using PHP. It used to take a day's work, but now it can be done in half an hour. It's really twice the result with half the effort!
At the same time, some projects also need to import some Excel data into the database. For example, the bank statements provided by the bank and the sales reports are imported into the database. The usual approach is to use PHPExcel.
Although you can use Xml parser, SimpleXML, XMLReader, DOMDocument and other methods to read Excel in xml format, CleverCode has tried to use these methods and found that they are too complicated and laborious, and are not as useful as PHPExcel.
So when you need to read Excel (including xml format), CleverCode recommends using the PHPExcel library.
A certain group needs the person in charge of each region to import the orders and sales of the city stations they are responsible for into the database.
1) The website provides an imported sales report template.
2) Each person in charge can only upload and download data for the city they are responsible for (permission check).
3) Only upload to generate all quarters owned by the current year and that day. For example, today is 2015-05-26. Then only the first quarter and second quarter of 2015 are generated.
If it is 2015-12-01. You need to generate the first, second, third and fourth quarter of 2015.
4) Display the data of previous quarters of this quarter.
5) The data for this quarter are all 0 by default.
6) Only the data for this quarter can be modified.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
1) Create a new [sales report.xlsx]. The design is as follows.
2) Save the [Sales Report.xlsx] file as [Sales Report.xml]
#3) Open [Sales Report.xml] to see the data in xml format.
4) Find table information. Delete ss:ExpandedColumnCount="5" ss:ExpandedRowCount="6". This restriction limits the length and width of the table, so it must be removed.
1 2 3 |
|
Change to
1 2 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
3) PHP imported Excel client code (import.php)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
The above is the detailed content of How to import and export data in php with Excel graphics and text code sharing in xml format. For more information, please follow other related articles on the PHP Chinese website!