1: EAS 自制导出功能
@Override
public void actionExportASN_actionPerformed(ActionEvent e) throws Exception {
int result = MsgBox.showConfirm2("===是否导出ASN===");
if(MsgBox.OK==result){
KDFileChooser fileChooser = new KDFileChooser();
fileChooser.setDialogTitle("选择导出路径");
fileChooser.setFileFilter(new ExcelFileFilter());
//fileChooser.showSaveDialog(this);
int customResult = fileChooser.showSaveDialog(this);
if(0==customResult){
//MsgBox.showConfirm2(fileChooser.getSelectedFile()+"");
String path = fileChooser.getSelectedFile()+"";
exportASNExcel(path,editData.getId().toString());
}else{
MsgBox.showConfirm2("======导出失败,请联系管理员======");
}
//int d=fileChooser.showDialog(this, "导出");
//MsgBox.showInfo(d+"");
}
// else{
// MsgBox.showInfo("不是");
// }
}
/**
* 导出Excel
* @param path
* @param string
* @throws Exception
* @throws BOSException
* @throws EASBizException
*/
private void exportASNExcel(String path, String id) throws EASBizException, BOSException, Exception {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("ASN");
HSSFRow row = sheet.createRow((int) 0);
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
initHeadCell(row,style);
//写入实体数据 实际应用中这些数据从数据库得到,
List list = ((ICustomInformation) getBizInterface()).getASNResult(id);
for (int i = 0; i < list.size(); i++){
ASNInfo asnInfo = (ASNInfo)list.get(i);
row = sheet.createRow((int) i + 1);
row.createCell(0).setCellValue(asnInfo.getAsnType());
row.createCell(1).setCellValue(asnInfo.getSupplierName());
row.createCell(2).setCellValue(asnInfo.getSupplierPartNo());
row.createCell(3).setCellValue(asnInfo.getCustomerName());
row.createCell(4).setCellValue(asnInfo.getCustomerPartNo());
row.createCell(5).setCellValue(asnInfo.getMfr());
row.createCell(6).setCellValue(asnInfo.getShippingQty().doubleValue());
row.createCell(7).setCellValue(asnInfo.getPrice().doubleValue());
row.createCell(8).setCellValue(asnInfo.getCurrency());
row.createCell(9).setCellValue(asnInfo.getCountryOfOriginal());
row.createCell(10).setCellValue(new SimpleDateFormat("yyyy/MM/dd").format(asnInfo.getEta()));
row.createCell(11).setCellValue(asnInfo.getInvoiceNo());
if(asnInfo.getGrossWeight()==null){
row.createCell(12).setCellValue("");
}else{
row.createCell(12).setCellValue(asnInfo.getGrossWeight().doubleValue());
}
if(asnInfo.getCartonQty()==null){
row.createCell(13).setCellValue("");
}else{
row.createCell(13).setCellValue(asnInfo.getCartonQty().doubleValue());
}
if(asnInfo.getPalletQty()==0){
row.createCell(14).setCellValue("");
}else{
row.createCell(14).setCellValue(asnInfo.getPalletQty());
}
row.createCell(15).setCellValue(asnInfo.getCustomerPO());
row.createCell(16).setCellValue(asnInfo.getCustomerPOItem());
row.createCell(17).setCellValue(asnInfo.getPartnerReferenceNo());
row.createCell(18).setCellValue(asnInfo.getForwarderName());
row.createCell(19).setCellValue(asnInfo.getSupplierPackName());
row.createCell(20).setCellValue(asnInfo.getXOut());
row.createCell(21).setCellValue(asnInfo.getOwnershipType());
}
try
{
FileOutputStream fout = new FileOutputStream(path+".xls");
wb.write(fout);
fout.close();
}
catch (Exception e)
{
e.printStackTrace();
MsgBox.showInfo("======导出失败======");
}
MsgBox.showInfo("======导出成功======");
}