问题描述
我正在尝试向资产中的 Excel 文件添加一个单元格。我可以从资产文件夹中获取数据,但我无法添加任何内容。当代码运行时,应用程序关闭。我想用于我的无人机飞行前检查清单。
ekle.setOnClickListener(new View.OnClickListener() {//button
@Override
public void onClick(View v) {
InputStream myInput;// Reach the folder
AssetManager assetManager = getAssets();
try {
myInput = assetManager.open("OrnekChecklist-Tomruk.xls");
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput); // Reach the details of folder
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
// Get the first sheet from workbook
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
Row row = mySheet.createRow(0);//create row
Cell cell = null;//create cell
CellStyle cellStyle = myWorkBook.createCellStyle();
cellStyle.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index);
cell = row.createCell(0);
cell.setCellValue(insertTextView.getText().toString());
cell.setCellStyle(cellStyle);
Uri file = Uri.parse("file:///android_asset/raw/sample/OrnekChecklist-Tomruk.xls");// folder path but i am not sure
String path = file.toString();
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(path);
myWorkBook.write(outputStream);
Toast.makeText(getApplicationContext(),"OK",Toast.LENGTH_LONG).show();//feedback
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),"NO OK",Toast.LENGTH_LONG).show();//feedback
try {
outputStream.close();
}
catch (IOException ex) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)