80,472
社区成员




InputStream is = null;
String name = null;
String sex = null;
String phone = null;
try {
is = getAssets().open("test.xlsx");
Workbook workbook = WorkbookFactory.create(is);
Sheet sheet = workbook.getSheetAt(0);
int rowCount = sheet.getPhysicalNumberOfRows();
for (int r = 0; r < rowCount; r++) {
Row row = sheet.getRow(r);
int cellCount = row.getPhysicalNumberOfCells(); // 获取总列数
for (int c = 0; c < cellCount; c++) {
Cell cell = row.getCell(c);
int cellType = cell.getCellType();
String cellValue = null;
switch (cellType) {
case Cell.CELL_TYPE_STRING: // 文本
cellValue = cell.getStringCellValue();
if (cellValue.equals("男")||cellValue.equals("女")) {
sex=cellValue;
}
else {
name=cellValue;
}
break;
case Cell.CELL_TYPE_NUMERIC:
DecimalFormat df = new DecimalFormat("0");
cellValue= df.format(cell.getNumericCellValue());
phone=cellValue;
break;
default:
}
}
values.put("name", name);
values.put("sex", sex);
values.put("phone", phone);
service.addPerson(values);
}
} catch (Exception e) {
e.printStackTrace();
}