浅谈JAVA读写Excel的几种途径
读写Excel文件需要使用Excel类库Free Spire.XLS for Java.
读取Excel内容:
//创建Workbook对象
Workbook wb = new Workbook();
//加个Excel文档
wb.loadFromFile("C:\\Users\\Administrator\\Desktop\\test.xlsx");
//获取第一作表
Worksheet sheet = wb.getWorksheets().get(0);
//遍历工作表的每一
for (int i = 1; i
//遍历工作的每一列
for (int j = 1; j
//输出指定单元格的数据
System.out.print(sheet.get(i,j).getText());
System.out.print("\t");
}
System.out.print("\n");
}
写入内容:
//创建Workbook对象
Workbook wb = new Workbook();
//加载一个Excel文档
wb.loadFromFile("C:\\Users\\Administrator\\Desktop\\test.xlsx");
//获取第一个工作表
Worksheet sheet = wb.getWorksheets().get(0);
//在单元格A1写入新数据
sheet.getCellRange("A1")