今天终于搞定了一个头疼的问题,为了省事,将页面的table直接保存为excel,但是单元格内容有换行就很麻烦了,用<br/>换行的话就变成多行记录了,
用下边这个就ok了:
<br style='mso-data-placement:same-cell;'/>
导出jsp的代码
<%@ page contentType="application/vnd.ms-excel; charset=gbk" %>
<%@ page language="java" pageEncoding="GBK"%>
<%@include file="/common.jsp"%>
<%
String filename = new String(("工单导出于"+request.getAttribute("datetime")).getBytes("GBK"),"ISO-8859-1");
response.addHeader("Content-Disposition", "filename="+filename+ ".xls");
%>
<html>
<!--
- Author(s): 宋成平
- Date: 2011-02-13 00:28:38
- Description:
-->
<head>
<title>工单导出到excel</title>
<meta name="Generator" content="Microsoft Excel 11">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body >
<table align="left" border="1" width="100%" height="100%" style="border-collapse: collapse;border:1px solid #A3C4D0;border-top-width: 0px" Cellpadding="12" Cellspacing="3" >
<tr>
<td align="center" colspan="13" style="font-weight: bold;size:50pt;">工单导出</td>
</tr>
<tr >
<th align="left" nowrap="nowrap">
工单号
</th>
<th align="left" nowrap="nowrap">
请求来源
</th>
<th align="left" nowrap="nowrap">
紧急度
</th>
<th align="left" nowrap="nowrap">
满意度
</th>
<th align="left" nowrap="nowrap">
故障点位
</th>
<th align="left" nowrap="nowrap">
是否超时
</th>
<th align="left" nowrap="nowrap">
停线失效
</th>
<th align="left" nowrap="nowrap">
服务目录
</th>
<th align="left" nowrap="nowrap">
工单责任人
</th>
<th align="left" nowrap="nowrap">
创建时间
</th>
<th align="left" nowrap="nowrap">
关闭时间
</th>
<th align="left" nowrap="nowrap">
主题
</th>
</tr>
<tr>
<td>
<b:write property="names/ORDER_CODE"/>
</td>
<td>
<b:write property="names/REQU_PEOP_NAME"/>
</td>
<td align="center" >
<b:write property="names/EMERGENCY_NAME"/>
</td>
<td align="center">
<b:write property="names/CONTENT_NAME"/>
</td>
<td align="center" >
<b:write property="names/DISCOVER_AREA_NAME"/>
</td>
<td align="center">
<b:write property="names/IS_TIME_OUT_NAME"/>
</td>
<td align="center">
<b:write property="names/DISABLED_TIMEOUT_NAME"/>
</td>
<td align="center" >
<b:write property="names/SERVICE_LIST_NAME"/>
</td>
<td align="center">
<b:write property="names/RESPONSIBLE_USER_NAME"/>
</td>
<td align="center">
<b:write property="names/ORDER_CREATE_DATE"/>
</td>
<td align="center">
<b:write property="names/ORDER_CLOSE_DATE"/>
</td>
<td align="center">
<b:write property="names/TITLE"/>
</td>
</tr>
<tr>
<td align="left" colspan="15" >工单总数:<b:write property="number"/></td>
</tr>
<tr>
<th align="left" nowrap="nowrap">
<font style="font-weight: bold">工单编号</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">请求日期</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">停线时间(分钟)</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">失效时间(分钟)</font>
</th>
<th align="left" nowrap="nowrap">
<font style="font-weight: bold">服务项</font>
</th>
<th align="left" nowrap="nowrap">
<font style="font-weight: bold">工单主题</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">工单描述</font>
</th>
<th align="center" nowrap="nowrap" >
<font style="font-weight: bold">处理过程</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">故障点位</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">原因分析</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">故障类型</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">责任人</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold"> 工单整体耗时</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">工单提前/超时</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">紧急度</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">响应时间</font>
</th>
<th align="center" nowrap="nowrap">
<font style="font-weight: bold">解决时间</font>
</th>
<th nowrap="nowrap">
<font style="font-weight: bold">请求发起人</font>
</th>
<th nowrap="nowrap">
<font style="font-weight: bold">请求发起人编号</font>
</th>
<th nowrap="nowrap">
<font style="font-weight: bold">请求发起人科室</font>
</th>
<th nowrap="nowrap">
<font style="font-weight: bold">发起人手机号码</font>
</th>
<th nowrap="nowrap">
<font style="font-weight: bold">请求发起人电脑编号</font>
</th>
<th align="left" nowrap="nowrap">
<font style="font-weight: bold">工单创建时间</font>
</th>
<th nowrap="nowrap">
<font style="font-weight: bold">工单关闭时间</font>
</th>
<l:iterate id="fault" property="ITSM_FAULT_LISTs" >
<th nowrap="nowrap" bgcolor="<l:equal iterateId="fault" property="FAULT_LIST_PARENT_ID" targetValue="0">blue</l:equal>" >
<font style="font-weight: bold"><b:write iterateId="fault" property="FAULT_LIST_NAME" /></font>
</th>
</l:iterate>
</tr>
<l:iterate id="order" property="list" >
<tr>
<td>
<b:write iterateId="order" property="ORDER_CODE" />
</td>
<td>
<b:write iterateId="order" property="ORDER_CREATE_DATE" formatPattern="yyyy-MM-dd"/>
</td>
<td>
<b:write iterateId="order" property="STOP_TIME"/>
</td>
<td>
<b:write iterateId="order" property="DISABLED_TIME"/>
</td>
<td>
<b:write iterateId="order" property="SERVICE_LIST_PATH_NAME"/>
</td>
<td>
<b:write iterateId="order" property="TITLE"/>
</td>
<td>
<b:write iterateId="order" property="ORDER_DESC"/>
</td>
<td>
<l:iterate iterateId="order" property="ITSM_INC_HISTORY_OPERATIONs" id="id3">
第<l:indexId start="1"/>步:<b:write iterateId="id3" property="ACTIVITYDEF_NAME"/>(<b:write iterateId="id3" property="OPERATION_USER_NAME"/>)
<br style='mso-data-placement:same-cell;'/>
耗时:<b:write iterateId="id3" property="USEDTIME"/>
<br style='mso-data-placement:same-cell;'/>
<l:iterate iterateId="id3" property="iTSM_WORK_RECORDs" id="works">
<b:write iterateId="works" property="WORK_OUTCOME_TITLE"/>: <b:write iterateId="works" property="WORK_OUTCOME"/>
<br style='mso-data-placement:same-cell;'/>
</l:iterate>
</l:iterate>
</td>
<td>
<b:write iterateId="order" property="DISCOVER_AREA"/>
</td>
<td>
<b:write iterateId="order" property="ITSM_SA_CAUSE/CAUSE_CONTENT"/>
</td>
<td>
<b:write iterateId="order" property="ITSM_BUSINESS_ITEM/NAME"/>
</td>
<td>
<b:write iterateId="order" property="RESPONSIBLE_USER_NAME"/>
</td>
<td>
<b:write iterateId="order" property="USED_TIME"/>分钟
</td>
<td >
<b:write property="REMAIN_TIME" iterateId="order" />分钟
</td>
<td align="center" width="5%" >
<l:equal property="EMERGENCY_ID" iterateId="order" targetValue="2" >
<img src="common/images/icons/lightbulb.png"/>
</l:equal>
<d:write iterateId="order" dictTypeId="ITSM_EMERGENCY" property="EMERGENCY_ID"/>
</td>
<td>
<b:write property="REQU_RESPONSE_TIME" iterateId="order" />分钟
</td>
<td>
<b:write property="REQU_SOLVE_TIME" iterateId="order" />分钟
</td>
<td>
<b:write iterateId="order" property="REQU_EMP_NAME"/>
<l:equal iterateId="order" property="REQU_EMP_DEGREE" targetProperty="level3" compareType="string">
(<b:write iterateId="order" property="REQU_EMP_DEGREE_NAME"/>)
</l:equal>
</td>
<td>
<b:write iterateId="order" property="REQU_EMP_CODE" />
</td>
<td align="center">
<b:write iterateId="order" property="REQU_EMP_ORGPATH" />
</td>
<td>
<b:write iterateId="order" property="REQU_EMP_MOBILENO" />
</td>
<td>
<b:write iterateId="order" property="REQU_EMP_MSN" />
</td>
<td>
<b:write iterateId="order" property="ORDER_CREATE_DATE"/>
</td>
<td>
<b:write iterateId="order" property="ORDER_CLOSE_DATE"/>
</td>
<l:iterate id="oderFault" iterateId="order" property="ITSM_FAULT_LISTs" >
<td>
<b:write iterateId="oderFault" property="FLAG"/>
<!--<l:in iterateId="oderFault" property="FAULT_LIST_ID" seperator="," targetId="order" targetProperty="ITSM_ORDER_FAULTSTR" >
1
</l:in>-->
</td>
</l:iterate>
</tr>
</l:iterate>
</table>
</body>
</html>