POI를 Excel로 내보내기
9687 단어 Excel
if (billForm.getButtonName() != null) {
if(billForm.getButtonName().equals("export")){
System.out.println("-------------------export start--------------------");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow((short) 0);
HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 6);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 7);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 8);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 9);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 10);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 11);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(WtPepBillpay.class);
detachedCriteria.createAlias("id", "id");
String start = billForm.getDateStart();
String end = billForm.getDateEnd();
String remitName=billForm.getRemitName();//
String bankName=billForm.getBankName();//
String termid=billForm.getTermid();//
String zonePhone=billForm.getZonePhone();//
String payCode = billForm.getPayCodeSelect();//
if(StringUtils.isNotEmpty(start)&&StringUtils.isNotEmpty(end)){
detachedCriteria.add(Restrictions.between(WtPepBillpay.PEPDATE, start, end));
billForm.setDateStart("");//
billForm.setDateEnd("");//
}
if (StringUtils.isNotEmpty(bankName)) {
String temp = bankName.trim();
// detachedCriteria.add(Restrictions.between(WtPepBillpay.BANKNAME, billForm.getBankName().trim(), temp));
String keyWord="%" + temp + "%";
detachedCriteria.add(Restrictions.like(WtPepBillpay.BANKNAME, keyWord));
billForm.setBankName("");//
}
if (StringUtils.isNotEmpty(termid)) {
String temp = termid.trim();
// detachedCriteria.add(Restrictions.between(WtPepBillpay.TERMID, billForm.getTermid().trim(), temp));
String keyWord="%" + temp + "%";
detachedCriteria.add(Restrictions.like(WtPepBillpay.BANKNAME, keyWord));
billForm.setTermid("");//
}
if (StringUtils.isNotEmpty(zonePhone)) {
if(zonePhone.indexOf("-")!=-1){
String[] splitArray = zonePhone.split("-");
String zone = splitArray[0].trim();
String phone = splitArray[1].trim();
// detachedCriteria.add(Restrictions.between(WtPepBillpay.ZONE, splitArray[0].trim(), temp0));
// detachedCriteria.add(Restrictions.between(WtPepBillpay.PHONE, splitArray[1].trim(), temp1));
String keyWord0="%" + zone + "%";
String keyWord1="%" + phone + "%";
detachedCriteria.add(Restrictions.like(WtPepBillpay.ZONE, keyWord0));
detachedCriteria.add(Restrictions.like(WtPepBillpay.PHONE, keyWord1));
}else{
String temp = zonePhone.trim();
// detachedCriteria.add(Restrictions.between(WtPepBillpay.PHONE, billForm.getZonePhone().trim(), temp));
String keyWord="%" + temp + "%";
detachedCriteria.add(Restrictions.like(WtPepBillpay.PHONE, keyWord));
}
billForm.setZonePhone("");//
}
if (payCode!=null){
if(payCode.equals("SS")){
}else if(payCode.equals("00")){//00
detachedCriteria.add(Restrictions.eq(WtPepBillpay.BILLPAYCODE, "00"));
}
else if(payCode.equals("FF")){
detachedCriteria.add(Restrictions.eq(WtPepBillpay.BILLPAYCODE, "FF"));
}
}
//
detachedCriteria.addOrder(Order.desc("pepdate"));
detachedCriteria.addOrder(Order.desc("peptime"));
List exportList = this.getBillService().getListByCriteria(detachedCriteria);
System.out.println("exportList.size="+exportList.size());
Iterator itr = exportList.iterator();
WtPepBillpay wtp;
short rowNum = 1;
String temp = "";
while (itr.hasNext()) {
wtp = (WtPepBillpay) itr.next();
row = sheet.createRow(rowNum);
cell = row.createCell((short) 0);
cell.setCellValue(wtp.getTermid());
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(" ");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(wtp.getBankName());
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(wtp.getBankCard());
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
if (wtp.getOpeningBank()== null || wtp.getOpeningBank().equals(""))
wtp.setOpeningBank("—");
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(wtp.getOpeningBank());
cell = row.createCell((short) 5);
temp = wtp.getPepdate().substring(0, 4) + "-"
+ wtp.getPepdate().substring(4, 6) + "-"
+ wtp.getPepdate().substring(6, 8);
cell.setCellValue(temp);
cell = row.createCell((short) 6);
/*temp = Integer.parseInt(wtp.getTranamt().substring(
0, 10))
+ "." + wtp.getTranamt().substring(10, 12);*/
temp = "¥" + Util.FormatSum(wtp.getTranamt());//modify for NumberFormatException
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(temp);
cell = row.createCell((short) 7);
temp = "¥" + Util.FormatSum(wtp.getFee().trim());
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(temp);
cell = row.createCell((short) 8);
long total = Long.parseLong(wtp.getTranamt())+Long.parseLong(Util.KillZero(wtp.getFee().trim()));
temp = "¥" + Util.FormatSum(String.valueOf(total));
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(temp);
cell = row.createCell((short) 9);
if(wtp.getZone()!=null){
cell.setCellValue(wtp.getZone().trim() + "-"
+ wtp.getPhone());
}else{
cell.setCellValue(wtp.getPhone());
}
cell = row.createCell((short) 10);
if (!wtp.getBillPaycode().equals("00")){
temp = "—";
}else{
temp = wtp.getPayCard();
}
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(temp);
cell = row.createCell((short) 11);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
if (wtp.getBillPaycode().equals("00"))
temp = " ";
else
temp = " ";
cell.setCellValue(temp);
rowNum++;
}
try {
response.setContentType("octets/stream");
response.addHeader("Content-Disposition",
"attachment;filename=today.xls");
OutputStream fileOut = response.getOutputStream();
wb.write(fileOut);
fileOut.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("--------------------export end------------------------");
return null;//add for "cannot forward after response has been commit"
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Excel Grep toolExcel Grep tool ■히나가타 ■ 시트 구성 ExcelGrep.cls...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.