线程“ main”中的异常java.lang.NoSuchMethodError:'void scala.util.matching.Regex。<init>(java.lang.String,scala.collection.Seq)'

当我尝试将.xlsx文件读取为csv格式的DataFrame时,会发生此错误。谁能帮助我这里的问题是什么以及如何解决?以下是我使用的代码,

package Sample

import org.apache.spark.sql{SparkSession, SparkContext}
import org.apache.spark.SparkConf


val conf = new SparkConf()
.setAppName("Excel to DataFrame")
.setMaster("local[*]")

val sc = new SparkContext(conf)
sc.setLogLevel("WARN")


val spark = SparkSession.builder()
.appName("Excel to DataFrame")
.config("spark.master","local")
.getOrCreate()

val inputDF = spark.read
.format("csv")
.option("inferSchema","true")
.option("path","G:\\Sample Input.xlsx")
.load()

inputDF.show()
评论
  • 灵凡
    灵凡 回复

    You can try using Spark Excel dependency in your project.

    def readExcel(file: String): DataFrame = sqlContext.read
        .format("com.crealytics.spark.excel")
        .option("location", file)
        .option("useHeader", "true")
        .option("treatEmptyValuesAsNulls", "true")
        .option("inferSchema", "true")
        .option("addColorColumns", "False")
        .load()
    
    val data = readExcel("path to your excel file")
    
    data.show(false)
    

    you can also give sheetname as option if your excel sheet has multiple sheets