2015-11-09 3 views
1

Я пытаюсь экспортировать данные SQLite в файл Excel. Я добавил код для экспорта внутри кнопки click event. Мой код выглядит следующим образом:Не удается найти класс символов WorkbookSettings

mBtnExport.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      final String fileName = "Data.xls"; 

      //Saving file in external storage 
      File sdCard = Environment.getExternalStorageDirectory(); 
      File directory = new File(sdCard.getAbsolutePath() + "/ExportToExcel"); 

      //create directory if not exist 
      if (!directory.isDirectory()) { 
       directory.mkdirs(); 
      } 

      //file path 
      File file = new File(directory, fileName); 

      WorkbookSettings wbSettings = new WorkbookSettings(); 
      wbSettings.setLocale(new Locale("en", "EN")); 
      WritableWorkbook workbook; 
      Log.i("Path=================", file.getAbsolutePath()); 
      try { 
       workbook = Workbook.createWorkbook(file, wbSettings); 
       //Excel sheet name. 0 represents first sheet 
       WritableSheet sheet = workbook.createSheet("User Detail", 0); 

       try { 
        sheet.addCell(new Label(0, 0, "")); // column and row 
        sheet.addCell(new Label(1, 0, "Age")); 
        for (int i = 0; i < mData.size(); i++) { 
         //String title = cursor.getString(cursor.getColumnIndex(DatabaseHelper.TODO_SUBJECT)); 
         String title = mData.get(i).getmName(); 
         String age = mData.get(i).getmAge(); 


         sheet.addCell(new Label(0, i + 1, title)); 
         sheet.addCell(new Label(1, i + 1, age)); 
        } 


        //closing cursor 

       } catch (RowsExceededException e) { 
        e.printStackTrace(); 
       } catch (WriteException e) { 
        e.printStackTrace(); 
       } 
       workbook.write(); 
       try { 
        workbook.close(); 
       } catch (WriteException e) { 
        e.printStackTrace(); 
       } 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      Toast.makeText(getActivity(), "Exported", Toast.LENGTH_SHORT).show(); 
     } 
    }); 

зависимости в build.gradle:

dependencies { 
compile 'com.android.support:appcompat-v7:23.0.1' 
compile fileTree(dir: 'libs', include: ['*.jar']) 
compile 'jexcelapi:jxl:2.6' 
compile 'com.madgag:sc-light-jdk15on:1.47.0.3' 
compile 'com.itextpdf:itextpdf:5.5.7' 

}

ERRORLOG:

Error:(218, 17) error: cannot find symbol class WorkbookSettings 
Error:(218, 51) error: cannot find symbol class WorkbookSettings 
Error:(220, 17) error: cannot find symbol class WritableWorkbook 
Error:(223, 32) error: cannot find symbol variable Workbook 
Error:(225, 21) error: cannot find symbol class WritableSheet 

Что здесь проблема? Есть ли проблема с библиотекой?

ответ

0

Все было в порядке, я просто должен сделать Добавить в библиотеку во все файлы .jar, включенные в папку libs, щелкнув правой кнопкой мыши на конкретном файле .jar.

1

Я столкнулся с той же проблемой и решил проблему, добавив последнюю банку jexcel. Я удалил последний zip-файл с https://sourceforge.net/projects/jexcelapi/, извлек jxl.jar, создал папку lib в Android Studio и вставил папку jar int it lib. Наконец, выберите банку, щелкните правой кнопкой мыши и выберите «Добавить как библиотеку». Перестройте проект, и ошибка должна быть решена.

Смежные вопросы