POI低版本像高版本升級時新舊方法對應


低版本升級高版本

1.1 顏色定義變化

舊:

setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index)

cellStyle.setBottomBorderColor(HSSFColor.BLACK.getIndex());

cellStyle.setTopBorderColor(HSSFColor.BLACK.getIndex());

新:

setFillForegroundColor(IndexedColors.SKY_BLUE.index)

setBottomBorderColor(IndexedColors.BLACK.getIndex());

setTopBorderColor(IndexedColors.BLACK.getIndex());

1.2 獲取單元格格式

舊:

cell.getCellType() < 2

CELL_TYPE_NUMERIC =0

CELL_TYPE_STRING = 1

CELL_TYPE_FORMULA = 2

Cell.CELL_TYPE_NUMERIC

新:

cell.getCellTypeEnum().NUMERIC == CellType.NUMERIC || cell.getCellTypeEnum().NUMERIC == CellType.STRING

CellType.NUMERIC

1.3 設置單元格格式

舊 :

row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);

新 :

row.getCell(0).setCellType(CellType.STRING);

1.4 設置單元格垂直居中樣式

舊:

setAlignment(XSSFCellStyle.ALIGN_CENTER); // 居中

setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);//垂直

新:

setAlignment(HorizontalAlignment.CENTER); // 居中

setVerticalAlignment(VerticalAlignment.CENTER); //垂直

1.5 設置邊框

舊:

setBorderBottom(HSSFCellStyle.BORDER_THIN); //下邊框

setBorderLeft(HSSFCellStyle.BORDER_THIN);

setBorderRight(HSSFCellStyle.BORDER_THIN);

setBorderTop(HSSFCellStyle.BORDER_THIN);

新:

setBorderBottom(BorderStyle.THIN); //下邊框

setBorderLeft(BorderStyle.THIN);

setBorderRight(BorderStyle.THIN);

setBorderTop(BorderStyle.THIN);

1.6 合並單元格

舊:

addMergedRegion(new CellRangeAddress(1, 1,(short) 0, (short) 0));// 起始行,結束行,起始列,結束列

新:

addMergedRegion(new Region(1, (short) 0, 1,(short) 0));// 起始行,起始列,結束行,結束列

1.7 設置字體加粗

setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

新:

setBold(true)

1.8 字體顏色

舊:

setColor(HSSFColor.BLACK.index)

新:

setColor(IndexedColors.BLACK.getIndex())

1.9設置樣式

舊:

setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);

新:

setFillPattern(FillPatternType.SOLID_FOREGROUND);

setFillForegroundColor(IndexedColors.SKY_BLUE.index);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM