<style>
.xlsText{mso-style-parent:style0;mso-number-format:"\@";} /* 設定儲存格類型為文本*/
</style>
<%
response.ContentType="application/vnd.ms-excel" '設定網頁輸出類型為:Excel
%>
<table>
<tr>
<td>欄位1</td>
<td>欄位2</td>
<td>欄位3</td>
<td>欄位4</td>
</tr>
<tr>
<td class="xlsText"><%= 欄位1的值 %></td> <!--該儲存格為文字格式設定-->
<td class="xlsText"><%= 欄位2的值 %></td> <!--該儲存格為文字格式設定-->
<td><%= 欄位3的值 %></td>
<td><%= 欄位4的值 %></td>
</tr>
</table>
mso-number-format:"0" NO Decimals
mso-number-format:"0\.000" 3 Decimals
mso-number-format:"\#\,\#\#0\.000" Comma with 3 dec
mso-number-format:"mm\/dd\/yy" Date7
mso-number-format:"mmmm\ d\,\ yyyy" Date9
mso-number-format:"m\/d\/yy\ h\:mm\ AM\/PM" D -T AMPM
mso-number-format:"Short Date" 01/03/1998
mso-number-format:"Medium Date" 01-mar-98
mso-number-format:"d\-mmm\-yyyy" 01-mar-1998
mso-number-format:"Short Time" 5:16
mso-number-format:"Medium Time" 5:16 am
mso-number-format:"Long Time" 5:16:21:00
mso-number-format:"Percent" Percent - two decimals
mso-number-format:"0%" Percent - no decimals
mso-number-format:"0\.E+00" Scientific Notation
mso-number-format:"\@" Text
mso-number-format:"\#\ ???\/???" Fractions - up to 3 digits (312/943)
mso-number-format:"\0022£\0022\#\,\#\#0\.00" £12.76
mso-number-format:"\#\,\#\#0\.00_ \;\\-\#\,\#\#0\.00\ " 2 decimals, negative numbers in red and signed
(1.56 -1.56)
用法舉例:
當我們用<%@page contentType="application/vnd.ms-excel; charset=UTF-8"%>的方法匯出jsp檔案為excel時,如果匯出的資料中有數字以0開頭,則該0會被省略,為了保留這個處於首位的0,可以在表格的style中加入:
style='mso-number-format:"\@";'
這樣的話,匯出的該表格中首位為0的數字就會將該0保留啦!