代码如下:import java.io.FileOutputStream;import java.io.IOException;//import org.apache.poi.hssf.*;import org.apache.poi.hssf.usermodel.*;import org.apache.poi.ss.usermodel.*;public class ex1 {public static void main(String[] args) throws IOException {// 创建一个excel文件Workbook wb = new HSSFWorkbook();FileOutputStream fileOut = new FileOutputStream("C://workbook.xlsx");wb.write(fileOut);fileOut.close();}}运行环境是Myeclipse,始终报错:Exception in thread "main" java.lang.Error: Unresolved compilation problems: HSSFWorkbook cannot be resolved to a typeHSSFWorkbook cannot be resolved to a type at ex1.main(ex1.java:10)是我的外部jar包添加有问题吗,还忘前辈们指导,谢谢。
4 回答
慕虎7371278
TA贡献1802条经验 获得超4个赞
可能是这句出问题了:
Workbook wb = new HSSFWorkbook();
可以像这样写试试:
File excelFile = new File("D://test.xls"); InputStream fileInStream = new FileInputStream(this.excelFile); Workbook workBook = WorkbookFactory.create(this.fileInStream); . .
饮歌长啸
TA贡献1951条经验 获得超3个赞
报的是类型转换出错,HSSFWorkbook不能转换为Workbook
不能直接这样?:
HSSFWorkbook wb = new HSSFWorkbook();
添加回答
举报
0/150
提交
取消