loop array data using apache poi

sharky :

I am a beginner in java and Apache POI.

So right now what i wanna to achieve is I want to loop the array days row by row(vertical) under the Days column:

Public Holidays Days Date Class

public static void main(String[] args) {

    XSSFWorkbook workbook = new XSSFWorkbook();

    XSSFSheet sheet = workbook.createSheet();

    String[] days = { "SU", "MO", "TU", "WED", "TH", "FR", "SA" };

    Row row = sheet.createRow(0);
    row.createCell(0).setCellValue("Public Holidays");
    row.createCell(1).setCellValue("Days");
    row.createCell(2).setCellValue("Date");
    row.createCell(3).setCellValue("Class");

    int numRows = sheet.getFirstRowNum();
    int numCols = sheet.getRow(0).getLastCellNum();

    for (int i = 1; i < 7; i++) {

        Row row2 = sheet.createRow(i);
        Cell cell = row.createCell(1);
        cell.setCellValue(days);

    }

    try {

        FileOutputStream out = new FileOutputStream(new File("C:xx"));

        workbook.write(out);

        out.close();

        System.out.print("Sucess, please check the file");

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

}

The error that I am getting is that:

The method setCellValue(double) in the type Cell is not applicable for the arguments (String[])

Please help me solve this array problem.

Jim Garrison :
The method setCellValue(double) in the type Cell is not applicable for the arguments (String[])

You attempted to pass a String array declared as

String[] days = { "SU", "MO",...};

to the setCellValue() method. There is no overloaded variant of setCellValue() that accepts a String[] argument. I think you meant

cell.setCellValue(days[i-1]);

The error message is a little confusing because in trying to resolve the method it chose one (the one taking double) to indicate in the message.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=70944&siteId=1