When jsp exports excel, the problem is that long numbers are displayed in the form of scientific notation?

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 room to customize the data format, of course we must use the format supported by excel. Here are some commonly used formats:

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


view plaincopy to clipboardprint?

<td style="vnd.ms-excel.numberformat:@">410522198402161833</td>  
<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:

 

view plaincopy to clipboardprint?

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

 

Guess you like

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