我需要从Android应用程序制作一个简单的Excel报告。我正在使用“jlx.jar”,但我不知道如何将excel保存在手机上。
WriteExcel test = new WriteExcel();
String path = getBaseContext().getFilesDir().getPath();
test.setOutputFile(path);
try {
test.write();
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
}
我收到FileNotFoundException。路径是“/ data / data / mypackage / files /”
不要认为这里有问题,但这里是write()方法:
public void write() throws IOException, WriteException {
File file = new File(inputFile);
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings);
workbook.createSheet("Report", 0);
WritableSheet excelSheet = workbook.getSheet(0);
createLabel(excelSheet);
createContent(excelSheet);
workbook.write();
workbook.close();
}
答案 0 :(得分:0)
我猜您正在关注本教程
http://www.vogella.com/articles/JavaExcel/article.html
当你执行setOutputFile时,
public void setOutputFile(String inputFile) {
this.inputFile = inputFile;
}
但是当你将值传递给inputFile时,你正在传递
String path = getBaseContext().getFilesDir().getPath();
test.setOutputFile(path);
此处的路径仅为the path to a directory
和not a file
将filename(test.xls)
附加到path variable
,如教程
test.setOutputFile("c:/temp/lars.xls");