sách gpt4 ăn đã đi

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

In lại 作者:搜寻专家 更新时间:2023-10-31 20:16:54 25 4
mua khóa gpt4 giày nike

我是 java 和 Apache POI 的初学者。

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

公共(public)假期日期类

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

}

thử {

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

workbook.write(out);

ra ngoài.đóng();

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

} catch (Ngoại lệ e) {
e.printStackTrace();
}

}

Lỗi tôi nhận được là:

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

请帮我解决这个数组问题。

câu trả lời hay nhất

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

您试图传递一个声明为

的字符串数组
String[] days = { "SU", "MO",...};

đến setCellValue() 方法。没有接受 String[] 参数的 setCellValue() 的重载变体。我想你的意思是

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

错误消息有点令人困惑,因为在尝试解决方法时,它选择了一个方法(采用 gấp đôi 的方法)在消息中指示。

关于java - 使用 apache poi 循环数组数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52714067/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress