一個關于導出excel模板的實例

1 首先jsp頁面

點擊模板下載,會自動下載模板excel,效果如下

讓我們看源碼:

1 jsp頁面

<div class="tab-pane" id="profile">
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" id="export" onClick="toModelExport()" value="模板下載" >
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" id="export" onClick="toExport()" value="批量導入" >
</div>

主要是兩個按鈕

js函數

function toModelExport(){

$("<form>").attr({
"action":"${ctx}/doctor/toModelDownLoad",
"method":"get"
}).submit();toModelExport

}

2后臺controller

//模板導入
@RequestMapping(value = "/toModelDownLoad")
public void toModelDownLoad(HttpServletRequest request, HttpServletResponse response) {
WritableWorkbook wb = null;
OutputStream os = null;
String fileName = "doctorImportStand.xls";
try {
os = response.getOutputStream();
wb =new Importmodel().createWorkbookModel(os);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
wb.write();
wb.close();
os.close();
response.flushBuffer();
} catch (Exception e) {
e.printStackTrace();
}
}

核心就是這個new Importmodel().createWorkbookModel(os);

3Importmodel類

public class Importmodel {
protected final Log log = LogFactory.getLog(getClass());
//醫生模板
public WritableWorkbook createWorkbookModel(OutputStream outputStream) {
WritableWorkbook wwb = null;
try {
wwb = Workbook.createWorkbook(outputStream);
WritableSheet sheet =wwb.createSheet("醫生信息錄入模板",1);
//解決jxl下拉框254字符限制
WritableSheet sheet2 = wwb.createSheet("錄入說明", 1);
WritableFont font = new WritableFont(jxl.write.WritableFont
.createFont("隸書"),14);
WritableCellFormat format = new WritableCellFormat(font);
Label label1 = new Label(0,0,"性別",format);
sheet2.addCell(label1);
label1 = new Label(0,1,"1",format);
sheet2.addCell(label1);
label1 = new Label(1,1,"男",format);
sheet2.addCell(label1);
label1 = new Label(0,2,"2",format);
sheet2.addCell(label1);
label1 = new Label(1,2,"女",format);
sheet2.addCell(label1);
label1 = new Label(0,3,"用戶類型",format);
sheet2.addCell(label1);
label1 = new Label(0,4,"1",format);
sheet2.addCell(label1);
label1 = new Label(1,4,"醫生",format);
sheet2.addCell(label1);
label1 = new Label(0,5,"2",format);
sheet2.addCell(label1);
label1 = new Label(1,5,"患者",format);
sheet2.addCell(label1);
label1 = new Label(0,6,"3",format);
sheet2.addCell(label1);
label1 = new Label(1,6,"專家",format);
sheet2.addCell(label1);
label1 = new Label(0,7,"職稱",format);
sheet2.addCell(label1);
label1 = new Label(0,8,"1",format);
sheet2.addCell(label1);
label1 = new Label(1,8,"主任醫師",format);
sheet2.addCell(label1);
label1 = new Label(0,9,"2",format);
sheet2.addCell(label1);
label1 = new Label(1,9,"副主任醫師",format);
sheet2.addCell(label1);
label1 = new Label(0,10,"3",format);
sheet2.addCell(label1);
label1 = new Label(1,10,"主治醫師",format);
sheet2.addCell(label1);
label1 = new Label(0,11,"4",format);
sheet2.addCell(label1);
label1 = new Label(1,11,"醫師",format);
sheet2.addCell(label1);
label1 = new Label(0,12,"5",format);
sheet2.addCell(label1);
label1 = new Label(1,12,"教授",format);
sheet2.addCell(label1);
label1 = new Label(0,13,"6",format);
sheet2.addCell(label1);
label1 = new Label(1,13,"副教授",format);
sheet2.addCell(label1);
label1 = new Label(0,14,"醫院代碼",format);
sheet2.addCell(label1);
label1 = new Label(0,15,"1",format);
sheet2.addCell(label1);
label1 = new Label(1,15,"中山醫院",format);
sheet2.addCell(label1);

label1 = new Label(0,16,"2",format);
sheet2.addCell(label1);
label1 = new Label(1,16,"金澤鎮社區衛生服務中心",format);
sheet2.addCell(label1);
label1 = new Label(0,17,"3",format);
sheet2.addCell(label1);
label1 = new Label(1,17,"青浦區中心醫院",format);
sheet2.addCell(label1);
label1 = new Label(0,18,"組織架構",format);
sheet2.addCell(label1);
label1 = new Label(0,19,"1",format);
sheet2.addCell(label1);
label1 = new Label(1,19,"肺癌聯盟",format);
sheet2.addCell(label1);
label1 = new Label(0,20,"科室",format);
sheet2.addCell(label1);
label1 = new Label(0,21,"1",format);
sheet2.addCell(label1);
label1 = new Label(1,21,"呼吸內科",format);
sheet2.addCell(label1);
label1 = new Label(0,22,"2",format);
sheet2.addCell(label1);
label1 = new Label(1,22,"全科",format);
sheet2.addCell(label1);
sheet.mergeCells(0,0,13,0);
sheet.setRowView(0, 400);
StringBuffer strBuf = new StringBuffer();
strBuf.append("屬性說明: \r\n 1、用戶類型:1 醫生 2患者 3專家 此處只能導入醫生")
.append("\r\n").append(" 2、性別:1 男 2 女")
.append("\r\n").append(" 3、組織架構為用戶所在的組織架構Id 1 肺癌聯盟")
.append("\r\n").append(" 4、醫院,科室均輸入編號即可")
.append("\r\n").append(" 5、 職稱:1 主任醫師 2 副主任醫師 3 主治醫師4 醫師 5 教授 6 副教授")
.append("\r\n").append(" 6、 請嚴格按照模板格式進行導入,每一項都要填寫,否則不能導入");
Label label = new Label(0,0,strBuf.toString());
sheet.addCell(label);
label = new Label(0,1,"用戶類型");
sheet.addCell(label);
label = new Label(0,2,"1");
sheet.addCell(label);
label = new Label(1,1,"手機號");
sheet.addCell(label);
label = new Label(1,2,"13524929813");
sheet.addCell(label);
label = new Label(2,1,"姓名");
sheet.addCell(label);
label = new Label(2,2,"趙");
sheet.addCell(label);
label = new Label(3,1,"性別");
sheet.addCell(label);
label = new Label(3,2,"2");
sheet.addCell(label);
label = new Label(4,1,"組織架構");
sheet.addCell(label);
label = new Label(4,2,"1");
sheet.addCell(label);
label = new Label(5,1,"醫院");
sheet.addCell(label);
label = new Label(5,2,"2");
sheet.addCell(label);
label = new Label(6,1,"科室");
sheet.addCell(label);
label = new Label(6,2,"2");
sheet.addCell(label);
label = new Label(7,1,"職稱");
sheet.addCell(label);
label = new Label(7,2,"1");
sheet.addCell(label);
label = new Label(8,1,"出生日期");
sheet.addCell(label);
label = new Label(8,2,"1980.08.08");
sheet.addCell(label);
label = new Label(9,1,"醫生角色");
sheet.addCell(label);
label = new Label(9,2,"3");
sheet.addCell(label);
label = new Label(10,1,"坐診時間");
sheet.addCell(label);
label = new Label(10,2,"1-0,1-1,2-0,2-1");
sheet.addCell(label);
label = new Label(11,1,"會診時間");
sheet.addCell(label);
label = new Label(11,2,"3");
sheet.addCell(label);
label = new Label(12,1,"會診價格");
sheet.addCell(label);
label = new Label(12,2,"2000");
sheet.addCell(label);
label = new Label(13,1,"簡介");
sheet.addCell(label);
label = new Label(13,2,"副教授、醫學博士、呼吸內科執行主任,青浦區學科帶頭人、上海市醫學會肺科學會青年委員。從事呼吸內科專業臨床醫療、科研及教學工作20年,基礎理論知識扎實,擅長慢性阻塞性肺疾病、支氣管哮喘、肺心病、呼吸衰竭、肺部感染性疾病、肺部腫瘤、間質性肺疾病、胸膜疾病等呼吸系統常見疾病的診治,對于呼吸系統各種疑難、危重病癥的診治及搶救技術,機械通氣技術和呼吸內鏡及介入診療技術具有豐富的臨床經驗。 近年來,主持市級科研課題2項,參與國家自然基金項目、市級科研課題項目多項;作為第一作者在SCI收錄及國內核心期刊發表專業學術論文20余篇。");
sheet.addCell(label);
} catch (IOException e) {
log.error("ERROR:createWorkbookModel",e);
} catch (RowsExceededException e) {
log.error("ERROR:createWorkbookModel",e);
} catch (WriteException e) {
log.error("ERROR:createWorkbookModel",e);
}
return wwb;
}

至此,可以順利實現功能

所用到的依賴

import java.io.IOException;
import java.io.OutputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

?

轉載于:https://www.cnblogs.com/zhaoblog/p/6264090.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/284921.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/284921.shtml
英文地址,請注明出處:http://en.pswp.cn/news/284921.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

騰訊視頻VIP會員,周卡特價9.5元!

今天給大家推薦特價充值騰訊視頻VIP會員的平臺——幻海優品&#xff0c;騰訊視頻在線直充&#xff0c;VIP會員實時生效&#xff01;騰訊視頻VIP會員特價充值周卡&#xff1a;原價12元&#xff0c;特價9.5元月卡&#xff1a;原價30元&#xff0c;特價22元季卡&#xff1a;原價68…

解決安裝SQL Server 2005開發版時,出現“SQL Server 服務無法啟動 ”點擊重試或取消的解決方法

問題描述&#xff1a; 安裝SQL Server 2005開發版時&#xff0c;提示SQL Server服務無法啟動&#xff0c;有關詳細信息&#xff0c;請參閱SQL Server聯機叢書中的主題如何查看SQL Server 2005安裝日志文件和手動啟動SQL Server&#xff0c;如下圖所示。 此時&#xff0c;如果點…

C語言試題196之實現strstr函數功能

??個人主頁:個人主頁 ??系列專欄:C語言試題200例 ?作者簡介:大家好,我是碼莎拉蒂,CSDN博客專家(全站排名Top 50),阿里云博客專家、51CTO博客專家、華為云享專家 1、題目 題目: 實現strstr函數功能 C 庫函數 char *strstr(const char *haystack, const char *nee…

svnsync實現版本庫的同步備份

svnsync實現版本庫的同步備份 實驗環境&#xff1a;A&#xff0c;172.17.201.243&#xff08;主&#xff09;B&#xff0c;172.17.201.88&#xff08;備&#xff09;項目需求&#xff0c;生產環境要求svn服務器實現熱備機制&#xff0c;于是就想到了svn自帶的svnsync機制&#…

關于數據結構(二)

文章目錄[點擊展開](?)[] 一UI返回功能思路分析實現方法二當前正在CD技能接著上文<<關于數據結構(一)>>&#xff0c;關于數據結構&#xff0c;在實際的開發中或多或少都有涉及到&#xff0c;只是看自己平時沒有積累到。下面是我在項目中的幾個實例&#xff1a; 一…

JDBC 之 事務

1.概念&#xff1a;事務指邏輯上的一組操作&#xff0c;組成這組操作的各個單元&#xff0c;要么全部成功&#xff0c;要么全部不成功。 2.數據庫開啟事務的命令dtl&#xff1a; Start transaction開啟事務 Rollback回滾事務&#xff08;撤銷&#xff09; Commit提交事務 3.JDB…

[轉]后端程序員必備:書寫高質量SQL的30條建議

以下文章來源于撿田螺的小男孩 &#xff0c;作者撿田螺的小男孩 轉載&#xff1a;《后端程序員必備&#xff1a;書寫高質量SQL的30條建議》 前言 本文將結合實例demo&#xff0c;闡述30條有關于優化SQL的建議&#xff0c;多數是實際開發中總結出來的&#xff0c;希望對大家有…

GIS熱詞:AR、VR、MR辨析

AR、VR、MR技術讓我們見識到了科技神奇的同時&#xff0c;也讓真實可感的現實世界和無法觸摸的虛擬世界的聯系更加緊密。 1. AR AR&#xff0c;全稱Augmented Reality&#xff0c;即增強現實技術。這項技術是利用電腦技術將虛擬的信息疊加到真實世界&#xff0c;通過手機、平板…

云原生數據庫是未來數據庫的天下

一、傳統數據庫的發展階段和痛點 1&#xff09;、傳統數據庫的發展階段 ?人工管理階段 20世紀50十年代中期以前&#xff0c;計算機只是用來計算的&#xff0c;那么數據管理就只能純人工. ?文件系統管理階段 20世紀50年代后期到60年代中期&#xff0c;這時硬件方面有了磁盤、磁…

用.NET做DDNS動態域名解析和SSL證書申請

本文主要介紹 IPv6 配置 DDNS 解析和 SSL 證書申請工具的開發歷程和其中的相關知識。工具使用.NET開發&#xff0c;已開源&#xff0c;目前該工具的域名解析只支持阿里云。文中提及或使用的 .NET 開源項目&#xff1a;SangServerTool&#xff08;DDNS,SSL證書申請工具&#xff…

匯編學習(一)

看的是王爽老師的《匯編語言》第三版基礎知識 一.匯編語言的誕生上古時期在匯編語言還未出現的時候&#xff0c;那時的程序員還只能用二進制也就是所謂的機器語言寫代碼&#xff0c;將0和1編成的程序代碼打在紙帶或卡片上&#xff0c;再將紙帶卡片輸入計算機&#xff0c;進行運…

Java 網絡編程1

talnet工具與Socket類 如今單機的程序已經不太能適合用戶的需要&#xff0c;網絡編程變得比以往更加重要。首先需要認識一下talnet工具&#xff0c;可以使用該工具來連接服務器在終端中輸入,可以進入本地的80端口 talnet 127.0.0.1 80 需要我們輸入ip地址和端口號&#xff0c;使…

【GIS風暴】GeoJSON數據格式案例全解

在了解GeoJSON數據之前,先來通過一個網站和一個簡單的代碼案例,看一下GeoJSON的神奇魅力吧! 網站:http://geojson.io 打開上述網站,在左側的代碼區域粘入中國區域GeoJSON代碼,如下所示: 中國地圖: 地名:

mysqldump參數大全

參數 參數說明 --all-databases , -A 導出全部數據庫。 mysqldump -uroot -p --all-databases --all-tablespaces , -Y 導出全部表空間。 mysqldump -uroot -p --all-databases --all-tablespaces --no-tablespaces , -y 不導出任何表空間信息。 mysqldump -uroot -p --a…

[轉]2020年5月程序員工資統計,平均14542元

平均工資 2020年5月全國招收程序員312761人。2020年5月全國程序員平均工資14542元&#xff0c;工資中位數12500 元&#xff0c;其中95%的人的工資介于5250元到35000元。 一線城市工資 2020年5月北京招收軟件工程師24478人。2019年5月北京軟件工程師平均工資19273元&#xff0…

云原生IDE:iVX免費的首個通用無代碼開發平臺

一、iVX簡單介紹 1、iVX是什么東東? iVX 是一個 “零代碼” 的可視化編程語言&#xff0c;擁有方便的 在線集成開發環境 &#xff0c;不需要下載開發環境&#xff0c;打開瀏覽器即可隨時隨地的進行項目編輯&#xff1b;iVX 擁有 “一站式” 的云資源&#xff0c;通過這一套一…

.NET GC工作流程

前言在上文[如何獲取GC的STW時間]一文中&#xff0c;我們聊到了如何通過監聽GC發出的診斷事件來計算STW時間。里面只簡單的介紹了幾種GC事件和它的流程。群里就有小伙伴在問&#xff0c;那么GC事件是什么時候產生的&#xff1f;分別是代表什么含義&#xff1f;那么在本文就通過…

libco協程庫源碼解讀

2019獨角獸企業重金招聘Python工程師標準>>> 協程,又被稱為用戶級線程,是在應用層被調度,可以減少因為調用系統調用而阻塞的線程切換的時間.目前有很多協程的實現,由于微信內部大量使用了其直研的的libco協程庫&#xff0c;所以我選擇了騰訊開源的libco協程庫進行研…

【ArcGIS風暴】如何將矢量數據(點、線、面)折點坐標轉為GeoJSON格式?

本文以案例的形式,講述在ArcGIS和QGIS專業軟件中,將矢量數據轉為GeoJSON的方法。 擴展閱讀:【GIS風暴】GeoJSON數據格式案例全解 文章目錄 一、ArcGIS將矢量數據轉為GeoJSON二、QGIS將矢量數據轉為GeoJSON一、ArcGIS將矢量數據轉為GeoJSON ArcGIS中提供的【要素轉JSON】工具…

TypeScript 3.9 正式發布!平均編譯時長從 26 秒縮短至 10 秒

作者 | 微軟官方博客 譯者 | 核子可樂 策劃 | 小智 稿源 | 前端之巔 今天&#xff0c;微軟在其官方博客宣布&#xff1a;TypeScript 3.9 版本已經正式發布&#xff0c;詳情見下文。 有些朋友可能對 TypeScript 還不太熟悉&#xff0c;這是一種以 JavaScript 為基礎開發的語…