@Test
void excelg() throws IOException {
String MyPath = "F:\\xxxx\\test\\user\\excel.xls";
FileInputStream fis = new FileInputStream(MyPath);
//1.创建一个工作簿
// Workbook workbook = new XSSFWorkbook(fis);
HSSFWorkbook workbook = new HSSFWorkbook(fis);
Sheet sheet1 = workbook.getSheetAt(0);
//通过行下标和列下标返回cell对象
//Cell cell = sheet1.getRow(1).getCell(1);
//cell.setCellValue("呵呵呵呵呵呵呵");
Row row1 = sheet1.createRow(9);
//4.创建一个单元格
Cell cell1 = row1.createCell(3);
cell1.setCellValue("通过行下标和列下标返回cell对象");
Sheet sheet2 = workbook.getSheetAt(1);
Row row2 = sheet2.createRow(9);
//4.创建一个单元格
Cell cell2 = row2.createCell(3);
cell2.setCellValue("通过行下标和列下标返回cell对象--222");
HSSFSheet sheet3 = workbook.createSheet("国道");
Row row3 = sheet3.createRow(9);
//4.创建一个单元格
Cell cell3 = row3.createCell(2);
cell3.setCellValue("44455533343");
FileOutputStream fos = new FileOutputStream(MyPath);
workbook.write(fos);
fis.close();
}
https://www.cnblogs.com/javalinux/p/14780949.html
问题解决
个人总结:如果是是2013版及之前的,创建工作簿的时候使 用: HSSFWorkbook workbook = new HSSFWorkbook();相应的之后在创建表格,行,单元格
时使用:HSSFSheet sheet 、HSSFRow row、HSSFCell cell,
如果是是2017版,创建工作簿的时候使用: XSSFWorkbook workbook = new XSSFWorkbook(); 相应的之后在创建表格,行,单元格时使用:Sheet sheet、Row row、Cell cell。