POI 实现导入Excel 导入问题
publicvoidresultSetFromExcel_real(Stringurl,Stringfilename,Stringpsno)throwsIOExcepti...
public void resultSetFromExcel_real(String url, String filename,String psno) throws IOException{
RSDB rsdb=new RSDB();
HSSFWorkbook workbook = null;
FileInputStream fin = null;
FileOutputStream fileOut = null;
File file = new File(url+filename);
fin = new FileInputStream(file);
workbook = new HSSFWorkbook(fin);
HSSFSheet sheet= workbook.getSheetAt(0);
HSSFRow row = null;
HSSFCell cell = null;
List arr=new ArrayList();
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(workbook) ;
for(int i = 2; i <=sheet.getLastRowNum(); i++) {
Map<Integer,String> map=new HashMap<Integer,String>();
for(int j = 0; j <=13; j++){
row = sheet.getRow(i);
cell = row.getCell(j);
if(cell!=null && cell.toString().length()!=0){
//解析Excel 数据放入map
arr.add(map);
}
///====导入数据库=====
for(int j = 0; j <arr.size(); j++){
String sno="";
HashMap<String,String> map=new HashMap<String,String>();
Map map1=(HashMap)arr.get(j);
try {
sno = rsdb.getString("select F_SNO('HR_REALWELFARE_C') from dual");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(map1.get(3)==null || map1.get(3)=="0"){continue;}
map.put("SNO", sno);
map.put("PSNO", psno);
map.put("ORDERNO", map1.get(0).toString().trim().replace(".0",""));
map.put("ROOTDEPNAME", map1.get(1).toString().trim());
String workno=map1.get(2).toString();
map.put("WORKNO", workno);
//目前 想解决的问题是:
如果WORKNO 相等 上面的 SNO PSNO...不变
要将 下面的 EMPANNUITY_BU ,PROVIDEINSURE_BU ...这些数据累加
怎么处理。。。。。、。、、、、,、?
map.put("EMPANNUITY_BU", map1.get(9).toString().trim().replace(".0",""));
map.put("PROVIDEINSURE_BU", map1.get(10).toString());
map.put("LOSEJOB_BU", map1.get(11).toString());
map.put("MEDICALINSURE_BU", map1.get(12).toString());
map.put("HOUSINGFUND_BU", map1.get(13).toString().trim().replace(".0",""));
// System.out.print(map1.get(8));
try {
rsdb.doInsert("HR_REALWELFARE_C",map);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
意思讲1422 累加合并成一个人 ,把后面的数值加一起导入数据库 展开
RSDB rsdb=new RSDB();
HSSFWorkbook workbook = null;
FileInputStream fin = null;
FileOutputStream fileOut = null;
File file = new File(url+filename);
fin = new FileInputStream(file);
workbook = new HSSFWorkbook(fin);
HSSFSheet sheet= workbook.getSheetAt(0);
HSSFRow row = null;
HSSFCell cell = null;
List arr=new ArrayList();
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(workbook) ;
for(int i = 2; i <=sheet.getLastRowNum(); i++) {
Map<Integer,String> map=new HashMap<Integer,String>();
for(int j = 0; j <=13; j++){
row = sheet.getRow(i);
cell = row.getCell(j);
if(cell!=null && cell.toString().length()!=0){
//解析Excel 数据放入map
arr.add(map);
}
///====导入数据库=====
for(int j = 0; j <arr.size(); j++){
String sno="";
HashMap<String,String> map=new HashMap<String,String>();
Map map1=(HashMap)arr.get(j);
try {
sno = rsdb.getString("select F_SNO('HR_REALWELFARE_C') from dual");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(map1.get(3)==null || map1.get(3)=="0"){continue;}
map.put("SNO", sno);
map.put("PSNO", psno);
map.put("ORDERNO", map1.get(0).toString().trim().replace(".0",""));
map.put("ROOTDEPNAME", map1.get(1).toString().trim());
String workno=map1.get(2).toString();
map.put("WORKNO", workno);
//目前 想解决的问题是:
如果WORKNO 相等 上面的 SNO PSNO...不变
要将 下面的 EMPANNUITY_BU ,PROVIDEINSURE_BU ...这些数据累加
怎么处理。。。。。、。、、、、,、?
map.put("EMPANNUITY_BU", map1.get(9).toString().trim().replace(".0",""));
map.put("PROVIDEINSURE_BU", map1.get(10).toString());
map.put("LOSEJOB_BU", map1.get(11).toString());
map.put("MEDICALINSURE_BU", map1.get(12).toString());
map.put("HOUSINGFUND_BU", map1.get(13).toString().trim().replace(".0",""));
// System.out.print(map1.get(8));
try {
rsdb.doInsert("HR_REALWELFARE_C",map);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
意思讲1422 累加合并成一个人 ,把后面的数值加一起导入数据库 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询