后缀为xls的表
try {
FileInputStream fs=new FileInputStream("C:\\Users\\Administrator\\Desktop\\13.xls"); //获取d://test.xls
//POIFSFileSystem ps=new POIFSFileSystem(fs); //使用POI提供的方法得到excel的信息
HSSFWorkbook work1=new HSSFWorkbook(fs);
HSSFSheet sheet1=work1.getSheet("sheet1");
HSSFRow row=sheet1.getRow(2);//创建行 0表示第一行,2表示第三行
HSSFCell cell=row.createCell(8);
cell.setCellValue("周杰伦");
HSSFCell cell2=row.createCell(7);
HSSFCell c3 = row.getCell(0);
System.out.println(c3.getStringCellValue());
cell2.setCellValue("蔡徐坤");
fs.close();
FileOutputStream fo=new FileOutputStream("C:\\Users\\Administrator\\Desktop\\13.xls");
work1.write(fo);
fo.close();
}catch (Exception e){
e.printStackTrace();
}
后缀为xlsx的表
try {
XSSFWorkbook work2=new XSSFWorkbook();
XSSFSheet sheet2=work2.createSheet("sheet2");
XSSFRow row =sheet2.createRow(1);
XSSFCell cell=row.createCell(1);
cell.setCellValue("07版的内容");
FileOutputStream fo=new FileOutputStream("C:\\Users\\Administrator\\Desktop\\13.xlsx");
work2.write(fo);
fo.close();
}catch (Exception e){
e.printStackTrace();
}