简体   繁体   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

Is any android dependency available for read and perform row and column operation Kotlin or java是否有任何 android 依赖项可用于读取和执行行和列操作 Kotlin 或 java

error in this --> workbook = Workbook.getWorkbook(file) after execution file not found exception此错误 --> 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.

相关问题 如何从 XLS (Excel) 文件中读取数据 [Java, Android] - How to read data from XLS (Excel) file [Java, Android] 如何使用Java读取Spark中的xls和xlsx文件? - how can I read xls and xlsx file in spark with java? 我想将excel(xls / xlsx)文件嵌入电子邮件正文(而非附件)中 - I want to embed an excel(xls/xlsx) file in an email body(not attachment) 如何在Java 1.3中将.xlsx格式的Excel文件转换为.xls? - How can i convert excel file of format .xlsx to .xls in Java 1.3? 如何在Java中转换Excel文件格式XLS和XLSX反之亦然 - How to convert the excel file format xls and xlsx vice versa in java 如何从android studio中的本地JSON文件读取并添加到ArrayList? - How to read from a local JSON file in android studio and add to an ArrayList? 如何在Java中读取.xlsx和.xls文件? - How can I read .xlsx and .xls files in Java? 如何通过Apache POI 3.9从xls / xlsx读取时间格式? - How to read a time format from xls/xlsx by Apache POI 3.9? 如何使用 Kotlin/Java 从我的 s3 存储桶中读取 Excel 文件 (xlsx)? - How can I read an Excel file (xlsx) from my s3 bucket with Kotlin/Java? 如何读取像文本一样的excel(.xls)文件? - How to read an excel(.xls) file like text?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM