Witam chciałem się poradzić bo bawię się z edycja excela przez apkę korzystając z poi, czy to jest w miarę znośny kawałek kodu? zwłaszcza chodzi mi o Stream
private static void readExcelFile(Context context, String filename, String data[][][]) {
if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
Log.e(TAG, "Storage not available or read only");
return;
}
try {
// Creating Input Stream
File file = new File(context.getExternalFilesDir(null), filename);
FileInputStream myInput = new FileInputStream(file);
// Create a POIFSFileSystem object
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
// Create a workbook using the File System
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
// Get the first sheet from workbook
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
Toast.makeText(context, "File open", Toast.LENGTH_LONG).show();
// edit file
Cell cell = null;
HSSFRow row;
for (int i = 0; i < 7; i++) {
row = mySheet.getRow(i + 5);
for (int day = 0; day < 7; day++) {
if (data[0][i][day] != null) {
cell = row.getCell(0 + (day * 6));
cell.setCellValue(data[0][i][day]);
}
if (data[1][i][day] != null) {
cell = row.getCell(4 + (day * 6));
cell.setCellValue(data[1][i][day]);
}
if (data[2][i][day] != null) {
cell = row.getCell(5 + (day * 6));
cell.setCellValue(data[2][i][day]);
}
}
}
//edit 2
for (int rowIndex = 2; rowIndex < 4; rowIndex++) {
row = mySheet.getRow(rowIndex);
for (int cellDay = 0; cellDay < 5; cellDay++) {
if (data[rowIndex + 1][0][cellDay] != null) {
cell = row.getCell(1 + (cellDay * 6));
cell.setCellValue(data[rowIndex + 1][0][cellDay]);
}
}
}
myInput.close();
File file2 = new File(context.getExternalFilesDir(null), "Arkusz pracy.xls");
FileOutputStream os = null;
try {
os = new FileOutputStream(file2);
myWorkBook.write(os);
Log.w("FileUtils", "Writing file" + file);
Toast.makeText(context, "File ready ", Toast.LENGTH_SHORT).show();
os.close();
} catch (IOException e) {
Log.w("FileUtils", "Error writing " + file, e);
} catch (Exception e) {
Log.w("FileUtils", "Failed to save file", e);
} finally {
try {
if (null != os)
os.close();
} catch (Exception ex) {
}
}
} catch (Exception e) {
e.printStackTrace();
}
}