62,614
社区成员
发帖
与我相关
我的任务
分享
public class ReadDataFromExcel2 {
public static String outputFile = "e:\\test\\tels.xls";
public static String fileToBeRead = "D:\\uws资料\\预收未录入20110407\\预收已录入(青岛).xls";
public void readExcel() {
DecimalFormat df = new DecimalFormat("#");
try {
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
fileToBeRead));
for (int numSheets = 0; numSheets < workbook.getNumberOfSheets(); numSheets++) {
if (null != workbook.getSheetAt(numSheets)) {
HSSFSheet aSheet = workbook.getSheetAt(numSheets);// 获得一个sheet
short number6 = 1;
short number1 = 3;
short number2 = 7;
short number3 = 8;
short number4 = 9;
short number5 = 10;
//System.out.println("long==" +aSheet.getLastRowNum() );
for (int rowNumOfSheet = 1; rowNumOfSheet <= aSheet
.getLastRowNum(); rowNumOfSheet++) {
if (null != aSheet.getRow(rowNumOfSheet)) {
HSSFRow aRow = aSheet.getRow(rowNumOfSheet);
HSSFCell agentNo = aRow.getCell(number1);
HSSFCell appClientName = aRow.getCell(number2);
Date appBirthDate = aRow.getCell(number3).getDateCellValue();
HSSFCell insClientName = aRow.getCell(number4);
Date insBirthDate = aRow.getCell(number5).getDateCellValue();
HSSFCell regionCode = aRow.getCell(number6);
HSSFCell insBirthDatetes = aRow.getCell(number3);
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String appBirthDateStr = sdf.format(appBirthDate);
String insBirthDateStr = sdf.format(insBirthDate);
int cellType = insBirthDatetes.getCellType();
//System.out.println("test=="+cellType);
String uwsdataEntru = new String();
uwsdataEntru = "insert into uws_plan_convert_client_record(region_code_2,agentno,app_client_name,app_birth_date,ins_client_name,ins_birth_date,proc_type,is_valid,proc_date,proc_user)values('" +
regionCode.getStringCellValue()+"','"+
agentNo.getStringCellValue() + "','" +
appClientName.getStringCellValue() + "',date'" +
appBirthDateStr + "','" +
insClientName.getStringCellValue() + "',date'" +
insBirthDateStr + "','01','Y',sysdate,user);";
System.out.println(uwsdataEntru);
/*switch (cellType) {
case 0:// Numeric
String strCell = df.format(insBirthDate
.getNumericCellValue());
System.out.println(strCell);
break;
case 1:// String
strCell = insBirthDate.getStringCellValue();
System.out.println(strCell);
break;
default:
}*/
}
}
}
}
} catch (Exception e) {
System.out.println("ReadExcelError" + e);
}
}
public static void main(String[] args) {
ReadDataFromExcel2 poi = new ReadDataFromExcel2();
// poi.CreateExcel();
poi.readExcel();
}
}