String filePath = "C:\\Tool\\99好一點上傳格式.xls";
File file = new File(filePath); try {
FileInputStream fileInput = new FileInputStream(file);
} catch (Exception ex) {
ex.printStackTrace();
}
POIFSFileSystem fs = null;
try {
fs = new POIFSFileSystem(is);} catch (Exception ex) {
log.error(StringUtil.getStackTraceAsString(ex)); throw ex;
}
HSSFWorkbook wb = null;
try {
wb = new HSSFWorkbook(fs);
} catch (IOException ex) {
log.error(StringUtil.getStackTraceAsString(ex));
throw ex;
}
HSSFSheet sheet = wb.getSheetAt(0); //第一個sheet
HSSFRow row = null; //列
for(int i=3;i
yearPointTransCount ++;
try{ row = sheet.getRow(i);
HSSFCell cell = null;
if(row != null){
cell = row.getCell(getExcelColumnIndex("A"));//區部代碼
agent99YearPointDTO.setRegioncode(getCellValue(cell));
}
}catch (Exception e){
log.error(StringUtil.stackTrace(e));
}
private static int getExcelColumnIndex(String columnName){
String allName[] = {"A","B","C","D","E",
"F","G","H","I","J",
"K","L","M","N","O",
"P","Q","R","S","T",
"U","V","W","X","Y",
"Z","AA","AB","AC","AD"
,"AE","AF","AG","AH","AI"
,"AJ","AK","AL","AM","AN"
,"AO","AP","AQ","AR","AS"
,"AT","AU","AV","AW","AX"
,"AY","AZ","BA","BB","BC"
,"BD","BE","BF","BG","BH" };
int index = 0;
for(int i=0;i
if(columnName.equalsIgnoreCase(allName[i])){
index = i;
}
}
return index;
}
</code></pre>
沒有留言:
張貼留言