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)