0

I want to read an xlsx file in internal storage (not sdcard but the app's internal) using apache poi. Since I have the file I would prefer if I didn't use an input stream but rather load the file directly into Apache Poi. How do I do this? Thanks. Keyword here is 'internal storage'

akokskis
  • 1,486
  • 15
  • 32
Ahmed Zafar
  • 665
  • 2
  • 10
  • 24

1 Answers1

1

To create a new Workbook, you can use either a File or an InputStream:

// Use a file
Workbook wb = WorkbookFactory.create(new File("MyExcel.xls"));

// Use an InputStream, needs more memory
Workbook wb = WorkbookFactory.create(new FileInputStream("MyExcel.xlsx"));

More details are available on the POI site.

akokskis
  • 1,486
  • 15
  • 32
  • Thanks! I want to use the file. Is this file retrieved from internal storage automatically? Example: The above code will retrieve the file called MyExcel.xlsx which is in internal storage? – Ahmed Zafar Aug 16 '13 at 13:49
  • I have no idea how your directory structure is setup, but instead of using MyExcel.xlsx, you'll have to point that to wherever your file is located. This post: http://stackoverflow.com/a/17546843/697281 looks to have some good information regarding locating the internal storage. – akokskis Aug 16 '13 at 13:53