public void totalImport(HttpServletRequest request,HttpServletResponse response,ServletConfig config,String path){
HttpSession session=request.getSession();
SpecJ specjdto=(SpecJ)session.getAttribute("specJdto");
List list=(List)session.getAttribute("getList");
int i=0;
int j=0;
File file = new File("D://total.xls");
if (file.exists()) {
file.delete();
}
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int temp_row = 6;
try {
OutputStream os=new FileOutputStream(file);
WritableWorkbook wwb = Workbook.createWorkbook(os);
WritableSheet ws = wwb.createSheet("出口玩具產品所使用塗料等危險化學品台帳", 0);
Label labelC0 = new Label(5, 0, "出口玩具產品所使用塗料等危險化學品台帳");
ws.addCell(labelC0);
Label labelC1 = new Label(0, 2, "入库日期");
Label labelC2 = new Label(1, 2, "原色油名");
Label labelC3 = new Label(2, 2, "原油編號");
Label labelC4 = new Label(3, 2, "原油批號");
Label labelC5 = new Label(4, 2, "品牌");
Label labelC6 = new Label(5, 2, "供应商");
Label labelC7 = new Label(6, 2, "產地");
Label labelC8 = new Label(7, 2, "入库数量");
Label labelC9 = new Label(8, 2, "檢測機構");
Label labelC10 = new Label(9, 2, "檢測報告");
Label labelC11 = new Label(10, 2, "檢項");
ws.addCell(labelC1);
ws.addCell(labelC2);
ws.addCell(labelC3);
ws.addCell(labelC4);
ws.addCell(labelC5);
ws.addCell(labelC6);
ws.addCell(labelC7);
ws.addCell(labelC8);
ws.addCell(labelC9);
ws.addCell(labelC10);
ws.addCell(labelC11);
Label labelD0 = new Label(0, 3, specjdto.getDateJ());
Label labelD1 = new Label(1, 3, "原色油");
Label labelD2 = new Label(2, 3, specjdto.getPaintNo());
Label labelD3 = new Label(3, 3, specjdto.getBatchNo());
Label labelD4 = new Label(4, 3, "/");
Label labelD5 = new Label(5, 3, "WS");
Label labelD6 = new Label(6, 3, "China");
Label labelD7 = new Label(7, 3, new Float(specjdto.getQuantity()).toString());
Label labelD8 = new Label(8, 3, specjdto.getOrg());
Label labelD9 = new Label(9, 3, specjdto.getFileA());
Label labelD10 = new Label(10, 3, new Integer(specjdto.getIndexA()).toString());
ws.addCell(labelD0);
ws.addCell(labelD1);
ws.addCell(labelD2);
ws.addCell(labelD3);
ws.addCell(labelD4);
ws.addCell(labelD5);
ws.addCell(labelD6);
ws.addCell(labelD7);
ws.addCell(labelD8);
ws.addCell(labelD9);
ws.addCell(labelD10);
Label labelE1 = new Label(0, 5, "入库日期");
Label labelE2 = new Label(1, 5, "配油編號");
Label labelE3 = new Label(2, 5, "配油批號");
Label labelE4 = new Label(3, 5, "生產配油量(KG)");
Label labelE5 = new Label(4, 5, "領用原油量(KG)");
Label labelE6 = new Label(5, 5, "剩余原油量(KG)");
Label labelE7 = new Label(6, 5, "領用人");
Label labelE8 = new Label(7, 5, "發料人");
Label labelE9 = new Label(8, 5, "生产日期");
Label labelE10 = new Label(9, 5, "部件名");
Label labelE11 = new Label(10, 5, "部件編號");
Label labelE12 = new Label(11, 5, "生產量(個)");
Label labelE13 = new Label(12, 5, "追蹤號");
Label labelE14 = new Label(13, 5, "使用配油量(KG)");
Label labelE15 = new Label(14, 5, "工場最終庫存(KG)");
ws.addCell(labelE1);
ws.addCell(labelE2);
ws.addCell(labelE3);
ws.addCell(labelE4);
ws.addCell(labelE5);
ws.addCell(labelE6);
ws.addCell(labelE7);
ws.addCell(labelE8);
ws.addCell(labelE9);
ws.addCell(labelE10);
ws.addCell(labelE11);
ws.addCell(labelE12);
ws.addCell(labelE13);
ws.addCell(labelE14);
ws.addCell(labelE15);
Iterator it = list.iterator();
while (it.hasNext()) {
Total total=(Total)it.next();
Label labelF1 = new Label(0, temp_row, total.getDateS());
Label labelF2 = new Label(1, temp_row, total.getPaintNo());
Label labelF3 = new Label(2, temp_row, total.getBatchNo());
String getQuantity="";
if (total.getQuantity()== 0.0){
getQuantity="";
}else {
getQuantity=new Float(total.getQuantity()).toString();
}
Label labelF4 = new Label(3, temp_row, getQuantity);
String getJustQuantity="";
if (total.getJustQuantity()== 0.0){
getJustQuantity="";
}else {
getJustQuantity=new Float(total.getJustQuantity()).toString();
}
Label labelF5 = new Label(4, temp_row, getJustQuantity);
String getTiaoQuantity="";
if (total.getJustQuantity()== 0.0&&total.getQuantity()==0.0){
getTiaoQuantity="";
}else {
getTiaoQuantity=new Float(total.getTiaoQuantity()).toString();
}
Label labelF6 = new Label(5, temp_row, getTiaoQuantity);
Label labelF7 = new Label(6, temp_row, total.getUserName());
Label labelF8 = new Label(7, temp_row, total.getSendName());
Label labelF9 = new Label(8, temp_row, total.getBdate());
Label labelF10 = new Label(9, temp_row, total.getBname());
Label labelF11 = new Label(10, temp_row, total.getBid());
String getBnum="";
if (total.getBnum()== 0.0){
getBnum="";
}else {
getBnum=new Float(total.getBnum()).toString();
}
Label labelF12 = new Label(11, temp_row, getBnum);
Label labelF13 = new Label(12, temp_row, total.getStrace());
String getSuse="";
if (total.getSuse()== 0.0){
getSuse="";
}else {
getSuse=new Float(total.getSuse()).toString();
}
Label labelF14 = new Label(13, temp_row, getSuse);
String getSstore="";
if ((total.getSnum()==total.getSuse())&&(total.getSuse()!=0.0)){
getSstore=new Float(0.0).toString();
}else if(total.getSuse()==0.0){
getSstore="";
}else if(total.getSstore()==0&&(total.getSnum()!=total.getSuse())){
getSstore="";
}else {
getSstore=new Float(total.getSstore()).toString();
}
Label labelF15 = new Label(14, temp_row, getSstore);
ws.addCell(labelF1);
ws.addCell(labelF2);
ws.addCell(labelF3);
ws.addCell(labelF4);
ws.addCell(labelF5);
ws.addCell(labelF6);
ws.addCell(labelF7);
ws.addCell(labelF8);
ws.addCell(labelF9);
ws.addCell(labelF10);
ws.addCell(labelF11);
ws.addCell(labelF12);
ws.addCell(labelF13);
ws.addCell(labelF14);
ws.addCell(labelF15);
temp_row++;
}
wwb.write(); // 写入文件
wwb.close();
os.flush();
os.close();
} catch (Exception e) {
System.out.println(e.toString());
}
//直接打开XLS文件:
try {
Runtime.getRuntime().exec("cmd /c start d://total.xls");
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e.toString());
}
//下载XLS文件:
// SmartUpload su = new SmartUpload();
// try {
// su.initialize(config,request,response);
// su.setContentDisposition(null);
// su.downloadFile(path);
//
// } catch (ServletException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }catch (SmartUploadException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}