public class demo {
public static void main(String[] args) {
try {
String bid="";
String phone="";
InputStream is = new FileInputStream("E:/1.xlsx");
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
// 获取每一个工作薄
for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
if (xssfSheet == null) {
continue;
}
// 获取当前工作薄的每一行
for (int rowNum = 0; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
XSSFRow xssfRow = xssfSheet.getRow(rowNum);
if (xssfRow != null) {
// 读取第一列数据
XSSFCell one = xssfRow.getCell(0);
bid+=getValue(one)+",";
// 读取第二列数据
XSSFCell two = xssfRow.getCell(1);
phone+=getValue(two)+",";
// XSSFCell three = xssfRow.getCell(2);
// 读取第三列数据
// 需要转换数据的话直接调用getValue获取字符串
}
}
break;
}
System.out.println(bid+","+phone);
} catch (Exception e) {
e.printStackTrace();
}
}
// 转换数据格式
private static String getValue(XSSFCell xssfRow) {
if (xssfRow.getCellType() == xssfRow.CELL_TYPE_BOOLEAN) {
return String.valueOf(xssfRow.getBooleanCellValue());
} else if (xssfRow.getCellType() == xssfRow.CELL_TYPE_NUMERIC) {
return String.valueOf(xssfRow.getNumericCellValue());
} else {
return String.valueOf(xssfRow.getStringCellValue());
}
}
}
jar包地址 链接: https://pan.baidu.com/s/1c3oVVws 密码: jpui