如何解决在android studio中的资产中插入一个单元格到excel文件夹
我正在尝试向资产中的 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 举报,一经查实,本站将立刻删除。