How to import import org.apache.poi.ss.usermodel.Row error?

15,141

Solution 1

Simple You need to add the jar file

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

Go to this link download the jar file Add it in your lib folder.

Solution 2

Try following code

String filepath = "/tmp/MyFirstExcel.xlsx";

    FileInputStream fis;

    fis = new FileInputStream(filepath);

    XSSFWorkbook workbook = new XSSFWorkbook(fis);
    XSSFSheet sheet = workbook.getSheetAt(0);

    Iterator<org.apache.poi.ss.usermodel.Row> rowIterator = sheet.iterator();

    while (rowIterator.hasNext()) {

        Row row = rowIterator.next();

        row.getCell(0).getStringCellValue();

    }
Share:
15,141
demo
Author by

demo

Updated on June 16, 2022

Comments

  • demo
    demo almost 2 years

    I am tring to write data into Excel using Apache

    i refer this link:https://www.mkyong.com/java/apache-poi-reading-and-writing-excel-file-in-java/

    Cell and Row are not Importing

    Cell and Row are not Importing

    This my java class code:

    enter image description here

    I download Apache jar file here

    MY java code below:

     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'
    }
    
    • Axel Richter
      Axel Richter over 6 years
    • demo
      demo over 6 years
      @Axel Richter i already add same lib sir.
    • Axel Richter
      Axel Richter over 6 years
      Sure? Seems you have only <artifactId>poi-ooxml</artifactId> but not <artifactId>poi</artifactId>.
    • demo
      demo over 6 years
      @AxelRichter thank you sir,let me check please wait sir,
    • demo
      demo over 6 years
      @AxelRichter stackoverflow.com/questions/46297250/… Please look at this sir my new question..i am facing new problem now
  • Daniel S.
    Daniel S. over 4 years
    Please give a more elaborate response. And you should write the code appropriately.