【发布时间】:2017-09-27 19:39:30
【问题描述】:
我正在阅读 Apache poi 指南:https://poi.apache.org/spreadsheet/quick-guide.html
我决定继续在我的 Eclipse 项目中输入代码,在编写“阅读和重写工作簿”部分时,我在 Eclipse 中遇到了这个错误:
CellType 无法解析为变量
我想知道为什么?我在 Stack Overflow 的另一篇文章中发现要更改这一行:
cell.setCellType(CellType.STRING);
到:
cell.setCellType(HSSFCellType.STRING);//or XSSFCell
但它不起作用,我的代码有什么问题吗? (顺便说一句,我从 apache 的网站复制并粘贴)
InputStream inp = new FileInputStream("workbook.xls");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(2);
Cell cell = row.getCell(3);
if (cell == null)
cell = row.createCell(3);
cell.setCellType(CellType.STRING);
cell.setCellValue("a test");
//Write
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
【问题讨论】: