![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiAzNfRHLGZkRGZkRfJ3bs92YsYTMfVmepNHL9kEROpXTU1keBRVT3V1MMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnLyAjNyMDNyETM0ITOwkTMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
選擇多個檔案 需要設定屬性 setMultiSelectionEnabled(true); 預設是單選。
JFileChooser dialog = new JFileChooser(); dialog.setMultiSelectionEnabled(true);
單表導入
try {
JFileChooser dialog = new JFileChooser();
dialog.setDialogTitle("打開");
dialog.setMultiSelectionEnabled(true);
dialog.setFileSelectionMode(JFileChooser.FILES_ONLY);
dialog.setDialogType(JFileChooser.SAVE_DIALOG);
dialog.setFileFilter(new FileNameExtensionFilter("Excel檔案", "xlsx"));
if(dialog.showSaveDialog(new JLabel()) == JFileChooser.APPROVE_OPTION){
File[] files = dialog.getSelectedFiles();
AggAssesVO[] aggvoList = new AggAssesVO[files.length];
for(int i = 0;i<files.length;i++){
//建立單表包裝類
AggAssesVO aggvo = new AggAssesVO();
File file = files[i];
//得到檔案全名
String filePath = file.getAbsolutePath();
//得到檔案輸入流
FileInputStream is = new FileInputStream(filePath);
//獲得Excel
//HSSFWorkbook workbook = new HSSFWorkbook(is); 這個是針對 xls檔案
XSSFWorkbook workbook = new XSSFWorkbook(is);
//獲得第一個Excel表格,為登出核準主表
XSSFSheet sheet1 = workbook.getSheetAt(0);
if(null==sheet1 ){
ExceptionUtils.wrappBusinessException("請檢查導入資料!");
}
//擷取查詢方法公共類
HYPubBO hyb = new HYPubBO();
int lastRow1 = sheet1.getLastRowNum();
//取第一個工作簿主表資料
XSSFRow row1 = sheet1.getRow(1);
AssesVO parentVO = new AssesVO();
String pk_org = null;
if(null!=row1.getCell(0) && row1.getCell(0).getCellType() != Cell.CELL_TYPE_BLANK){
pk_org = getCellValue(row1.getCell((short) 0));
}
String assess_tar = null;
if(null!=row1.getCell(1) && row1.getCell(1).getCellType() != Cell.CELL_TYPE_BLANK){
assess_tar = getCellValue(row1.getCell((short) 1));
}
String proholder = null;
if(null!=row1.getCell(2) && row1.getCell(2).getCellType() != Cell.CELL_TYPE_BLANK){
proholder = getCellValue(row1.getCell((short) 2));
}
String emlev = null;
if(null!=row1.getCell(3) && row1.getCell(3).getCellType() != Cell.CELL_TYPE_BLANK){
emlev = getCellValue(row1.getCell((short)3));
}
String apno = null;
if(null!=row1.getCell(4) && row1.getCell(4).getCellType() != Cell.CELL_TYPE_BLANK){
apno = getCellValue(row1.getCell((short)4));
}
String pfno = null;
if(null!=row1.getCell(5) && row1.getCell(5).getCellType() != Cell.CELL_TYPE_BLANK){
pfno = getCellValue(row1.getCell((short)5));
}
String aec = null;
if(null!=row1.getCell(6) && row1.getCell(6).getCellType() != Cell.CELL_TYPE_BLANK){
aec = getCellValue(row1.getCell((short)6));
}
String investmentcom = null;
if(null!=row1.getCell(7) && row1.getCell(7).getCellType() != Cell.CELL_TYPE_BLANK){
investmentcom = getCellValue(row1.getCell((short)7));
}
String ea_type = null;
if(null!=row1.getCell(8) && row1.getCell(8).getCellType() != Cell.CELL_TYPE_BLANK){
ea_type = getCellValue(row1.getCell((short)8));
}
String e_method = null;
if(null!=row1.getCell(9) && row1.getCell(9).getCellType() != Cell.CELL_TYPE_BLANK){
e_method = getCellValue(row1.getCell((short)9));
}
String er_no = null;
if(null!=row1.getCell(10) && row1.getCell(10).getCellType() != Cell.CELL_TYPE_BLANK){
er_no = getCellValue(row1.getCell((short)10));
}
String ea_name = null;
if(null!=row1.getCell(11) && row1.getCell(11).getCellType() != Cell.CELL_TYPE_BLANK){
ea_name = getCellValue(row1.getCell((short)11));
}
String certificationsno = null;
if(null!=row1.getCell(12) && row1.getCell(12).getCellType() != Cell.CELL_TYPE_BLANK){
certificationsno = getCellValue(row1.getCell((short)12));
}
String a_institution = null;
if(null!=row1.getCell(13) && row1.getCell(13).getCellType() != Cell.CELL_TYPE_BLANK){
a_institution = getCellValue(row1.getCell((short)13));
}
String aa_name = null;
if(null!=row1.getCell(14) && row1.getCell(14).getCellType() != Cell.CELL_TYPE_BLANK){
aa_name = getCellValue(row1.getCell((short)14));
}
String aa_no = null;
if(null!=row1.getCell(15) && row1.getCell(15).getCellType() != Cell.CELL_TYPE_BLANK){
aa_no = getCellValue(row1.getCell((short)15));
}
String phc = null;
if(null!=row1.getCell(16) && row1.getCell(16).getCellType() != Cell.CELL_TYPE_BLANK){
phc = getCellValue(row1.getCell((short)16));
}
String phc_tel = null;
if(null!=row1.getCell(17) && row1.getCell(17).getCellType() != Cell.CELL_TYPE_BLANK){
phc_tel = getCellValue(row1.getCell((short)17));
}
String phc_address = null;
if(null!=row1.getCell(18) && row1.getCell(18).getCellType() != Cell.CELL_TYPE_BLANK){
phc_address = getCellValue(row1.getCell((short)18));
}
String fcc = null;
if(null!=row1.getCell(19) && row1.getCell(19).getCellType() != Cell.CELL_TYPE_BLANK){
fcc = getCellValue(row1.getCell((short)19));
}
String fcc_tel = null;
if(null!=row1.getCell(20) && row1.getCell(20).getCellType() != Cell.CELL_TYPE_BLANK){
fcc_tel = getCellValue(row1.getCell((short)20));
}
String fcc_address = null;
if(null!=row1.getCell(21) && row1.getCell(21).getCellType() != Cell.CELL_TYPE_BLANK){
fcc_address = getCellValue(row1.getCell((short)21));
}
String pk_soaar_sasac = operator.getPk();
pk_org = queryCode(pk_org,"org"); //根據組織名查詢組織主鍵
String pk_group = queryCode(pk_org,"group");//根據組織名在ORG_ORGS表中可以一次查出集團主鍵 群組織版本主鍵
String pk_org_v = queryCode(pk_org,"org_v");//根據組織名在ORG_ORGS表中可以一次查出集團主鍵 群組織版本主鍵
String assess_tar_code = queryCode(assess_tar,"enterprise");//根據企業名稱查企業代碼(主鍵)根據表 equityman_enterprise
String ea_type_code = queryCode(ea_type,"eatype");//根據經濟行為類型名稱查詢代碼 根據表 basicdoc_equitymanx
parentVO.setAttributeValue("pk_org", pk_org);
parentVO.setAttributeValue("pk_org_v", pk_org_v);
parentVO.setAttributeValue("pk_group", pk_group);
parentVO.setAttributeValue("assess_tar", assess_tar_code);
parentVO.setAttributeValue("proholder", proholder);
parentVO.setAttributeValue("emlev", emlev);
parentVO.setAttributeValue("apno", apno);
parentVO.setAttributeValue("pfno", pfno);
parentVO.setAttributeValue("aec", aec);
parentVO.setAttributeValue("investmentcom", investmentcom);
parentVO.setAttributeValue("ea_type", ea_type_code);
parentVO.setAttributeValue("e_method", e_method);
parentVO.setAttributeValue("er_no", er_no);
parentVO.setAttributeValue("ea_name", ea_name);
parentVO.setAttributeValue("certificationsno", certificationsno);
parentVO.setAttributeValue("a_institution", a_institution);
parentVO.setAttributeValue("aa_name", aa_name);
parentVO.setAttributeValue("aa_no", aa_no);
parentVO.setAttributeValue("phc", phc);
parentVO.setAttributeValue("phc_tel", phc_tel);
parentVO.setAttributeValue("phc_address", phc_address);
parentVO.setAttributeValue("fcc", fcc);
parentVO.setAttributeValue("fcc_tel", fcc_tel);
parentVO.setAttributeValue("fcc_address", fcc_address);
parentVO.setAttributeValue("billdate", new UFDate());
parentVO.setAttributeValue("billstatus",-1);
parentVO.setAttributeValue("dr", 0);
aggvo.setParentVO(parentVO);
aggvoList[i] = aggvo;
}
operator.insert(aggvoList, null);
MessageDialog.showWarningDlg(null, "提示資訊", "導入成功");
}
} catch (Exception e) {
e.printStackTrace();
Logger.error(e.getMessage());
throw new Exception(e.getMessage());
}