I don\'t know why the file I write using POI cant be opened by Ms Excel 2013, but the file is still readable by POI. (cell value can be changed)
this is the error fr
You are calling getSheetAt(0) but you did not create any sheet before (workbook.createSheet(“name”)
There are two issues with your code. Firstly this:
FileInputStream fis = null;
try {
fis = new FileInputStream(fileUri);
As explained in the Apache POI Docs, don't use an InputStream if you have a File!
Secondly, this:
Workbook workbook = null;
workbook = new HSSFWorkbook(fis);
That will only work for .xls
files, not for .xlsx
ones. Instead, you need to use WorkbookFactory which identifies the type and gives you the right workbook for the format
So, change your code to be
File file = new File(fileUri);
Workbook workbook = WorkbookFactory.create(file);
Solved :
by using real android device instead of bluestack emulator, I dont know why, but it works!!
Thanks everyone :D
The solution is to use the .xls extension and NOT .xlsx, as outlined in this answer
The major problem that i see here is:
Workbook workbook = null;
workbook = new HSSFWorkbook(fis);
Instead you have to use:
Workbook workbook = null;
workbook = new XSSFWorkbook(fis);
TO be readable by MS EXCEL 2013.