public class ReadExcel {
public static void main(String[] args) throws Exception {
InputStream is = new FileInputStream(new File("c://SummaryHSSF.xls"));
//根据输入流创建Workbook对象
Workbook wb = WorkbookFactory.create(is);
//get到Sheet对象
Sheet sheet = wb.getSheetAt(0);
//这个必须用接口
for(Row row : sheet){
for(Cell cell : row){
//cell.getCellType是获得cell里面保存的值的type
//如Cell.CELL_TYPE_STRING
switch(cell.getCellType()){
case Cell.CELL_TYPE_BOOLEAN:
//得到Boolean对象的方法
System.out.print(cell.getBooleanCellValue()+" ");
break;
case Cell.CELL_TYPE_NUMERIC:
//先看是否是日期格式
if(DateUtil.isCellDateFormatted(cell)){
//读取日期格式
System.out.print(cell.getDateCellValue()+" ");
}else{
//读取数字
System.out.print(cell.getNumericCellValue()+" ");
}
break;
case Cell.CELL_TYPE_FORMULA:
//读取公式
System.out.print(cell.getCellFormula()+" ");
break;
case Cell.CELL_TYPE_STRING:
//读取String
System.out.print(cell.getRichStringCellValue().toString()+" ");
break;
}
}
System.out.println("");
}
}
}
分享到:
相关推荐
是关于读去excel中的数据,并且把excel中的信息封装到一个对象中。
使用vs2012开发,C# winform 可视化操作选择Excel文件并读取内容显示到DataTable
lua读取excel,用于批量数据的读写
use qt software to read excel data QT读取EXCEL表格数据并进行显示的两种方法,具体描述参考博客https://blog.csdn.net/import_new/article/details/117003163,这是完整的QT源码,欢迎学习交流
Using the QT software to open excel
该小工具功能为提取指定EXCEL文件中指定区域内的数据,并且可以重新导出为EXCEL文件。帮助他人提高工作效率
Unity读取Excel,包括一个简单的Demo和必要的dll文件。谢谢下载!谢谢下载!谢谢下载!谢谢下载!谢谢下载!
C# excel read oledb dataset