JXL生成excel實戰

2021-09-02 03:24:58 字數 2442 閱讀 6672

需求:

完成乙個簡單excel的生成和匯出

前台**:

var flightstart = $("#flightdate1").val();

var flightend = $("#flightdate2").val();

var segment = $("#segment").val();

var flightno = $("#flightno").val();

var isauto = $("#isauto").val();

var iseffect = $("#iseffect").val();

var autocap = $("#autocap").val();

var  requestpath =   "<%=path%>/pwr/assist/exportthreshold.action?spetype.iseffect="+iseffect+"&spetype.isauto="+isauto ;

if(flightstart!="" && flightstart!= null)

if(flightend!="" && flightend!= null)

if(segment!="" && segment!= null)

if(flightno!="" && flightno!= null)

if(autocap!="" && autocap!= null)   

form1.action= requestpath ;

$("#form1").submit();              

後台**:

speflighttype speflighttype = null ;

for (int j = 0 ; j < resultlist.size() ; j ++)

if(threshkezuoentity.gettimespan2()!=null)                    

wsheet.addcell(new label(k++, i, comparedate));

wsheet.addcell(new label(k++, i, threshkezuoentity.getincludeairline()));

if("1".equals(threshkezuoentity.getratetype()) )else if("2".equals(threshkezuoentity.getratetype()) )else if("3".equals(threshkezuoentity.getratetype()) )

wsheet.addcell(new label(k++, i,threshkezuoentity.getdiscountrange() ));

wsheet.addcell(new label(k++, i,threshkezuoentity.getdiscount() ));

wsheet.addcell(new label(k++, i,threshkezuoentity.getweek() ));

wsheet.addcell(new label(k++, i,threshkezuoentity.getaheaddate() ));

wsheet.addcell(new label(k++, i, "1".equals(threshkezuoentity.getiseffect()) ? "生效":"未生效")); 

i++;}}

//同比子閥值寫入excel

if(tblist.size()>0)

}if(tblist.size() == 0 && kzlist.size()==0)

}speflighttype = null;

log.info("export into excel success  and has "+ i +" row export. ");

} // 主體內容生成結束          

wbook.write(); // 寫入檔案  

wbook.close(); 

os.close(); // 關閉流

return null;

} catch(exception ex)

}/**

* * @param wsheet 

* @param i 傳入寫到第幾行

* @param speflighttype

* @param type

* @return 返回已經寫到excel的第幾列

* @throws row***ceededexception

* @throws writeexception

* */

private int createnewline(writablesheet wsheet , int i , speflighttype speflighttype , string type) throws row***ceededexception, writeexception

利用jxl生成excel檔案

工程進行的差不多了,這兩天正在做excel相關的工作。鬱悶壞了,不知道為什麼eclipse老是提示輸出的方法已經被呼叫,明明只寫excel標題的時候可以生成的,在csdn上搜了半天,終於找到原因。下面是一位老兄的例子 匯出某個object陣列的內容到excel public static boole...

用jxl來生成Excel

file file new file xx xx xls if file.getparentfile exists workbook wb null 用來獲取工作簿 writableworkbook wwb null 建立工作簿 writablesheet sheet0 null sheet if ...

通過JXL生成Excel報表!

最近做專案中,中間有乙個功能是用 jxl外掛程式生成 excel 報表,因為之前沒有弄過這些,所以都是從網上找一些資料 文件現學。現在功能已經做完了,就整理了一下,留著自己以後看,以免忘記 廢話不多話,直接上 建立乙個 excel 檔案 string path d report.xls fileou...