如何在android上制作excel报告?

时间:2013-12-23 17:46:02

标签: android excel

我需要从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();
      }

1 个答案:

答案 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 directorynot a file

filename(test.xls)附加到path variable

,如教程

test.setOutputFile("c:/temp/lars.xls");