jfinal jxl 导出上传excel

jfinal  注意下载是renderNull(); 且前台不能用$jaxa  ,可用 window.open



public void imp() {

String dqid = getPara("dqid");
Frame jf = null;
FileDialog fdopen = new FileDialog(jf, "打开", FileDialog.LOAD);// 框属性为"LOAD加载",附于JFrame对象
fdopen.setVisible(true);
String name = fdopen.getFile();
String path = fdopen.getDirectory() + name;
try
{


Workbook rwb = Workbook.getWorkbook(new File(path));
Sheet rs = rwb.getSheet(0);// 或者rwb.getSheet(0)
int clos = rs.getColumns();// 得到所有的列
int row = rs.getRows();// 得到所有的行
List<String> xxmc=null;
int count=0;


for (int i = 1; i < row; i++) {
for (int j = 0; j < clos; j++) {
// 第一个是列数,第二个是行数
Org org = new Org();
org.set("ACTIVE_FLAG", KdConst.ORG_QYZT);
org.set("DEPTTYPE", KdConst.ORG_LX);
org.set("DQID", dqid);


String jgmc = rs.getCell(j++, i).getContents();
if (jgmc == null)
jgmc = "";
else
jgmc = jgmc.replaceAll(" ", "").replaceAll("\\s", "");
org.set("JGMC", jgmc);


String jgdm = rs.getCell(j++, i).getContents();
if (jgdm == null)
jgdm = "";
else
jgdm = jgdm.replaceAll(" ", "").replaceAll("\\s", "");
org.set("JGDM", jgdm);
String jgjc = rs.getCell(j++, i).getContents();
if (jgjc == null)
jgjc = "";
else
jgjc = jgmc.replaceAll(" ", "").replaceAll("\\s", "");
org.set("JGJC", jgjc);
   Org namelist=Org.me.findById("jgdm");
   String njgmc =namelist.getStr("jgmc") ;
   org.save();
   i++;


   if(name!=null||!("").equals(name))
   {
    xxmc.add(name);
   }

}
}
if(xxmc.size()>0)
{
setAttr("msg", "期中[" + xxmc + "] 等"+ xxmc.size()+"导入失败,请确认其是否已经录入系统中!");
}
else
{
setAttr("msg", "同步成功!");

}
render(new JsonRender().forIE());
}
catch (Exception e) {
e.printStackTrace();
setAttr("msg", "导入失败,请联系技术支持!");










}




public void exp() {
String dqid = getPara("dqid");
Area name = Area.me.findById(dqid);
OutputStream os = null;
WritableWorkbook wb = null;
String fileName = name.getStr("name") + "学校编码维护表";
try {
getResponse().reset();


getResponse().setCharacterEncoding("GBK");
getResponse().setContentType("application/msexcel");
getResponse().setHeader(
"content-disposition",
"attachment;filename="
+ java.net.URLEncoder.encode(fileName, "UTF-8")
+ ".xls");
os = getResponse().getOutputStream();
wb = jxl.Workbook.createWorkbook(os);


WritableSheet sheet = wb.createSheet("学校编码维护表", 0);
Label label = new Label(0, 0, "");
sheet.addCell(label);
int col = 0;
int line = 0;


label = new Label(col++, line, "学校名称"); // line 9 col 0 BJDM
sheet.addCell(label);
label = new Label(col++, line, "学校编码");
sheet.addCell(label);
label = new Label(col++, line, "学校简称");
sheet.addCell(label);
label = new Label(col++, line, "IP");
sheet.addCell(label);
int headerLines = 1;
List<Org> list = Org.me.getOrgByDqid(dqid);
String orglist = gson.toJson(toOrgMapList(list));
JSONArray array = JSONArray.fromObject(orglist);


String[] list1 = { "jgmc", "jgdm", "jgjc" };
for (int i = 0; list != null && i < array.size(); i++) {
JSONObject orgjson = JSONObject.fromObject(array.get(i));
for (int j = headerLines - 1; j < list1.length; j++) {
label = new Label(j - headerLines + 1, i + headerLines,
orgjson.getString(list1[j]));
sheet.addCell(label);
}
}


if (wb != null) {
wb.write();
wb.close();
}
if (os != null) {
os.flush();
os.close();
os = null;
}


} catch (Exception e) {
e.printStackTrace();
setAttr("msg", "下载,请联系技术支持!");
} finally {
renderNull();


}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值