1、POI有三种API:
-
POI-HSSF
-
POI-XSSF
-
SXSSF
ps:HSSF、XSSF、SXSSF的区别,可参考博客:https://blog.csdn.net/SudaDays/article/details/90669237
二、java基于poi源码操作excel之XSSFCell源码类
参考博客:https://blog.csdn.net/weixin_48726433/article/details/120908045
XSSFCell源码类
pom配置
1 <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> 2 <dependency> 3 <groupId>org.apache.poi</groupId> 4 <artifactId>poi-ooxml</artifactId> 5 <version>4.1.2</version> 6 </dependency>
源码类
public final class XSSFCell extends CellBase
构造方法
protected XSSFCell(XSSFRow row, CTCell cell)
XSSFCell类中的构造方法是受保护的,所以我们不能进行实例化; 那么我们可以通过XSSFRow类中的getCell(int cellnum)方法获取XSSFCell类对象; 再通过对象调用以下方法↓
普通方法
//Returns the sheet this cell belongs to public XSSFSheet getSheet() //Returns the row this cell belongs to public XSSFRow getRow() //以布尔值获取单元格的值 public boolean getBooleanCellValue() //为单元格设置布尔值 public void setCellValue(boolean value) //以数字形式获取单元格的值 public double getNumericCellValue() //为单元格设置数值 public void setCellValue(double value) //以字符串形式获取单元格的值 public String getStringCellValue() //为单元格设置字符串值 public void setCellValue(String str) //以XSSFRichTextString的形式获取单元格的值 public XSSFRichTextString getRichStringCellValue() //为单元格设置XSSFRichTextString public void setCellValue(RichTextString str) //返回单元格的公式 public String getCellFormula() //为单元格设置公式 public void setCellFormula(String formula) //返回此单元格的列索引 public int getColumnIndex() //返回包含此单元格的工作表中某一行的行索引 public int getRowIndex() //获取单元格的值为日期 public Date getDateCellValue() //为单元格设置日期 public void setCellValue(Date value) //返回错误消息 public String getErrorCellString() //为单元格设置错误消息 public void setCellErrorValue(byte errorCode) //返回单元格类型 public CellType getCellType()
参考博客:https://blog.csdn.net/weixin_48726433/article/details/120906652
XSSFRow类源码
pom配置
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency>
源码类
public class XSSFRow implements Row, Comparable<XSSFRow>
构造方法
protected XSSFRow(CTRow row, XSSFSheet sheet)
XSSFRow类中的构造方法是受保护的,所以我们不能进行实例化; 那么我们可以通过XSSFSheet类中的getRow(int rownum)方法获取XSSFRow类对象; 再通过对象调用以下方法↓
普通方法
//Returns the XSSFSheet this row belongs to public XSSFSheet getSheet() //创建 public XSSFCell createCell(int columnIndex) public XSSFCell createCell(int columnIndex, CellType type) //据下标得到对应的单元格 public XSSFCell getCell(int cellnum) //得到行第1个和最后1个单元格的下标 public short getFirstCellNum() public short getLastCellNum() //得到行下标 public int getRowNum() //获取已定义的单元格数 public int getPhysicalNumberOfCells() //删除 public void removeCell(Cell cell)