3

How to get filename of xlsx file with apache poi XSSF?

case class XlsxSplitter(path: InputStream){

  lazy val spreadSheet=load(path)

  def load(path: InputStream):SpreadSheet={
    val wb = new XSSFWorkbook(path)
    .........
  }
}

I could extract it from the path, but I would like to make my case class as generic as possible.

Samkit Jain
  • 2,523
  • 16
  • 33
YoBre
  • 2,520
  • 5
  • 27
  • 37

2 Answers2

1

If you're able to change the path attribute to a attribute of type File instead of InputStream, you can get the filename from the file itself by file.getName();

Otherwise I think you have no other choice than extracting it by yourself.

winklerrr
  • 13,026
  • 8
  • 71
  • 88
0

You can get file name by using method file.getOriginalFilename()

spandey
  • 1,034
  • 1
  • 15
  • 30