When we export the data on the Web page to excel, sometimes our data needs to be presented in a specific format. At this time, we need to add some style specification information to the cell.
First, let's take a look at how Excel exports from a Web page. When we send the data to the client, we want the clientProgram(Browser) read it in Excel format, so set the MIME type to application/vnd. MS-Excel: When an Excel file is read, data is displayed in the format of each cell. If the cell does not have a specified format, Excel displays the data of the cell in the default format. This provides us with a space for custom data formats. Of course, we must use the formats supported by Excel. Common formats are listed below:
1) Text: VND. ms-excel.numberformat :@
2) Date: VND. ms-excel.numberformat: yyyy/mm/dd
3) number: VND. ms-excel.numberformat: #,## 0.00
4) Currency: VND. ms-excel.numberformat: ¥ #, #0.00
5) percentage: VND. ms-excel.numberformat: # 0.00%
You can also customize these formats. For example, you can define the year and month as YY-mm. So how can I add these formats to cells when I know these formats? It is very simple. We only need to add the style to the corresponding tag pair (that is, to close the tag. For example, <TD> </TD>, add a style to <TD> </TD> as follows:
[HTML]
View plain
Copy
Print
?
- <TD Style="Vnd. ms-excel.numberformat :@">410522198402161833</TD>
<TD style = "Vnd. ms-excel.numberformat: @"> 410522198402161833 </TD>
Similarly, we can also<Div> </div>To add a style, you can also<Tr> </tr>,<Table> </table>Adding a style will introduce a problem. Do you notice this? First look at the followingCode:
[HTML]
View plain
Copy
Print
?
-
- <Table Style= 'Vnd. ms-excel.numberformat: #,## 0.00'>
-
- <Tr>
-
- <TD>542</TD>
- <TD Style= 'Vnd. ms-excel.numberformat: #8080'>0.25</TD>
-
- </Tr>
-
- </Table>
<Table Style = 'vnd. ms-excel.numberformat: #, #0.00 '> <tr> <TD> 542 </TD> <TD style = 'vnd. ms-excel.numberformat: # 0.00% '> 0.25 </TD> </tr> </table>
Yes. When we add a style to both the parent tag pair and the Child tag pair, which style will the data be presented in? After testing, it will be presented in the style closest to the data, which is also in line with our wishes (it seems that it is also in line with the saying that the county officials are not as competent as they are now ). In this way, we can change the data inExcel(You can add these style specifications on the front-end page or give the corresponding controls in the background code, such:DataGridAnd so on ). If your application is relatively simple, it is enough to meet your needs. However, if your applications are complex, you can also use different data presentation methods. Next, let's look at an application that is a little more complex.
For example, if your data is to be presented to users in different countries and regions, the data format will be different. How can we solve this problem? Of course, you can process these data manually, but this is not the best method, because if we add users from other countries or regions, then we need to process all the data in the format requested by the customer. When the data volume is large, this is undoubtedly a heavy and boring job. So how should we solve such problems? Next, let me share my opinion: extract the formatted Information toXMLFile, when the program is running, it reads different formatting information according to different customers, and then dynamically adds the formatting information to our data. In this way, when we add users in other countries or regions, we only need to add one moreXMLFile to write the corresponding formatting information to thisXMLFile, and then when users in this country or region view it, they can read the corresponding formatted Information and apply it to the data.
The above example is a sudden thought of. I believe that multinational corporations will encounter similar problems. The solution is just to provide you with an idea, hoping that the results will be helpful.