`

jsp 导出excel(利用excel本身另存为html)

    博客分类:
  • j2ee
 
阅读更多
<%@page contentType="application/vnd.ms-excel;charset=GBK" %>
<%@ include file="/base.jsp"%>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<% 
response.setHeader("contenttype", "application/vnd.ms-excel; charset=GBK"); 
response.setHeader("content-disposition", "attachment; filename=document.xls"); 
Map  map=(Map)request.getAttribute("listData");
List header=(List)((Map)map.get("list")).get("header");
List data=(List)((Map)map.get("list")).get("data"); 
%> 

<head>
<meta http-equiv=Content-Type content="text/html; charset=GBK">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<!--[if gte mso 9]>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>3</x:ActiveRow>
       <x:ActiveCol>2</x:ActiveCol>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>9600</x:WindowHeight>
<x:WindowWidth>15075</x:WindowWidth>
<x:WindowTopX>480</x:WindowTopX>
<x:WindowTopY>90</x:WindowTopY>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml>
<![endif]-->

<style id="excel_list_31045_Styles"> 
<!--table
	{mso-displayed-decimal-separator:"\.";
	mso-displayed-thousand-separator:"\,";}
.font531045
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;}
.xl1531045
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
.xl2431045
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:bottom;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
.xl2531045
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:left;
	vertical-align:bottom;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
.xl2631045
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:center;
	vertical-align:middle;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;}
-->
</style>


</head>

<body>
<!--[if !excel]>  <![endif]-->
<!--下列信息由 Microsoft Office Excel 的“发布为网页”向导生成。-->
<!--如果同一条目从 Excel 中重新发布,则所有位于 DIV 标记之间的信息均将被替换。-->
<!----------------------------->
<!--“从 EXCEL 发布网页”向导开始-->
<!----------------------------->
<div id="excel_list_31045" align=center x:publishsource="Excel">
 
<table x:str border=0 cellpadding=0 cellspacing=0 width=360 style='border-collapse:
 collapse;table-layout:fixed;width:270pt'>
 <col width=72 span="<%=header.size()-1 %>" style='width:54pt'>
 <tr height=19 style='mso-height-source:userset;height:14.25pt'>
  <td colspan="<%=header.size()-1 %>" height=19 class=xl2631045 width=288 style='height:14.25pt;
  width:216pt'>${ExcelTitle}</td>
 </tr>
 <tr height=19 style='mso-height-source:userset;height:14.25pt'>
 <%for(int i =1;i<header.size();i++){%>
  <td class=xl2431045><%=(String)header.get(i)%></td>
  <%}%>
 </tr>
  <%for (int i =0;i<data.size();i++){
   List colList = (List)data.get(i);
 %>
 <tr height=19 style='mso-height-source:userset;height:14.25pt'>
  <%for (int j =1;j<colList.size();j++){%>  
  <td class=xl2531045><%=colList.get(j)==null?"":(String)colList.get(j)%></td>
  <%} %>  
 </tr>
 <%} %>
 <%-- 
 <![if supportMisalignedColumns]>
 <tr height=0 style='display:none'>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=72 style='width:54pt'></td>
 </tr>
 <![endif]>
--%></table>
 
</div>
<!----------------------------->
<!--“从 EXCEL 发布网页”向导结束-->
<!----------------------------->
</body>

</html>

 

分享到:
评论
1 楼 mfhappy 2013-11-29  
你好,你这个导出的文件中如果有图片你怎么处理??

相关推荐

Global site tag (gtag.js) - Google Analytics