java – 使用apache poi循环数组数据

前端之家收集整理的这篇文章主要介绍了java – 使用apache poi循环数组数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我是java和Apache POI的初学者.

所以现在我想要实现的是我想在Days列下逐行(垂直)循环数组:

公众假期日期日期类

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();
    }

}

我得到的错误是:

参数类型Cell中的方法setCellValue(double)不适用于参数(String [])

请帮我解决这个阵列问题.

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

您试图传递声明为的String数组

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

到setCellValue()方法.没有setCellValue()的重载变体接受String []参数.我想你的意思

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

错误消息有点令人困惑,因为在尝试@R_403_323@时,它选择了一个(双重一个)在消息中指示.

原文链接:https://www.f2er.com/java/437513.html

猜你在找的Java相关文章