jxl导出excel的一些方法

来源:互联网 发布:淘宝在线人数免费插件 编辑:程序博客网 时间:2024/05/21 10:54


在做struts应用开发过程中,有时遇到需要导入导出excel,下面是其中一些常用的方法:

(1)导入excel表时对表中内容验证

for(int i=2; i<rowNum; i++){      for(int j=0;j<colNum;j++){       Cell cell = sheet.getCell(j, i);       String contents = cell.getContents();       if ((j == 0) || (j == 2) || (j == 3)) {        if (contents.equals("")){        res = "第" + (i+1) +"行"+"第"+(j+1)+"列的数据不能为空!";        check = false;        }       }       if(((j == 1)||(j == 3))&& check){        if (!(cell.getType() == CellType.LABEL)){         res = "第" + (i+1) +"行"+"第"+(j+1)+"列的数据应为字符型!";         check = false;        }       }              if((j == 1)&&(cell.getContents().length() > 30)&& check){        res = "第" + (i+1) +"行"+"第"+(j+1)+"列的数据不能超过30字符!";        check = false;       }       if((j == 3)&&(cell.getContents().length() > 1200)&& check){        res = "第" + (i+1) +"行"+"第"+(j+1)+"列的数据不能超过1200字符!";        check = false;       }       if(((j == 0)||(j == 2))&& check){        if ((cell.getType() != CellType.NUMBER)&& (cell.getType() != CellType.NUMBER_FORMULA)){         res = "第" + (i+1) +"行"+"第"+(j+1)+"列的数据应为数字型!";         check = false;        }        }       }      }

(2)设置某一列的单元格下拉菜单选项

public WritableCellFeatures addColumnList(String[] contentArray){List<String> contentList=new ArrayList<String>();WritableCellFeatures wcf=new WritableCellFeatures();for(int i=0;i<contentArray.length;i++){contentList.add(contentArray[i]);}wcf.setDataValidationList(contentList);contentList.clear();contentList=null;return wcf;} 然后Label=new Label(列,行,内容); label.setCellFeatures(上面那个方法); contentArray是下拉列表的显示的内容



 

原创粉丝点击