YoBre
YoBre

Reputation: 2530

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

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.

Upvotes: 3

Views: 4861

Answers (2)

Sandeep Pandey
Sandeep Pandey

Reputation: 1132

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

Upvotes: 0

winklerrr
winklerrr

Reputation: 14877

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.

Upvotes: 1

Related Questions