i have some problem with my android app; i want that users could upload an excel file on Firebase and populate a RecyclerView with data on this file. I don't have problem about populate the RecyclerView, i know how to do it, i have problem on read the file. I uploaded it on Firebase with this:
StorageReference stRef = storageRef.child("clienti.xlsx");
UploadTask task = stRef.putFile(file);
task.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Toast.makeText(getActivity(), "Upload error: "+exception.getMessage() , Toast.LENGTH_SHORT).show();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
downloadFile("clienti");
}
It all works until now, i also download the file from firebase to a specific folder but now i don't know how to "read" it and take data from it; i have tried this, but it said to me always that the file doesn't exists.
String[][] arrays = read( Environment.getExternalStorageDirectory() + localFile.getPath());
if(arrays == null){strHyouji="no such file";}else{
for (String[] array : arrays) {
for (String v : array) {
strHyouji = strHyouji + v + ",";
}
strHyouji = strHyouji + "\n";
aList.add(strHyouji);
}
}
Toast.makeText(getActivity(), strHyouji, Toast.LENGTH_SHORT).show();
Here the read() method:
Workbook workbook = null;
try {
WorkbookSettings ws = new WorkbookSettings();
ws.setGCDisabled(true);
workbook = Workbook.getWorkbook(new File(dbStr), ws);
Sheet sheet = workbook.getSheet(0);
int rowCount = sheet.getRows();
String[][] result = new String[rowCount][];
for (int i = 0; i < rowCount; i++) {
Cell[] row = sheet.getRow(i);
result[i] = new String[row.length];
for (int j = 0; j < row.length; j++) {
result[i][j] = row[j].getContents();
}
}
return result;
} catch (BiffException e) {
strHyouji=strHyouji+ e.toString();
} catch (IOException e) {
strHyouji=strHyouji+ e.toString();
} catch (Exception e) {
strHyouji=strHyouji+ e.toString();
} finally {
if (workbook != null) {
workbook.close();
}
}
return null;