这是读取Excel的代码
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();
}这是导入的jar包困扰很久了 ,跪求 大神指点!!
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();
}这是导入的jar包困扰很久了 ,跪求 大神指点!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货