目录
所需要的jar包
导入模板
实体类
ExcelUtil工具类
controller层导入
controller层导出
jxl-2.6.jar
poi-3.17.jar
package schooloa.bean;
import schooloa.util.ExcelVOAttribute;
public class ToolsList {
private Integer id;
@ExcelVOAttribute(name = "年份", column = "A")
private String time;
@ExcelVOAttribute(name = "学期", column = "B")
private String semester;//学期
@ExcelVOAttribute(name = "专业", column = "C")
private String professional;
@ExcelVOAttribute(name = "教师姓名", column = "D")
private String teachername;
@ExcelVOAttribute(name = "蓝圆珠笔", column = "E")
private String lyzb;
@ExcelVOAttribute(name = "红圆珠笔", column = "F")
private String hyzb;
@ExcelVOAttribute(name = "蓝圆珠笔芯", column = "G")
private String lyzbx;
@ExcelVOAttribute(name = "红圆珠笔芯", column = "H")
private String hyzbx;
@ExcelVOAttribute(name = "晨光0.5中性笔(黑)", column = "I")
private String cgfivezxbh;
@ExcelVOAttribute(name = "晨光0.5中性笔(红)", column = "J")
private String cgfivezxbhong;
@ExcelVOAttribute(name = "晨光0.7中性笔", column = "K")
private String cgsevenzxb;
@ExcelVOAttribute(name = "晨光1.0中性笔", column = "L")
private String cgonezxb;
@ExcelVOAttribute(name = "红蓝铅笔", column = "M")
private String hlqb;
@ExcelVOAttribute(name = "铅笔(2B)", column = "N")
private String twobqb;
@ExcelVOAttribute(name = "彩色铅笔", column = "O")
private String csqb;
@ExcelVOAttribute(name = "白板笔", column = "P")
private String baibanbi;
@ExcelVOAttribute(name = "白板笔油", column = "Q")
private String baibanbiyou;
@ExcelVOAttribute(name = "晨光0.5中性笔芯(黑)", column = "R")
private String chengguangwuzhongxingbixinhei;
@ExcelVOAttribute(name = "晨光0.5中性笔芯(红)", column = "S")
private String chengguangwuzhongxingbixinhong;
@ExcelVOAttribute(name = "晨光0.7中性笔芯", column = "T")
private String chenguangqizhongxingbixin;
@ExcelVOAttribute(name = "晨光1.0中性笔芯", column = "U")
private String chenguangyizhongxingbixin;
@ExcelVOAttribute(name = "油性记号笔", column = "V")
private String youxingjihaobi;
@ExcelVOAttribute(name = "大信笺", column = "W")
private String daxinfa;
@ExcelVOAttribute(name = "稿纸", column = "X")
private String gaozhi;
@ExcelVOAttribute(name = "牛皮纸档案袋", column = "Y")
private String niupizhidangandai;
@ExcelVOAttribute(name = "塑料档案袋", column = "Z")
private String suliaodangandai;
@ExcelVOAttribute(name = "透明窄胶带", column = "AA")
private String toumingzhaijiaodai;
@ExcelVOAttribute(name = "透明宽胶带", column = "AB")
private String toumingkuangjiaodai;
@ExcelVOAttribute(name = "双面窄胶带", column = "AC")
private String shuangmianzhaijiaodai;
@ExcelVOAttribute(name = "双面宽胶带", column = "AD")
private String shuangmiankuanjiaodai;
@ExcelVOAttribute(name = "泡沫双面胶带", column = "AE")
private String paomoshuangmianjiaodai;
@ExcelVOAttribute(name = "大红纸", column = "AF")
private String dahongzhi;
@ExcelVOAttribute(name = "宣纸", column = "AG")
private String xuanzhi;
@ExcelVOAttribute(name = "3.5得力档案盒", column = "AH")
private String sanwudelidanganhe;
@ExcelVOAttribute(name = "5.5得力档案盒", column = "AI")
private String wuwudelidanganhe;
@ExcelVOAttribute(name = "文件夹", column = "AJ")
private String wenjianjia;
@ExcelVOAttribute(name = "A4抽杆夹", column = "AK")
private String asichouganjia;
@ExcelVOAttribute(name = "锥子", column = "AL")
private String zhuizi;
@ExcelVOAttribute(name = "胶水", column = "AM")
private String jiaoshui;
@ExcelVOAttribute(name = "胶棒", column = "AN")
private String jiaobang;
@ExcelVOAttribute(name = "橡皮", column = "AO")
private String xiangpi;
@ExcelVOAttribute(name = "浆糊", column = "AP")
private String jianghu;
@ExcelVOAttribute(name = "墨汁", column = "AQ")
private String mozhi;
@ExcelVOAttribute(name = "PU皮黑硬皮本", column = "AR")
private String pupiheiyingpiben;
@ExcelVOAttribute(name = "软皮本", column = "AS")
private String ruanpiben;
@ExcelVOAttribute(name = "速写本", column = "AT")
private String suxieben;
@ExcelVOAttribute(name = "红印泥", column = "AU")
private String hongyinni;
@ExcelVOAttribute(name = "转笔刀", column = "AV")
private String zhuanbidao;
@ExcelVOAttribute(name = "壁纸刀", column = "AW")
private String bizhidao;
@ExcelVOAttribute(name = "剪刀", column = "AX")
private String jiandao;
@ExcelVOAttribute(name = "小刀", column = "AY")
private String xiaodao;
@ExcelVOAttribute(name = "得力订书机", column = "AZ")
private String delidingshuji;
@ExcelVOAttribute(name = "得力订书钉", column = "BA")
private String delidingshuding;
@ExcelVOAttribute(name = "计算器", column = "BB")
private String jisuanqi;
@ExcelVOAttribute(name = "得力函数计算器", column = "BC")
private String delihanshujisuanqi;
@ExcelVOAttribute(name = "口取纸", column = "BD")
private String kouquzhi;
@ExcelVOAttribute(name = "塑料长直尺30cm", column = "BE")
private String suliaochangzhichisanshi;
@ExcelVOAttribute(name = "塑料长直尺40cm", column = "BF")
private String suliaochangzhichisishi;
@ExcelVOAttribute(name = "得力长尾夹(大)", column = "BG")
private String delichangweijiada;
@ExcelVOAttribute(name = "得力长尾夹(中)", column = "BH")
private String delichangweijiazhong;
@ExcelVOAttribute(name = "得力长尾夹(小)", column = "BI")
private String delichangweijiaxiao;
@ExcelVOAttribute(name = "5号南孚电池", column = "BJ")
private String wuhaonanfudianchi;
@ExcelVOAttribute(name = "7号南孚电池", column = "BK")
private String qihaonanfudianchi;
@ExcelVOAttribute(name = "9V双鹿电池", column = "BL")
private String jiufushuangludianchi;
@ExcelVOAttribute(name = "得力回形针", column = "BM")
private String delihuixingzhen;
@ExcelVOAttribute(name = "得力起钉器", column = "BN")
private String deliqidingqi;
@ExcelVOAttribute(name = "塑料文件架", column = "BO")
private String suliaowenjianjia;
@ExcelVOAttribute(name = "塑料笔筒", column = "BP")
private String suliaobitong;
@ExcelVOAttribute(name = "木质笔筒", column = "BQ")
private String muzhibitong;
@ExcelVOAttribute(name = "1.8米插排", column = "BR")
private String yidianbamichapai;
@ExcelVOAttribute(name = "3米插排", column = "BS")
private String sanmichapai;
@ExcelVOAttribute(name = "5米插排", column = "BT")
private String wumichapai;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time == null ? null : time.trim();
}
public String getSemester() {
return semester;
}
public void setSemester(String semester) {
this.semester = semester == null ? null : semester.trim();
}
public String getTeachername() {
return teachername;
}
public void setTeachername(String teachername) {
this.teachername = teachername == null ? null : teachername.trim();
}
public String getLyzb() {
return lyzb;
}
public void setLyzb(String lyzb) {
this.lyzb = lyzb == null ? null : lyzb.trim();
}
public String getHyzb() {
return hyzb;
}
public void setHyzb(String hyzb) {
this.hyzb = hyzb == null ? null : hyzb.trim();
}
public String getLyzbx() {
return lyzbx;
}
public void setLyzbx(String lyzbx) {
this.lyzbx = lyzbx == null ? null : lyzbx.trim();
}
public String getHyzbx() {
return hyzbx;
}
public String getZhuizi() {
return zhuizi;
}
public void setZhuizi(String zhuizi) {
this.zhuizi = zhuizi;
}
public void setHyzbx(String hyzbx) {
this.hyzbx = hyzbx == null ? null : hyzbx.trim();
}
public String getCgfivezxbh() {
return cgfivezxbh;
}
public void setCgfivezxbh(String cgfivezxbh) {
this.cgfivezxbh = cgfivezxbh == null ? null : cgfivezxbh.trim();
}
public String getCgfivezxbhong() {
return cgfivezxbhong;
}
public void setCgfivezxbhong(String cgfivezxbhong) {
this.cgfivezxbhong = cgfivezxbhong == null ? null : cgfivezxbhong.trim();
}
public String getCgsevenzxb() {
return cgsevenzxb;
}
public void setCgsevenzxb(String cgsevenzxb) {
this.cgsevenzxb = cgsevenzxb == null ? null : cgsevenzxb.trim();
}
public String getCgonezxb() {
return cgonezxb;
}
public void setCgonezxb(String cgonezxb) {
this.cgonezxb = cgonezxb == null ? null : cgonezxb.trim();
}
public String getHlqb() {
return hlqb;
}
public void setHlqb(String hlqb) {
this.hlqb = hlqb == null ? null : hlqb.trim();
}
public String getTwobqb() {
return twobqb;
}
public void setTwobqb(String twobqb) {
this.twobqb = twobqb == null ? null : twobqb.trim();
}
public String getCsqb() {
return csqb;
}
public void setCsqb(String csqb) {
this.csqb = csqb == null ? null : csqb.trim();
}
public String getBaibanbi() {
return baibanbi;
}
public void setBaibanbi(String baibanbi) {
this.baibanbi = baibanbi == null ? null : baibanbi.trim();
}
public String getBaibanbiyou() {
return baibanbiyou;
}
public void setBaibanbiyou(String baibanbiyou) {
this.baibanbiyou = baibanbiyou == null ? null : baibanbiyou.trim();
}
public String getChengguangwuzhongxingbixinhei() {
return chengguangwuzhongxingbixinhei;
}
public void setChengguangwuzhongxingbixinhei(String chengguangwuzhongxingbixinhei) {
this.chengguangwuzhongxingbixinhei = chengguangwuzhongxingbixinhei == null ? null : chengguangwuzhongxingbixinhei.trim();
}
public String getChengguangwuzhongxingbixinhong() {
return chengguangwuzhongxingbixinhong;
}
public void setChengguangwuzhongxingbixinhong(String chengguangwuzhongxingbixinhong) {
this.chengguangwuzhongxingbixinhong = chengguangwuzhongxingbixinhong == null ? null : chengguangwuzhongxingbixinhong.trim();
}
public String getChenguangqizhongxingbixin() {
return chenguangqizhongxingbixin;
}
public void setChenguangqizhongxingbixin(String chenguangqizhongxingbixin) {
this.chenguangqizhongxingbixin = chenguangqizhongxingbixin == null ? null : chenguangqizhongxingbixin.trim();
}
public String getChenguangyizhongxingbixin() {
return chenguangyizhongxingbixin;
}
public void setChenguangyizhongxingbixin(String chenguangyizhongxingbixin) {
this.chenguangyizhongxingbixin = chenguangyizhongxingbixin == null ? null : chenguangyizhongxingbixin.trim();
}
public String getYouxingjihaobi() {
return youxingjihaobi;
}
public void setYouxingjihaobi(String youxingjihaobi) {
this.youxingjihaobi = youxingjihaobi == null ? null : youxingjihaobi.trim();
}
public String getDaxinfa() {
return daxinfa;
}
public void setDaxinfa(String daxinfa) {
this.daxinfa = daxinfa == null ? null : daxinfa.trim();
}
public String getGaozhi() {
return gaozhi;
}
public void setGaozhi(String gaozhi) {
this.gaozhi = gaozhi == null ? null : gaozhi.trim();
}
public String getNiupizhidangandai() {
return niupizhidangandai;
}
public void setNiupizhidangandai(String niupizhidangandai) {
this.niupizhidangandai = niupizhidangandai == null ? null : niupizhidangandai.trim();
}
public String getSuliaodangandai() {
return suliaodangandai;
}
public void setSuliaodangandai(String suliaodangandai) {
this.suliaodangandai = suliaodangandai == null ? null : suliaodangandai.trim();
}
public String getToumingzhaijiaodai() {
return toumingzhaijiaodai;
}
public void setToumingzhaijiaodai(String toumingzhaijiaodai) {
this.toumingzhaijiaodai = toumingzhaijiaodai == null ? null : toumingzhaijiaodai.trim();
}
public String getToumingkuangjiaodai() {
return toumingkuangjiaodai;
}
public void setToumingkuangjiaodai(String toumingkuangjiaodai) {
this.toumingkuangjiaodai = toumingkuangjiaodai == null ? null : toumingkuangjiaodai.trim();
}
public String getShuangmianzhaijiaodai() {
return shuangmianzhaijiaodai;
}
public void setShuangmianzhaijiaodai(String shuangmianzhaijiaodai) {
this.shuangmianzhaijiaodai = shuangmianzhaijiaodai == null ? null : shuangmianzhaijiaodai.trim();
}
public String getShuangmiankuanjiaodai() {
return shuangmiankuanjiaodai;
}
public void setShuangmiankuanjiaodai(String shuangmiankuanjiaodai) {
this.shuangmiankuanjiaodai = shuangmiankuanjiaodai == null ? null : shuangmiankuanjiaodai.trim();
}
public String getPaomoshuangmianjiaodai() {
return paomoshuangmianjiaodai;
}
public void setPaomoshuangmianjiaodai(String paomoshuangmianjiaodai) {
this.paomoshuangmianjiaodai = paomoshuangmianjiaodai == null ? null : paomoshuangmianjiaodai.trim();
}
public String getDahongzhi() {
return dahongzhi;
}
public void setDahongzhi(String dahongzhi) {
this.dahongzhi = dahongzhi == null ? null : dahongzhi.trim();
}
public String getXuanzhi() {
return xuanzhi;
}
public void setXuanzhi(String xuanzhi) {
this.xuanzhi = xuanzhi == null ? null : xuanzhi.trim();
}
public String getSanwudelidanganhe() {
return sanwudelidanganhe;
}
public void setSanwudelidanganhe(String sanwudelidanganhe) {
this.sanwudelidanganhe = sanwudelidanganhe == null ? null : sanwudelidanganhe.trim();
}
public String getWuwudelidanganhe() {
return wuwudelidanganhe;
}
public void setWuwudelidanganhe(String wuwudelidanganhe) {
this.wuwudelidanganhe = wuwudelidanganhe == null ? null : wuwudelidanganhe.trim();
}
public String getWenjianjia() {
return wenjianjia;
}
public void setWenjianjia(String wenjianjia) {
this.wenjianjia = wenjianjia == null ? null : wenjianjia.trim();
}
public String getAsichouganjia() {
return asichouganjia;
}
public void setAsichouganjia(String asichouganjia) {
this.asichouganjia = asichouganjia == null ? null : asichouganjia.trim();
}
public String getJiaoshui() {
return jiaoshui;
}
public void setJiaoshui(String jiaoshui) {
this.jiaoshui = jiaoshui == null ? null : jiaoshui.trim();
}
public String getJiaobang() {
return jiaobang;
}
public void setJiaobang(String jiaobang) {
this.jiaobang = jiaobang == null ? null : jiaobang.trim();
}
public String getXiangpi() {
return xiangpi;
}
public void setXiangpi(String xiangpi) {
this.xiangpi = xiangpi == null ? null : xiangpi.trim();
}
public String getJianghu() {
return jianghu;
}
public void setJianghu(String jianghu) {
this.jianghu = jianghu == null ? null : jianghu.trim();
}
public String getMozhi() {
return mozhi;
}
public void setMozhi(String mozhi) {
this.mozhi = mozhi == null ? null : mozhi.trim();
}
public String getPupiheiyingpiben() {
return pupiheiyingpiben;
}
public void setPupiheiyingpiben(String pupiheiyingpiben) {
this.pupiheiyingpiben = pupiheiyingpiben == null ? null : pupiheiyingpiben.trim();
}
public String getRuanpiben() {
return ruanpiben;
}
public void setRuanpiben(String ruanpiben) {
this.ruanpiben = ruanpiben == null ? null : ruanpiben.trim();
}
public String getSuxieben() {
return suxieben;
}
public void setSuxieben(String suxieben) {
this.suxieben = suxieben == null ? null : suxieben.trim();
}
public String getHongyinni() {
return hongyinni;
}
public void setHongyinni(String hongyinni) {
this.hongyinni = hongyinni == null ? null : hongyinni.trim();
}
public String getZhuanbidao() {
return zhuanbidao;
}
public void setZhuanbidao(String zhuanbidao) {
this.zhuanbidao = zhuanbidao == null ? null : zhuanbidao.trim();
}
public String getBizhidao() {
return bizhidao;
}
public void setBizhidao(String bizhidao) {
this.bizhidao = bizhidao == null ? null : bizhidao.trim();
}
public String getJiandao() {
return jiandao;
}
public void setJiandao(String jiandao) {
this.jiandao = jiandao == null ? null : jiandao.trim();
}
public String getXiaodao() {
return xiaodao;
}
public void setXiaodao(String xiaodao) {
this.xiaodao = xiaodao == null ? null : xiaodao.trim();
}
public String getDelidingshuji() {
return delidingshuji;
}
public void setDelidingshuji(String delidingshuji) {
this.delidingshuji = delidingshuji == null ? null : delidingshuji.trim();
}
public String getDelidingshuding() {
return delidingshuding;
}
public void setDelidingshuding(String delidingshuding) {
this.delidingshuding = delidingshuding == null ? null : delidingshuding.trim();
}
public String getJisuanqi() {
return jisuanqi;
}
public void setJisuanqi(String jisuanqi) {
this.jisuanqi = jisuanqi == null ? null : jisuanqi.trim();
}
public String getDelihanshujisuanqi() {
return delihanshujisuanqi;
}
public void setDelihanshujisuanqi(String delihanshujisuanqi) {
this.delihanshujisuanqi = delihanshujisuanqi == null ? null : delihanshujisuanqi.trim();
}
public String getKouquzhi() {
return kouquzhi;
}
public void setKouquzhi(String kouquzhi) {
this.kouquzhi = kouquzhi == null ? null : kouquzhi.trim();
}
public String getSuliaochangzhichisanshi() {
return suliaochangzhichisanshi;
}
public void setSuliaochangzhichisanshi(String suliaochangzhichisanshi) {
this.suliaochangzhichisanshi = suliaochangzhichisanshi == null ? null : suliaochangzhichisanshi.trim();
}
public String getSuliaochangzhichisishi() {
return suliaochangzhichisishi;
}
public void setSuliaochangzhichisishi(String suliaochangzhichisishi) {
this.suliaochangzhichisishi = suliaochangzhichisishi == null ? null : suliaochangzhichisishi.trim();
}
public String getDelichangweijiada() {
return delichangweijiada;
}
public void setDelichangweijiada(String delichangweijiada) {
this.delichangweijiada = delichangweijiada == null ? null : delichangweijiada.trim();
}
public String getDelichangweijiazhong() {
return delichangweijiazhong;
}
public void setDelichangweijiazhong(String delichangweijiazhong) {
this.delichangweijiazhong = delichangweijiazhong == null ? null : delichangweijiazhong.trim();
}
public String getDelichangweijiaxiao() {
return delichangweijiaxiao;
}
public void setDelichangweijiaxiao(String delichangweijiaxiao) {
this.delichangweijiaxiao = delichangweijiaxiao == null ? null : delichangweijiaxiao.trim();
}
public String getWuhaonanfudianchi() {
return wuhaonanfudianchi;
}
public void setWuhaonanfudianchi(String wuhaonanfudianchi) {
this.wuhaonanfudianchi = wuhaonanfudianchi == null ? null : wuhaonanfudianchi.trim();
}
public String getQihaonanfudianchi() {
return qihaonanfudianchi;
}
public void setQihaonanfudianchi(String qihaonanfudianchi) {
this.qihaonanfudianchi = qihaonanfudianchi == null ? null : qihaonanfudianchi.trim();
}
public String getJiufushuangludianchi() {
return jiufushuangludianchi;
}
public void setJiufushuangludianchi(String jiufushuangludianchi) {
this.jiufushuangludianchi = jiufushuangludianchi == null ? null : jiufushuangludianchi.trim();
}
public String getDelihuixingzhen() {
return delihuixingzhen;
}
public void setDelihuixingzhen(String delihuixingzhen) {
this.delihuixingzhen = delihuixingzhen == null ? null : delihuixingzhen.trim();
}
public String getDeliqidingqi() {
return deliqidingqi;
}
public void setDeliqidingqi(String deliqidingqi) {
this.deliqidingqi = deliqidingqi == null ? null : deliqidingqi.trim();
}
public String getSuliaowenjianjia() {
return suliaowenjianjia;
}
public void setSuliaowenjianjia(String suliaowenjianjia) {
this.suliaowenjianjia = suliaowenjianjia == null ? null : suliaowenjianjia.trim();
}
public String getSuliaobitong() {
return suliaobitong;
}
public void setSuliaobitong(String suliaobitong) {
this.suliaobitong = suliaobitong == null ? null : suliaobitong.trim();
}
public String getMuzhibitong() {
return muzhibitong;
}
public void setMuzhibitong(String muzhibitong) {
this.muzhibitong = muzhibitong == null ? null : muzhibitong.trim();
}
public String getYidianbamichapai() {
return yidianbamichapai;
}
public void setYidianbamichapai(String yidianbamichapai) {
this.yidianbamichapai = yidianbamichapai == null ? null : yidianbamichapai.trim();
}
public String getSanmichapai() {
return sanmichapai;
}
public void setSanmichapai(String sanmichapai) {
this.sanmichapai = sanmichapai == null ? null : sanmichapai.trim();
}
public String getWumichapai() {
return wumichapai;
}
public void setWumichapai(String wumichapai) {
this.wumichapai = wumichapai == null ? null : wumichapai.trim();
}
public String getProfessional() {
return professional;
}
public void setProfessional(String professional) {
this.professional = professional == null ? null : professional.trim();
}
}
ExcelVOAttribute:
package schooloa.util;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target( { java.lang.annotation.ElementType.FIELD })
public @interface ExcelVOAttribute {
/**
* 导出到Excel中的名字.
*/
public abstract String name();
/**
* 配置列的名称,对应A,B,C,D....
*/
public abstract String column();
/**
* 提示信息
*/
public abstract String prompt() default "";
/**
* 设置只能选择不能输入的列内容.
*/
public abstract String[] combo() default {};
/**
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
*/
public abstract boolean isExport() default true;
}
ExcelUtil:
package schooloa.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.apache.poi.hssf.usermodel.DVConstraint;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddressList;
/*
* ExcelUtil工具类实现功能:
* 导出时传入list,即可实现导出为一个excel,其中每个对象T为Excel中的一条记录.
* 导入时读取excel,得到的结果是一个list.T是自己定义的对象.
* 需要导出的实体对象只需简单配置注解就能实现灵活导出,通过注解您可以方便实现下面功能:
* 1.实体属性配置了注解就能导出到excel中,每个属性都对应一列.
* 2.列名称可以通过注解配置.
* 3.导出到哪一列可以通过注解配置.
* 4.鼠标移动到该列时提示信息可以通过注解配置.
* 5.用注解设置只能下拉选择不能随意填写功能.
* 6.用注解设置是否只导出标题而不导出内容,这在导出内容作为模板以供用户填写时比较实用.
* 本工具类以后可能还会加功能,请关注我的博客: http://blog.csdn.net/lk_blog
*/
public class ExcelUtil {
Class clazz;
public ExcelUtil(Class clazz) {
this.clazz = clazz;
}
public List importExcel(String sheetName, InputStream input) {
List list = new ArrayList();
try {
Workbook book = Workbook.getWorkbook(input);
Sheet sheet = null;
if (!sheetName.trim().equals("")) {
sheet = book.getSheet(sheetName);// 如果指定sheet名,则取指定sheet中的内容.
}
if (sheet == null) {
sheet = book.getSheet(0);// 如果传入的sheet名不存在则默认指向第1个sheet.
System.out.println(sheet.toString());
}
int rows = sheet.getRows();// 得到数据的行数
if (rows > 0) {// 有数据时才处理
Field[] allFields = clazz.getDeclaredFields();// 得到类的所有field.
Map fieldsMap = new HashMap();// 定义一个map用于存放列的序号和field.
for (Field field : allFields) {
// 将有注解的field存放到map中.
if (field.isAnnotationPresent(ExcelVOAttribute.class)) {
ExcelVOAttribute attr = field
.getAnnotation(ExcelVOAttribute.class);
int col = getExcelCol(attr.column());// 获得列号
// System.out.println(col + "====" + field.getName());
field.setAccessible(true);// 设置类的私有字段属性可访问.
fieldsMap.put(col, field);
}
}
for (int i = 1; i < rows; i++) {// 从第2行开始取数据,默认第一行是表头.
Cell[] cells = sheet.getRow(i);// 得到一行中的所有单元格对象.
T entity = null;
for (int j = 0; j < cells.length; j++) {
String c = cells[j].getContents();// 单元格中的内容.
if (c.equals("")) {
continue;
}
entity = (entity == null ? clazz.newInstance() : entity);// 如果不存在实例则新建.
// System.out.println(cells[j].getContents());
Field field = fieldsMap.get(j);// 从map中得到对应列的field.
// 取得类型,并根据对象类型设置值.
Class> fieldType = field.getType();
if ((Integer.TYPE == fieldType)
|| (Integer.class == fieldType)) {
field.set(entity, Integer.parseInt(c));
} else if (String.class == fieldType) {
field.set(entity, String.valueOf(c));
} else if ((Long.TYPE == fieldType)
|| (Long.class == fieldType)) {
field.set(entity, Long.valueOf(c));
} else if ((Float.TYPE == fieldType)
|| (Float.class == fieldType)) {
field.set(entity, Float.valueOf(c));
} else if ((Short.TYPE == fieldType)
|| (Short.class == fieldType)) {
field.set(entity, Short.valueOf(c));
} else if ((Double.TYPE == fieldType)
|| (Double.class == fieldType)) {
field.set(entity, Double.valueOf(c));
} else if (Character.TYPE == fieldType) {
if ((c != null) && (c.length() > 0)) {
field.set(entity, Character
.valueOf(c.charAt(0)));
}
}
}
if (entity != null) {
list.add(entity);
}
}
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
return list;
}
/**
* 对list数据源将其里面的数据导入到excel表单
*
* @param sheetName
* 工作表的名称
* @param sheetSize
* 每个sheet中数据的行数,此数值必须小于65536
* @param output
* java输出流
*/
public boolean exportExcel(List list, String sheetName, int sheetSize,
OutputStream output) {
Field[] allFields = clazz.getDeclaredFields();// 得到所有定义字段
List fields = new ArrayList();
// 得到所有field并存放到一个list中.
for (Field field : allFields) {
if (field.isAnnotationPresent(ExcelVOAttribute.class)) {
fields.add(field);
}
}
HSSFWorkbook workbook = new HSSFWorkbook();// 产生工作薄对象
// excel2003中每个sheet中最多有65536行,为避免产生错误所以加这个逻辑.
if (sheetSize > 65536 || sheetSize < 1) {
sheetSize = 65536;
}
double sheetNo = Math.ceil(list.size() / sheetSize);// 取出一共有多少个sheet.
for (int index = 0; index <= sheetNo; index++) {
HSSFSheet sheet = workbook.createSheet();// 产生工作表对象
workbook.setSheetName(index, sheetName + index);// 设置工作表的名称.
HSSFRow row;
HSSFCell cell;// 产生单元格
row = sheet.createRow(0);// 产生一行
// 写入各个字段的列头名称
for (int i = 0; i < fields.size(); i++) {
Field field = fields.get(i);
ExcelVOAttribute attr = field
.getAnnotation(ExcelVOAttribute.class);
int col = getExcelCol(attr.column());// 获得列号
cell = row.createCell(col);// 创建列
cell.setCellType(HSSFCell.CELL_TYPE_STRING);// 设置列中写入内容为String类型
cell.setCellValue(attr.name());// 写入列名
// 如果设置了提示信息则鼠标放上去提示.
if (!attr.prompt().trim().equals("")) {
setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, col, col);// 这里默认设了2-101列提示.
}
// 如果设置了combo属性则本列只能选择不能输入
if (attr.combo().length > 0) {
setHSSFValidation(sheet, attr.combo(), 1, 100, col, col);// 这里默认设了2-101列只能选择不能输入.
}
}
int startNo = index * sheetSize;
int endNo = Math.min(startNo + sheetSize, list.size());
// 写入各条记录,每条记录对应excel表中的一行
for (int i = startNo; i < endNo; i++) {
row = sheet.createRow(i + 1 - startNo);
T vo = (T) list.get(i); // 得到导出对象.
for (int j = 0; j < fields.size(); j++) {
Field field = fields.get(j);// 获得field.
field.setAccessible(true);// 设置实体类私有属性可访问
ExcelVOAttribute attr = field
.getAnnotation(ExcelVOAttribute.class);
try {
// 根据ExcelVOAttribute中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列.
if (attr.isExport()) {
cell = row.createCell(getExcelCol(attr.column()));// 创建cell
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(field.get(vo) == null ? ""
: String.valueOf(field.get(vo)));// 如果数据存在就填入,不存在填入空格.
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
try {
output.flush();
workbook.write(output);
output.close();
return true;
} catch (IOException e) {
e.printStackTrace();
System.out.println("Output is closed ");
return false;
}
}
/**
* 将EXCEL中A,B,C,D,E列映射成0,1,2,3
*
* @param col
*/
public static int getExcelCol(String col) {
col = col.toUpperCase();
// 从-1开始计算,字母重1开始运算。这种总数下来算数正好相同。
int count = -1;
char[] cs = col.toCharArray();
for (int i = 0; i < cs.length; i++) {
count += (cs[i] - 64) * Math.pow(26, cs.length - 1 - i);
}
return count;
}
/**
* 设置单元格上提示
*
* @param sheet
* 要设置的sheet.
* @param promptTitle
* 标题
* @param promptContent
* 内容
* @param firstRow
* 开始行
* @param endRow
* 结束行
* @param firstCol
* 开始列
* @param endCol
* 结束列
* @return 设置好的sheet.
*/
public static HSSFSheet setHSSFPrompt(HSSFSheet sheet, String promptTitle,
String promptContent, int firstRow, int endRow, int firstCol,
int endCol) {
// 构造constraint对象
DVConstraint constraint = DVConstraint
.createCustomFormulaConstraint("DD1");
// 四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList regions = new CellRangeAddressList(firstRow,
endRow, firstCol, endCol);
// 数据有效性对象
HSSFDataValidation data_validation_view = new HSSFDataValidation(
regions, constraint);
data_validation_view.createPromptBox(promptTitle, promptContent);
sheet.addValidationData(data_validation_view);
return sheet;
}
/**
* 设置某些列的值只能输入预制的数据,显示下拉框.
*
* @param sheet
* 要设置的sheet.
* @param textlist
* 下拉框显示的内容
* @param firstRow
* 开始行
* @param endRow
* 结束行
* @param firstCol
* 开始列
* @param endCol
* 结束列
* @return 设置好的sheet.
*/
public static HSSFSheet setHSSFValidation(HSSFSheet sheet,
String[] textlist, int firstRow, int endRow, int firstCol,
int endCol) {
// 加载下拉列表内容
DVConstraint constraint = DVConstraint
.createExplicitListConstraint(textlist);
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList regions = new CellRangeAddressList(firstRow,
endRow, firstCol, endCol);
// 数据有效性对象
HSSFDataValidation data_validation_list = new HSSFDataValidation(
regions, constraint);
sheet.addValidationData(data_validation_list);
return sheet;
}
}
@RequestMapping("/importOfficeExcel")
@ResponseBody
public JsonData importExcel(MultipartFile file) throws IOException {
CommonsMultipartFile cFile = (CommonsMultipartFile) file;
DiskFileItem fileItem = (DiskFileItem) cFile.getFileItem();
InputStream inputStream = fileItem.getInputStream();
ExcelUtil util = new ExcelUtil(ToolsList.class);// 创建excel工具类
List list = util.importExcel("Sheet1", inputStream);// 导入
for (int i = 0; i < list.size(); i++) {
int insertSelective = toolsListMapper.insertSelective(list.get(i));
}
System.out.println(list);
return JsonData.success(null, "上传成功");
}
@RequestMapping("/exportExcel")
@ResponseBody
public JsonData exportexcel(HttpServletResponse response,HttpServletRequest request,@RequestParam(value="time") String time,@RequestParam(value="semester") String semester,@RequestParam(value="professional") String professional) throws IOException
{
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
ToolsList toolsList=toolsListMapper.selectByTimeAndSemeterAndProfessional(time, semester, professional);
if(toolsList==null){
return JsonData.fail("没有数据");
}else{
// Create Blank workbook
XSSFWorkbook workbook = new XSSFWorkbook(); // 创建一个表
XSSFSheet xssfSheet = workbook.createSheet("空表");// 一个Sheet
xssfSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10));// 合并单元格
xssfSheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 4));
xssfSheet.addMergedRegion(new CellRangeAddress(1, 1, 6, 10));
XSSFCellStyle xssfCellStyle = workbook.createCellStyle();
xssfCellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);
XSSFRow xssfRow = xssfSheet.createRow((short) 0);// short0表示从第1行开始输出
xssfRow.createCell(0).setCellValue("济南大学泉城学院"+toolsList.getTime()+"年办公用品采购目录");// 第一行的第一列
xssfRow = xssfSheet.createRow((short) 1);// 第二行
xssfRow.createCell(0).setCellValue("单位:");// 第二行的第一列
xssfRow.createCell(6).setCellValue("人数:");
xssfRow = xssfSheet.createRow((short) 3);
xssfRow.createCell(0).setCellValue("名称");// 0代表第1列
xssfRow.createCell(1).setCellValue("单位");
xssfRow.createCell(2).setCellValue("单价");// double类型
xssfRow.createCell(3).setCellValue("数量");
xssfRow.createCell(4).setCellValue("金额");
xssfRow.createCell(6).setCellValue("名称");// 0代表列
xssfRow.createCell(7).setCellValue("单位");
xssfRow.createCell(8).setCellValue("单价");// double类型
xssfRow.createCell(9).setCellValue("数量");
xssfRow.createCell(10).setCellValue("金额");
xssfRow = xssfSheet.createRow((short) 4);
xssfRow.createCell(0).setCellValue("蓝圆珠笔");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.5);// 蓝圆珠笔的单价
xssfRow.createCell(3).setCellValue(toolsList.getLyzb());// 蓝圆珠笔的数量
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getLyzb())*0.5);// 蓝圆珠笔的数量
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);// 蓝圆珠笔的数量
}
xssfRow.createCell(6).setCellValue("胶水");// 0代表第1列
xssfRow.createCell(7).setCellValue("瓶");
xssfRow.createCell(8).setCellValue(1);// 胶水的单价
xssfRow.createCell(9).setCellValue(toolsList.getJiaoshui());// 胶水的数量
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getJiaoshui())*1);// 胶水的数量
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);// 胶水的数量
}
xssfRow = xssfSheet.createRow((short) 5);
xssfRow.createCell(0).setCellValue("红圆珠笔");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.5);
xssfRow.createCell(3).setCellValue(toolsList.getHyzb());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getHyzb())*0.5);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("胶棒");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(1);
xssfRow.createCell(9).setCellValue(toolsList.getJiaobang());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getJiaobang())*1);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 6);
xssfRow.createCell(0).setCellValue("蓝圆珠笔芯");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.1);
xssfRow.createCell(3).setCellValue(toolsList.getLyzbx());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getLyzbx())*0.1);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("橡皮");// 0代表第1列
xssfRow.createCell(7).setCellValue("块");
xssfRow.createCell(8).setCellValue(0.4);
xssfRow.createCell(9).setCellValue(toolsList.getXiangpi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getXiangpi())*0.4);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 7);
xssfRow.createCell(0).setCellValue("红圆珠笔芯");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.1);
xssfRow.createCell(3).setCellValue(toolsList.getHyzbx());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getHyzbx())*0.1);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("浆糊");// 0代表第1列
xssfRow.createCell(7).setCellValue("瓶");
xssfRow.createCell(8).setCellValue(1.5);
xssfRow.createCell(9).setCellValue(toolsList.getJianghu());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getJianghu())*1.5);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 8);
xssfRow.createCell(0).setCellValue("晨光0.5中性笔(黑)");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.8);
xssfRow.createCell(3).setCellValue(toolsList.getCgfivezxbh());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getCgfivezxbh())*0.8);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("墨汁");// 0代表第1列
xssfRow.createCell(7).setCellValue("瓶");
xssfRow.createCell(8).setCellValue(3);
xssfRow.createCell(9).setCellValue(toolsList.getMozhi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getMozhi())*3);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 9);
xssfRow.createCell(0).setCellValue("晨光0.5中性笔(红)");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.8);
xssfRow.createCell(3).setCellValue(toolsList.getCgfivezxbhong());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getCgfivezxbhong())*0.8);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("PU皮黑硬皮本");// 0代表第1列
xssfRow.createCell(7).setCellValue("本");
xssfRow.createCell(8).setCellValue(4.5);
xssfRow.createCell(9).setCellValue(toolsList.getPupiheiyingpiben());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getPupiheiyingpiben())*4.5);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 10);
xssfRow.createCell(0).setCellValue("晨光0.7中性笔");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(1.8);
xssfRow.createCell(3).setCellValue(toolsList.getCgsevenzxb());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getCgsevenzxb())*1.8);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("软皮本");// 0代表第1列
xssfRow.createCell(7).setCellValue("本");
xssfRow.createCell(8).setCellValue(1);
xssfRow.createCell(9).setCellValue(toolsList.getRuanpiben());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getRuanpiben())*1);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 11);
xssfRow.createCell(0).setCellValue("晨光1.0中性笔");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(1.8);
xssfRow.createCell(3).setCellValue(toolsList.getCgonezxb());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getCgonezxb())*1.8);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("速写本");// 0代表第1列
xssfRow.createCell(7).setCellValue("本");
xssfRow.createCell(8).setCellValue(3.5);
xssfRow.createCell(9).setCellValue(toolsList.getSuxieben());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getSuxieben())*3.5);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 12);
xssfRow.createCell(0).setCellValue("红蓝铅笔");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.3);
xssfRow.createCell(3).setCellValue(toolsList.getHlqb());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getHlqb())*0.3);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("红印尼");// 0代表第1列
xssfRow.createCell(7).setCellValue("盒");
xssfRow.createCell(8).setCellValue(2);
xssfRow.createCell(9).setCellValue(toolsList.getHongyinni());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getHongyinni())*2);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 13);
xssfRow.createCell(0).setCellValue("铅笔(2B)");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.5);
xssfRow.createCell(3).setCellValue(toolsList.getTwobqb());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getTwobqb())*0.5);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("转笔刀");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(1);
xssfRow.createCell(9).setCellValue(toolsList.getZhuanbidao());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getZhuanbidao())*1);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 14);
xssfRow.createCell(0).setCellValue("彩色铅笔");// 0代表第1列
xssfRow.createCell(1).setCellValue("盒");
xssfRow.createCell(2).setCellValue(3.5);
xssfRow.createCell(3).setCellValue(toolsList.getCsqb());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getCsqb())*3.5);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("壁纸刀");// 0代表第1列
xssfRow.createCell(7).setCellValue("把");
xssfRow.createCell(8).setCellValue(2);
xssfRow.createCell(9).setCellValue(toolsList.getBizhidao());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getBizhidao())*2);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 15);
xssfRow.createCell(0).setCellValue("白板笔");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(1);
xssfRow.createCell(3).setCellValue(toolsList.getBaibanbi());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getBaibanbi())*4);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("剪刀");// 0代表第1列
xssfRow.createCell(7).setCellValue("把");
xssfRow.createCell(8).setCellValue(2.5);
xssfRow.createCell(9).setCellValue(toolsList.getJiandao());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getJiandao())*2.5);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 16);
xssfRow.createCell(0).setCellValue("白板笔油");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(1.5);
xssfRow.createCell(3).setCellValue(toolsList.getBaibanbiyou());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getBaibanbiyou())*1.5);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("小刀");// 0代表第1列
xssfRow.createCell(7).setCellValue("把");
xssfRow.createCell(8).setCellValue(0.25);
xssfRow.createCell(9).setCellValue(toolsList.getXiaodao());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getXiaodao())*0.25);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 17);
xssfRow.createCell(0).setCellValue("晨光0.5中性笔芯(黑)");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.3);
xssfRow.createCell(3).setCellValue(toolsList.getChengguangwuzhongxingbixinhei());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getChengguangwuzhongxingbixinhei())*0.3);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("得力订书机");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(10);
xssfRow.createCell(9).setCellValue(toolsList.getDelidingshuji());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getDelidingshuji())*10);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 18);
xssfRow.createCell(0).setCellValue("晨光0.5中性笔芯(红)");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.3);
xssfRow.createCell(3).setCellValue(toolsList.getChengguangwuzhongxingbixinhong());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getChengguangwuzhongxingbixinhong())*0.3);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("得力订书钉");// 0代表第1列
xssfRow.createCell(7).setCellValue("盒");
xssfRow.createCell(8).setCellValue(1);
xssfRow.createCell(9).setCellValue(toolsList.getDelidingshuding());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getDelidingshuding())*1);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 19);
xssfRow.createCell(0).setCellValue("晨光0.7中性笔芯");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.45);
xssfRow.createCell(3).setCellValue(toolsList.getChenguangqizhongxingbixin());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getChenguangqizhongxingbixin())*0.45);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("计算器");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(12);
xssfRow.createCell(9).setCellValue(toolsList.getJisuanqi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getJisuanqi())*12);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 20);
xssfRow.createCell(0).setCellValue("晨光1.0中性笔芯");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(0.45);
xssfRow.createCell(3).setCellValue(toolsList.getChenguangyizhongxingbixin());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getChenguangyizhongxingbixin())*0.45);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("得力函数计算器");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(38);
xssfRow.createCell(9).setCellValue(toolsList.getDelihanshujisuanqi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getDelihanshujisuanqi())*38);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 21);
xssfRow.createCell(0).setCellValue("油性记号笔");// 0代表第1列
xssfRow.createCell(1).setCellValue("支");
xssfRow.createCell(2).setCellValue(1.8);
xssfRow.createCell(3).setCellValue(toolsList.getYouxingjihaobi());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getYouxingjihaobi())*1.8);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("口取纸");// 0代表第1列
xssfRow.createCell(7).setCellValue("张");
xssfRow.createCell(8).setCellValue(0.1);
xssfRow.createCell(9).setCellValue(toolsList.getKouquzhi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getKouquzhi())*0.1);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 22);
xssfRow.createCell(0).setCellValue("大信笺");// 0代表第1列
xssfRow.createCell(1).setCellValue("本");
xssfRow.createCell(2).setCellValue(0.75);
xssfRow.createCell(3).setCellValue(toolsList.getDaxinfa());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getDaxinfa())*0.75);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("塑料长直尺30cm");// 0代表第1列
xssfRow.createCell(7).setCellValue("把");
xssfRow.createCell(8).setCellValue(1.5);
xssfRow.createCell(9).setCellValue(toolsList.getSuliaochangzhichisanshi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getSuliaochangzhichisanshi())*1.5);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 23);
xssfRow.createCell(0).setCellValue("稿纸");// 0代表第1列
xssfRow.createCell(1).setCellValue("本");
xssfRow.createCell(2).setCellValue(0.75);
xssfRow.createCell(3).setCellValue(toolsList.getGaozhi());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getGaozhi())*0.75);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("塑料长直尺40cm");// 0代表第1列
xssfRow.createCell(7).setCellValue("把");
xssfRow.createCell(8).setCellValue(2);
xssfRow.createCell(9).setCellValue(toolsList.getSuliaochangzhichisishi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getSuliaochangzhichisishi())*2);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 24);
xssfRow.createCell(0).setCellValue("牛皮纸档案袋");// 0代表第1列
xssfRow.createCell(1).setCellValue("个");
xssfRow.createCell(2).setCellValue(0.4);
xssfRow.createCell(3).setCellValue(toolsList.getNiupizhidangandai());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getNiupizhidangandai())*0.4);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("得力长尾夹(大)");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(0.6);
xssfRow.createCell(9).setCellValue(toolsList.getDelichangweijiada());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getDelichangweijiada())*0.6);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 25);
xssfRow.createCell(0).setCellValue("塑料档案袋");// 0代表第1列
xssfRow.createCell(1).setCellValue("个");
xssfRow.createCell(2).setCellValue(0.8);
xssfRow.createCell(3).setCellValue(toolsList.getSuliaodangandai());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getSuliaodangandai())*0.8);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("得力长尾夹(中)");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(0.45);
xssfRow.createCell(9).setCellValue(toolsList.getDelichangweijiazhong());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getDelichangweijiazhong())*0.45);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 26);
xssfRow.createCell(0).setCellValue("透明窄胶带");// 0代表第1列
xssfRow.createCell(1).setCellValue("卷");
xssfRow.createCell(2).setCellValue(0.3);
xssfRow.createCell(3).setCellValue(toolsList.getToumingzhaijiaodai());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getToumingzhaijiaodai())*0.3);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("得力长尾夹(小)");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(0.25);
xssfRow.createCell(9).setCellValue(toolsList.getDelichangweijiaxiao());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getDelichangweijiaxiao())*0.25);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 27);
xssfRow.createCell(0).setCellValue("透明宽胶带");// 0代表第1列
xssfRow.createCell(1).setCellValue("卷");
xssfRow.createCell(2).setCellValue(3.5);
xssfRow.createCell(3).setCellValue(toolsList.getToumingkuangjiaodai());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getToumingkuangjiaodai())*3.5);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("5号南孚电池");// 0代表第1列
xssfRow.createCell(7).setCellValue("节");
xssfRow.createCell(8).setCellValue(1.8);
xssfRow.createCell(9).setCellValue(toolsList.getWuhaonanfudianchi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getWuhaonanfudianchi())*1.8);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 28);
xssfRow.createCell(0).setCellValue("双面窄胶带");// 0代表第1列
xssfRow.createCell(1).setCellValue("卷");
xssfRow.createCell(2).setCellValue(0.5);
xssfRow.createCell(3).setCellValue(toolsList.getShuangmianzhaijiaodai());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getShuangmianzhaijiaodai())*0.5);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("7号南孚电池");// 0代表第1列
xssfRow.createCell(7).setCellValue("节");
xssfRow.createCell(8).setCellValue(1.8);
xssfRow.createCell(9).setCellValue(toolsList.getQihaonanfudianchi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getQihaonanfudianchi())*1.8);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 29);
xssfRow.createCell(0).setCellValue("双面宽胶带");// 0代表第1列
xssfRow.createCell(1).setCellValue("卷");
xssfRow.createCell(2).setCellValue(1.2);
xssfRow.createCell(3).setCellValue(toolsList.getShuangmiankuanjiaodai());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getShuangmiankuanjiaodai())*1.2);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("9V双鹿电池");// 0代表第1列
xssfRow.createCell(7).setCellValue("节");
xssfRow.createCell(8).setCellValue(2.8);
xssfRow.createCell(9).setCellValue(toolsList.getJiufushuangludianchi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getJiufushuangludianchi())*2.8);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 30);
xssfRow.createCell(0).setCellValue("泡沫双面胶带");// 0代表第1列
xssfRow.createCell(1).setCellValue("卷");
xssfRow.createCell(2).setCellValue(1);
xssfRow.createCell(3).setCellValue(toolsList.getPaomoshuangmianjiaodai());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getPaomoshuangmianjiaodai())*1);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("得力回形针");// 0代表第1列
xssfRow.createCell(7).setCellValue("盒");
xssfRow.createCell(8).setCellValue(1);
xssfRow.createCell(9).setCellValue(toolsList.getDelihuixingzhen());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getDelihuixingzhen())*1);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 31);
xssfRow.createCell(0).setCellValue("大红纸");// 0代表第1列
xssfRow.createCell(1).setCellValue("张");
xssfRow.createCell(2).setCellValue(0.4);
xssfRow.createCell(3).setCellValue(toolsList.getDahongzhi());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getDahongzhi())*0.4);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("得力起钉器");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(1.8);
xssfRow.createCell(9).setCellValue(toolsList.getDeliqidingqi());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getDeliqidingqi())*1.8);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 32);
xssfRow.createCell(0).setCellValue("宣纸");// 0代表第1列
xssfRow.createCell(1).setCellValue("张");
xssfRow.createCell(2).setCellValue(0.5);
xssfRow.createCell(3).setCellValue(toolsList.getXuanzhi());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getXuanzhi())*0.5);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("塑料文件架");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(9.5);
xssfRow.createCell(9).setCellValue(toolsList.getSuliaowenjianjia());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getSuliaowenjianjia())*9.5);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 33);
xssfRow.createCell(0).setCellValue("3.5得力档案盒");// 0代表第1列
xssfRow.createCell(1).setCellValue("个");
xssfRow.createCell(2).setCellValue(6);
xssfRow.createCell(3).setCellValue(toolsList.getSanwudelidanganhe());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getSanwudelidanganhe())*6);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("塑料笔筒");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(5);
xssfRow.createCell(9).setCellValue(toolsList.getSuliaobitong());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getSuliaobitong())*5);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 34);
xssfRow.createCell(0).setCellValue("5.5得力档案盒");// 0代表第1列
xssfRow.createCell(1).setCellValue("个");
xssfRow.createCell(2).setCellValue(8);
xssfRow.createCell(3).setCellValue(toolsList.getWuwudelidanganhe());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getWuwudelidanganhe())*8);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("木质笔筒");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(9);
xssfRow.createCell(9).setCellValue(toolsList.getMuzhibitong());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getMuzhibitong())*9);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 35);
xssfRow.createCell(0).setCellValue("文件夹");// 0代表第1列
xssfRow.createCell(1).setCellValue("个");
xssfRow.createCell(2).setCellValue(3.2);
xssfRow.createCell(3).setCellValue(toolsList.getWenjianjia());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getWenjianjia())*3.2);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("1.8米插排");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(28);
xssfRow.createCell(9).setCellValue(toolsList.getYidianbamichapai());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getYidianbamichapai())*28);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 36);
xssfRow.createCell(0).setCellValue("A4抽杆夹");// 0代表第1列
xssfRow.createCell(1).setCellValue("个");
xssfRow.createCell(2).setCellValue(1);
xssfRow.createCell(3).setCellValue(toolsList.getAsichouganjia());
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getAsichouganjia())*1);
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);
}
xssfRow.createCell(6).setCellValue("3米插排");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(38);
xssfRow.createCell(9).setCellValue(toolsList.getSanmichapai());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getSanmichapai())*38);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
xssfRow = xssfSheet.createRow((short) 37);
xssfRow.createCell(0).setCellValue("锥子");// 0代表第1列
xssfRow.createCell(1).setCellValue("把");
xssfRow.createCell(2).setCellValue(1);
xssfRow.createCell(3).setCellValue(toolsList.getZhuizi());//没找到对应的字段
try {
xssfRow.createCell(4).setCellValue(Integer.parseInt(toolsList.getZhuizi())*1);//没找到对应的字段
} catch (NumberFormatException e) {
xssfRow.createCell(4).setCellValue(0);//没找到对应的字段
}
xssfRow.createCell(6).setCellValue("5米插排");// 0代表第1列
xssfRow.createCell(7).setCellValue("个");
xssfRow.createCell(8).setCellValue(48);
xssfRow.createCell(9).setCellValue(toolsList.getWumichapai());
try {
xssfRow.createCell(10).setCellValue(Integer.parseInt(toolsList.getWumichapai())*48);
} catch (NumberFormatException e) {
xssfRow.createCell(10).setCellValue(0);
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = new Date();
String dateString = formatter.format(date);
// Create file system using specific name
String path=request.getSession().getServletContext().getRealPath("/");
System.out.println(path);
FileOutputStream out = new FileOutputStream(new File(path+dateString+"办公用品.xlsx"));// 先在本地生成文件
// write operation workbook using file out object
workbook.write(out);
out.close();
return JsonData.success(dateString+"办公用品.xlsx");
}
}