web export excel format problem

When we import the data on the web page into 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 the principle of excel exporting from web pages. When we send this data to the client, we want the client program (browser) to read it in excel format, so set the mime type to: application/vnd.ms-excel, when excel reads the file The data will be presented in the format of each cell. If the cell does not have a specified format, excel will present the data of the cell in the default format. This gives us the space to customize the data format, of course we must use the format supported by excel. Some commonly used 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, such as year and month You can define as: yy-mm and so on. So knowing these formats, how to add these formats to the cell? Very simple, we only need to add the style to the corresponding tag pair (ie the closing tag). Such as <td></td>, add styles to the tag pair <td></td>, as follows:

<td style="vnd.ms-excel.numberformat:@">410522198402161833</td>


Similarly, we can also add styles to <div></div>, and we can also add styles to <tr></tr>, <table></table>, which will introduce a problem, have you noticed? First look at the following code:

<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>



Reprinted from: http://www.blogjava.net/Hopes/articles/387669.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326986651&siteId=291194637