Skip to content

Commit

Permalink
Skip empty rows when trying to find headers
Browse files Browse the repository at this point in the history
  • Loading branch information
nightscape committed Mar 23, 2017
1 parent c7cc437 commit 8427d1e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/com/crealytics/spark/excel/ExcelRelation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extends BaseRelation with TableScan with PrunedScan {
val inputStream = FileSystem.get(path.toUri, sqlContext.sparkContext.hadoopConfiguration).open(path)
val workbook = WorkbookFactory.create(inputStream)
val sheet = findSheet(workbook, sheetName)
val headers = sheet.getRow(0).cellIterator().asScala.to[Vector]
lazy val firstRowWithData = sheet.asScala.find(_ != null).getOrElse(throw new RuntimeException(s"Sheet $sheet doesn't seem to contain any data")).cellIterator().asScala.to[Vector]
override val schema: StructType = inferSchema
val dataFormatter = new DataFormatter();

Expand Down Expand Up @@ -115,7 +115,7 @@ extends BaseRelation with TableScan with PrunedScan {
if (this.userSchema != null) {
userSchema
} else {
val firstRow = headers
val firstRow = firstRowWithData
val header = if (useHeader) {
firstRow.map(_.getStringCellValue)
} else {
Expand Down

0 comments on commit 8427d1e

Please sign in to comment.