JAVA 读Excel 表格中的数据.

import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class ImportExcel { public static void main(String[] args) { String filePath = "E:\\kemu.xls"; File myFile = new File(filePath); String strAdd = ""; try { FileInputStream fis = new FileInputStream(myFile); HSSFWorkbook workbook; workbook = new HSSFWorkbook(fis); HSSFSheet sheet = null; HSSFRow row = null; HSSFCell cell = null; SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd"); String strPrefix = sdf1.format(new Date()); if (workbook != null) { sheet = workbook.getSheetAt(0); } if (sheet == null) { System.out.println("不能导入空的Excel文件!"); } if (sheet != null) { row = sheet.getRow(5);// 从第五行开始读取 } for (int j = 5; row != null; j++, row = sheet.getRow(j)) { strAdd = ""; for (int index = 1; index <= 10; index++) { cell = row.getCell((short) (index - 1)); if (cell != null) { if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { strAdd = cell.getStringCellValue(); } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { strAdd = String.valueOf(cell.getNumericCellValue()); }else if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) { strAdd = ""; } } System.out.println(strAdd); } } } catch (FileNotFoundException e) { e.printStackTrace(); }catch( IOException ie ){ ie.printStackTrace(); } } }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值