您的位置:首页 > 其它

poi上传excel

2016-06-17 20:00 375 查看
<form action="/xxxx.do" id="ModifyFile" method="post" enctype="multipart/form-data"  target="importResult">

            <div class="form-group col-md-6">

                <!--<label for="exampleInputFile">-->

                上传文件:<input type="file" name="excel" id="exampleInputFile">

                </label>

            </div>

            <div class="col-md-4">

                <button type="button" class="btn btn-default btn-primary exportexcel">提交改密</button>

            </div>
        </form>

$(".exportexcel").click(function(){

    var excel=$("#exampleInputFile").val();

    alert(excel)

    if(excel==""){

        alert("上传文件必需选择!!");

        return;

    }else{

        $("#ModifyFile").submit();

    }

});

    private File excel;

public void modifyPwdCard() throws Exception{

        String cardNumber=null;

        String password=null;

        List errorList=new ArrayList();

        String exception=null;

        List<HashMap<String,Object>> ErrorInfolist=new ArrayList<HashMap<String,Object>>();

        System.out.println("======excel====="+excel.getName());

        InputStream fi=new FileInputStream(excel);

        HSSFWorkbook wb=new HSSFWorkbook(fi);

        HSSFSheet sheet=wb.getSheetAt(0);

        int rows=sheet.getLastRowNum() + 1;

        int columns=sheet.getRow(0).getLastCellNum();

        HSSFRow row;

        HSSFCell cell;

        StringBuilder stb=new StringBuilder();

        for(int i=1;i < rows;i++){

            row=sheet.getRow(i);

            stb.setLength(0);

            for(int j=0;j < columns;j++){

                cell=row.getCell((short)j);

                if(j == 0){

                    cardNumber=HSSFCellUtil.getCellValue(cell).trim();

                }

                if(j == 1){

                    password=HSSFCellUtil.getCellValue(cell).trim();

                }

            }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: