依赖这个库
implementation "com.github.SUPERCILEX.poi-android:poi:3.17"
excel 的模板
Image 21.png
读取数据后用 ObjectBox 储存到数据库
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("读取完成")
}
网友评论