I am attempting to write to an Excel file however I keep getting the error:
Exception in thread \"main\" org.apache.poi.POIXMLException: org.apache.po
The excel file which your application trying to access is not responding due to network issues or corrupted format causes this error. If it is due to network issue try to run application later (or) If file is corrupted, try to put new file and test your application. Good Luck.
I have the same problem. When you open excel file it will generate some file like ~$______.xlsx Just find and delete all of them worked for me.
I got the same problem. Your excel isn't in right format. You can copy all work to new sheet or do Clear Format. Good luck.
Use file extension to handle WorkSheet
Type
String inputFilename = new File(path).getName();
switch (inputFilename.substring(inputFilename.lastIndexOf(".") + 1,
inputFilename.length())) {
case "xls":
return readXLS(path);
case "xlsx":
return readXLSX(path);
default:
Log.e(TAG, "No XLS file chosen");
return "Please select valid \"Excel\" File\"";
}
For XLSX file: use XSSFWorkbook & XSSFSheet
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File(path)));
XSSFSheet sheet = workbook.getSheetAt(0);
For XLS file: use HSSFWorkbook & HSSFSheet
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(new File(path)));
HSSFSheet sheet = workbook.getSheetAt(0);
Another possible solution is
Workbook workbook = WorkbookFactory.create(source)
WorkbookFactory
should be provided by Apache POI you are using (if not upgrade to newer version). It recognize file format and creates concrete implementation of Workbook
interface (XSSFWorkbook
or HSSFWorkbook
). The source
parameter can be java.io.InputStream
or java.io.File
.