繁体   English   中英

如何在 android 工作室中从本地读取 excel 文件 xls 和 xlsx 我还需要使用带有行和列的集合执行搜索

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM