android - 找不到符号类 WorkbookSettings

标签 android excel

我正在尝试将 SQLite 数据导出到 Excel 文件。 我在按钮单击事件中添加了用于导出的代码。 我的代码如下:

 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'

错误日志:

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

这里有什么问题?有图书馆问题吗?

最佳答案

我遇到了同样的问题并通过添加最新的 jexcel jar 解决了这个问题。我从 https://sourceforge.net/projects/jexcelapi/ 下载了最新的 zip 文件,提取 jxl.jar,在 Android Studio 中创建一个 lib 文件夹并将 jar 粘贴到 lib 文件夹中。最后选择 jar ,右键单击并选择“添加为库”。重建项目,错误应该得到解决。

关于android - 找不到符号类 WorkbookSettings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33603443/

相关文章:

excel - 将度分转换为十进制度

java - 自动完成 TextView + Json 服务器动态获取标签

javascript - localStorage 在 chrome mobile android 中为 null

android - fire TV stick adb install apk 不起作用

excel - 更改单元格格式但不更改数字大小?

excel - 如何点击雅虎财经中的搜索按钮

android - Android 上的 Delphi XE8 TThread Frozen,但适用于 Windows

android - LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?

vba - .Value 仅返回货币格式的值的小数点后 4 位

java - 如何使用 POI java 将多个工作表添加到同一工作簿?