依賴這個(gè)庫(kù)
implementation "com.github.SUPERCILEX.poi-android:poi:3.17"
excel 的模板
讀取數(shù)據(jù)后用 ObjectBox 儲(chǔ)存到數(shù)據(jù)庫(kù)
private fun readUserInfoExcel(path: String) {
var sheet1 = getSheet1(path)
sheet1.forEachIndexed { index, row ->
if (index == 0) {
return@forEachIndexed
}
var name = ""
var roomNumber = ""
var cardNumber = ""
row.forEachIndexed { index, cell ->
cell.setCellType(CellType.STRING)
var value = cell.stringCellValue
when (index) {
0 -> {
name = value
}
1 -> {
roomNumber = value
}
2 -> {
cardNumber = value
}
}
}
var user = User(name = name, roomNumber = roomNumber, cardNumber = cardNumber)
ObjectBox.get()?.let { store ->
var box = store.boxFor<User>()
box.put(user)
}
}
toast("讀取完成")
}