簡體   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