String[] title = {"id","name","sex"}; //创建文件 File file = new File("e:/jxl_test.xls"); try { file.createNewFile(); //创建工作簿 WritableWorkbook writableWorkbook = Workbook.createWorkbook(file); //创建Sheet WritableSheet writableSheet = writableWorkbook.createSheet("sheet1",0); Label label = null; //第一行设置列名 for (int i = 0; i <title.length ; i++) { label = new Label(i,0,title[i]); writableSheet.addCell(label); } //追加数据 for (int i = 0; i < 10; i++) { label = new Label(0,i,"a"+1); writableSheet.addCell(label); label = new Label(1,i,"user"+i); writableSheet.addCell(label); label = new Label(2,i,"男"); writableSheet.addCell(label); } writableWorkbook.write(); writableWorkbook.close(); } catch (Exception e) { e.printStackTrace(); } }
后面的数据从1开始,,你的覆盖了表头了