[英]How to read excel file xls and xlsx from local in android studio also I need to perform search with set with row and cols
是否有任何 android 依賴項可用於讀取和執行行和列操作 Kotlin 或 java
此錯誤 --> workbook = Workbook.getWorkbook(file) after execution file not found 異常
lateinit var workbook: Workbook
val XLS = "application/vnd.ms-excel"
val XLSV2 = "application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet"
val REQUEST_CODE = 101
fun readxlsdata(view: android.view.View) {
val intent = getCustomFileChooserIntent(XLS, XLSV2,"image/*")
startActivityForResult(intent, REQUEST_CODE)
}
fun getCustomFileChooserIntent(vararg types: String?): Intent? {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
// Filter to only show results that can be "opened"
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = "*/*"
intent.putExtra(Intent.EXTRA_MIME_TYPES, types)
return intent
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
try {
when (requestCode) {
REQUEST_CODE -> if (resultCode == Activity.RESULT_OK && data != null) {
val file = File(data.data!!.path)
//val wb = WorkbookSettings()
//wb.gcDisabled = true
if (file.toString().endsWith(".xls"))
{
Log.e("XLS","XLS")
}
else if (file.toString().endsWith(".xlsx"))
{
Log.e("XLS","XLSX")
try{
workbook = Workbook.getWorkbook(file)
} catch (e: FileNotFoundException) {
Log.e(
"XLS", "readExcelData: FileNotFoundException $e")
} catch (e: IOException) {
Log.i("debinf cliinf","readExcelData: Error reading InputStream $e")
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.e("XLS","Cancelled")
}
}
} catch (e: Exception) {
Log.e("XLS", "Exception in onActivityResult : " + e.message)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.