在Jsp页面中加上这几句也可以直接将Jsp页面保存为excel
<%@ page contentType="application/msexcel" %>
<!-- 以上这行设定本网页为excel格式的网页 -->
<%
response.setHeader("Content-disposition","inline; filename=test1.xls");
//以上这行设定传送到前端浏览器时的档名为test1.xls
//就是靠这一行,让前端浏览器以为接收到一个excel档
%>
用IE的用户,如果一个html页面有table的话,可以把table导出到excle文件里面,但是经常遇到会把身份证等数字比较长的数据改成科学计数法来显示。很是头疼。 |
<style type="text/css">
<!--
td {
mso-number-format:"\@";
}
-->
</style>
mso-nubber-format的格式用法如下:
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