java - 如何导入导入org.apache.poi.ss.usermodel.Row错误?

标签 java android excel apache maven-jar-plugin

我正在尝试使用 Apache 将数据写入 Excel

我引用这个链接:https://www.mkyong.com/java/apache-poi-reading-and-writing-excel-file-in-java/

单元格和行未导入

Cell and Row are not Importing

这是我的java类代码:

enter image description here

我下载Apache jar file here

我的java代码如下:

 try {
            String FILE_NAME = "/tmp/MyFirstExcel.xlsx";
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet sheet = workbook.createSheet("Datatypes in Java");
            Object[][] datatypes = {
                                  {"Datatype", "Type", "Size(in bytes)"},
                                  {"int", "Primitive", 2},
                                  {"float", "Primitive", 4},
                                  {"double", "Primitive", 8},
                                  {"char", "Primitive", 1},
                                  {"String", "Non-Primitive", "No fixesize"}
                          };
                int rowNum = 0;
                System.out.println("Creating excel");

                          for (Object[] datatype : datatypes) {
                              Row row = sheet.createRow(rowNum++);
                              int colNum = 0;
                              for (Object field : datatype) {
                                  Cell cell = row.createCell(colNum++);
                                  if (field instanceof String) {
                                      cell.setCellValue((String) field);
                                  } else if (field instanceof Integer) {
                                      cell.setCellValue((Integer) field);
                                  }
                              }
                          }
                          FileOutputStream outputStream = new FileOutputStream(FILE_NAME);
                          workbook.write(outputStream);
                          workbook.close();


                      } catch (IOException e) {
                          e.printStackTrace();
                      }
}

Build.gridle

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestCompile 'com.android.support:support-annotations:26.+'
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support:support-v4:26.+'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
    compile 'com.android.support:cardview-v7:25.2.0'

    testCompile 'junit:junit:4.12'
}

最佳答案

简单您需要添加jar文件

https://mvnrepository.com/artifact/org.apache.poi/poi/3.9

转至此链接下载jar 文件并将其添加到您的lib 文件夹中。

关于java - 如何导入导入org.apache.poi.ss.usermodel.Row错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46294033/

相关文章:

java - 如何从我自己的 Android 应用程序启动 Telegram 应用程序?

vba - 使用 VBA 从文本文件中检索和调用 VBA 代码

excel - 从 Excel 粘贴到 Access - 非数字条目无法通过

java - 在 android 中为类编写 Parcelable 时出现 StackOverflowError

java - 当我们有多个实现类时,依赖注入(inject)有何帮助?

android - 单击按钮开始另一个 Activity

android - 动态设置textview背景色

Java:方法签名中类型的子类

java - 无法使用JNI从C++中的jar访问某些类

Excel - 迭代计算收敛问题/无限循环