POI之读写Excel

Workbook之xls/xlsx

一、开发须知

Workbook可对excel(2003,2007,2010)版本(xls、xlsx)进行基本读写,HSSFWorkbook与XSSFWorkbook是其实现类。

二、基本示例

public void workbookPOI() throws Exception{
  Workbook workbook = null;
  InputStream is = new FileInputStream(filePath);
  workbook = WorkbookFactory.create(is);
  Sheet sheet = workbook.getSheetAt(0);
  Row row =sheet.getRow(0);
  Cell cell= row.getCell(0);
  System.out.println(cell.toString());
}

HSSFWorkbook之xls

一、开发须知

HSSFWorkbook专门针对excel2003版本(xls)进行读写。

二、基本示例

public void hssfworkbookPOI() throws Exception{
  InputStream is = new FileInputStream(filePath);
  HSSFWorkbook workbook = new HSSFWorkbook(is));
  HSSFSheet sheet = workbook.getSheetAt(0);
  HSSFRow row =sheet.getRow(0);
  HSSFCell cell= row.getCell(0);
  System.out.println(cell.toString());
}

XSSFWorkbook之xlsx

一、开发须知

XSSFWorkbook专门针对非excel2003版本(xlsx)进行读写。

二、基本示例

public void hssfworkbookPOI() throws Exception{
  InputStream is = new FileInputStream(filePath);
  XSSFWorkbook workbook = new HSSFWorkbook(is));
  XSSFSheet sheet = workbook.getSheetAt(0);
  XSSFRow row =sheet.getRow(0);
  XSSFCell cell= row.getCell(0);
  System.out.println(cell.toString());
}

发帖时间: POI

发表评论

电子邮件地址不会被公开。 必填项已用*标注