主键类:
HSSFRow row1= sheet.createRow(1); row.createCell(0).setCellValue("学生编号"); row.createCell(1).setCellValue("学生姓名"); row.createCell(2).setCellValue("学生年龄");
POI包:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17-beta1<ersion>
</dependency>
@Test public void aa() throws IOException {
//创建HSSFWorkbook对象 HSSFWorkbook wb=new HSSFWorkbook(); //创建HSSFSheet对象(excel表单) HSSFSheet sheet = wb.createSheet("成绩表"); HSSFRow row = sheet.createRow(0); HSSFCell cell=row.createCell(0); cell.setCellValue("学员考试成绩表"); sheet.addMergedRegion(new CellRangeAddress(0,0,0,3)); HSSFRow row1=sheet.createRow(1); row1.createCell(0).setCellValue("姓名"); row1.createCell(1).setCellValue("班级"); row1.createCell(2).setCellValue("笔试成绩"); HSSFRow row2=sheet.createRow(2); row2.createCell(0).setCellValue("黎明"); row2.createCell(1).setCellValue("s2"); row2.createCell(2).setCellValue("100"); FileOutputStream output=new FileOutputStream("f:\workbook.xls"); wb.write(output); output.flush();