jsp匯出Excel模板__js

來源:互聯網
上載者:User

最近碰到一個問題,在jsp頁面匯出excel的時候,只匯出1行沒有亂碼,匯出2行的時候,出現亂碼,然後我就一列列的匯出,在倒數第2列的時候出現亂碼,網上各種找資料,都沒有怎麼解決我的問題 ,網上大部分都是解決jsp中文亂碼的文章,跟我這個還是有點差別的。後來發現,不知道誰寫的代碼,由於涉及到匯出,有可能匯出word 也有可能匯出excel,以前的人在代碼中判斷了一下:

<%
if("word".equals(docType)){
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
</head>
<body>
<style>
<!--
.td_border1{
border-right:1 solid #000;
border-bottom:1 solid #000;
}
-->
</style>
<%
}
對,就是這種代碼,如果是匯出word的話<html>這種標籤才加,匯出excel不加

註:jsp匯出excel,如果其他該設定的都設定了,還有亂碼,記得添加: <meta http-equiv="Content-Type" content="text/html;charset=gb2312">

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ page import="org.apache.commons.codec.binary.Base64"%><%@ taglib prefix="s" uri="/struts-tags"%><%@ page import="java.net.URLEncoder"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%><%@ taglib prefix="limit" uri="http://www.yineng.com/limit"%><%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%><%@ taglib prefix="ev" uri="http://www.yineng.com/enumvalue" %><%String path = request.getContextPath();   response.setContentType("application/vnd.ms-excel;charset=UTF-8");String excelName = "學生學分達標情況";   //亂碼解決,根據使用者瀏覽器獲得下載資訊String agent = (String)request.getHeader("USER-AGENT");if(agent != null && agent.indexOf("MSIE") == -1){// FF    excelName = "=?UTF-8?B?" + (new String(Base64.encodeBase64(excelName.getBytes("UTF-8")))) + "?=";        response.setHeader("Content-Disposition", "attachment; filename=" + excelName + ".xls");    } else { // IEexcelName = new String(excelName.getBytes("GBK"), "ISO-8859-1");        response.setHeader("Content-Disposition", "attachment; filename=" + excelName+ ".xls");    }%><html><head></head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><body><div><table class="tableMainStyle"  border="1"><thead><tr> <th class="xh_align">序號</th><th >學號</th><th >姓名</th><th >行政班</th><th >組織機構</th><th >專業</th><th >年級</th><th >性別</th><th >民族</th><th >學生總學分</th><th >是否達標</th></tr></thead><tbody ><c:choose><c:when test="${! empty list }"><c:forEach var="entity" items="${list }" varStatus="obj"><tr><td>${obj.index+1 }</td><td>${entity.stuNum }</td><td>${entity.infoName }</td><td>${entity.orgClassName}</td><td>${entity.orgmanName}</td><td>${entity.specialtyName}</td><td>${entity.grade}</td><td>${entity.sex}</td><td>${entity.nation}</td><td>${entity.totalCredit}</td><td><ev:changeValue enumIndex="${entity.isCompliance}" enumClassPath="com.yineng.base.enums.StandardStateEnum" /></td></tr></c:forEach></c:when><c:otherwise><tr><td colspan="11" align="center"><s:text name="nodata" /></td></tr></c:otherwise></c:choose></tbody></table></div></body></html>


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.