二维数组在表格中的用法
public void RaadXls2() throws Exception{
Sheet[] sheet = wb.getSheets();
for(int x=0;x<sheet.length;x++){
Sheet s = wb.getSheet(x);
if(s.getRows()==0){
System.out.println("Sheet" + (x + 1) + "为空!");
continue;
}else{
int Rows = s.getRows(); //行数11
int Cols = s.getColumns(); //总列数13
String[][] str = new String[Rows][Cols];
for (int i = 1; i < Rows; i++) {
String gImages = null;
String gApk = null;
String gsuolu = null;
Game game = new Game();
GameType gt = new GameType();
GamePhoto gphoto = new GamePhoto();
for(int j = 0; j < Cols; j++){
str[i][j] = (s.getCell(j, i)).getContents();
switch (j) {
case 0:
game.setRecommend(Long.parseLong(str[i][j].trim())); //是否推荐
break;
case 1:
/**
*读一条数据 E:\游戏包\3D太空滚球\i1361758807343.png
*1、检测是否有,有则上传此图到web项目指定文件夹
*经过处理得到这个地址存入到数据库 /cms/game/4844_game.jpg
*/
gImages = str[i][j].trim(); //游戏图标
break;
case 2:
if(!Tools.isNullOrEmpty(str[i][j].trim())){
game.setChinaName(str[i][j].trim()); //中文名
}
break;
case 3:
if(!Tools.isNullOrEmpty(str[i][j].trim())){
game.setScore(Double.parseDouble(str[i][j].trim())); //评分
}
break;
default:
break;
}
}
Set<GameType> gameTypes = new HashSet<GameType>();
//游戏类型表
VOModel v1= new VOModel();
v1.setName(gt.getName());
List<GameType> gtlist = this.gameTypeDAO.getGameTypeList(v1);
if(gtlist.size()<=0){
gt = this.gameTypeDAO.merge(gt);
}else{ //如果存在
gt = gtlist.get(0);
}
gameTypes.add(gt);
}
}
wb.close(); //操作完成时,关闭对象,释放内存
}