sha*_*rky 5 java arrays 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();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
参数类型Cell中的方法setCellValue(double)不适用于参数(String [])
请帮我解决这个阵列问题.
The method setCellValue(double) in the type Cell is not applicable for the arguments (String[])
Run Code Online (Sandbox Code Playgroud)
您试图传递一个声明为的字符串数组
String[] days = { "SU", "MO",...};
Run Code Online (Sandbox Code Playgroud)
到setCellValue()方法。没有setCellValue()接受String[]参数的重载变体。我想你的意思是
cell.setCellValue(days[i-1]);
Run Code Online (Sandbox Code Playgroud)
该错误消息有点令人困惑,因为在尝试解析该方法时,它选择了一种(采用 的方法double)在消息中指示。
| 归档时间: |
|
| 查看次数: |
80 次 |
| 最近记录: |