@@ -36,13 +36,13 @@ public class CellIng {
Map . entry ( " SLANTEDDASHDOT " , " 斜点划线 " )
) ;
// 获取左框线样式
public String getLeftBorderStyle ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb ) {
public String getLeftBorderStyle ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb , String keyWords ) {
CellStyle style = cell . getCellStyle ( ) ;
BorderStyle border = style . getBorderLeft ( ) ;
return border ! = null ? borderStyleChineseMap . getOrDefault ( border . name ( ) , border . name ( ) ) : " 无 " ;
}
// 获取左框线颜色
public String getLeftBorderColor ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb ) {
public String getLeftBorderColor ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb , String keyWords ) {
CellStyle style = cell . getCellStyle ( ) ;
if ( style instanceof XSSFCellStyle ) {
XSSFCellStyle xssfStyle = ( XSSFCellStyle ) style ;
@@ -53,14 +53,14 @@ public class CellIng {
}
// 获取上框线样式
public String getTopBorderStyle ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb ) {
public String getTopBorderStyle ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb , String keyWords ) {
CellStyle style = cell . getCellStyle ( ) ;
BorderStyle border = style . getBorderTop ( ) ;
return border ! = null ? borderStyleChineseMap . getOrDefault ( border . name ( ) , border . name ( ) ) : " 无 " ;
}
// 获取上框线颜色
public String getTopBorderColor ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb ) {
public String getTopBorderColor ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb , String keyWords ) {
CellStyle style = cell . getCellStyle ( ) ;
if ( style instanceof XSSFCellStyle ) {
XSSFCellStyle xssfStyle = ( XSSFCellStyle ) style ;
@@ -70,14 +70,14 @@ public class CellIng {
}
// 获取右框线样式
public String getRightBorderStyle ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb ) {
public String getRightBorderStyle ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb , String keyWords ) {
CellStyle style = cell . getCellStyle ( ) ;
BorderStyle border = style . getBorderRight ( ) ;
return border ! = null ? borderStyleChineseMap . getOrDefault ( border . name ( ) , border . name ( ) ) : " 无 " ;
}
// 获取右框线颜色
public String getRightBorderColor ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb ) {
public String getRightBorderColor ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb , String keyWords ) {
CellStyle style = cell . getCellStyle ( ) ;
if ( style instanceof XSSFCellStyle ) {
XSSFCellStyle xssfStyle = ( XSSFCellStyle ) style ;
@@ -87,14 +87,14 @@ public class CellIng {
}
// 获取下框线样式
public String getBottomBorderStyle ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb ) {
public String getBottomBorderStyle ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb , String keyWords ) {
CellStyle style = cell . getCellStyle ( ) ;
BorderStyle border = style . getBorderBottom ( ) ;
return border ! = null ? borderStyleChineseMap . getOrDefault ( border . name ( ) , border . name ( ) ) : " 无 " ;
}
// 获取下框线颜色
public String getBottomBorderColor ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb ) {
public String getBottomBorderColor ( Cell cell , org . apache . poi . ss . usermodel . Workbook wb , String keyWords ) {
CellStyle style = cell . getCellStyle ( ) ;
if ( style instanceof XSSFCellStyle ) {
XSSFCellStyle xssfStyle = ( XSSFCellStyle ) style ;
@@ -103,16 +103,34 @@ public class CellIng {
return " 无 " ;
}
// 获取单元格的公式表达式(字符串形式)
public String getFormulaExpression ( Cell cell , Workbook wb ) {
public String getFormulaExpression ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
if ( cell . getCellType ( ) = = CellType . FORMULA ) {
return cell . getCellFormula ( ) ;
}
return " 无 " ;
}
// 获取单元格的公式表达式关键字
public String getFormulaExpressionContains ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
if ( cell . getCellType ( ) = = CellType . FORMULA ) {
String formula = cell . getCellFormula ( ) ;
// 转为小写再比较
if ( formula . toLowerCase ( ) . contains ( keyWords . toLowerCase ( ) ) ) {
return formula ; // 包含关键字时返回公式内容
} else {
return " 否 " ; // 不包含关键字
}
}
return " 否 " ;
}
// 获取单元格的公式计算结果(已经计算出来的值,字符串形式)
public String getFormulaResult ( Cell cell , Workbook wb ) {
public String getFormulaResult ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
if ( cell . getCellType ( ) ! = CellType . FORMULA ) {
return null ; // 不是公式单元格返回null
@@ -138,7 +156,7 @@ public class CellIng {
}
// 获取单元格字体名称
public String getFontName ( Cell cell , Workbook wb ) {
public String getFontName ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 无 " ;
@@ -152,7 +170,7 @@ public class CellIng {
}
// 获取单元格字体字号
public String getFontSize ( Cell cell , Workbook wb ) {
public String getFontSize ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 无 " ;
@@ -170,7 +188,7 @@ public class CellIng {
// 获取单元格字形(加粗 / 斜体 )
public String getFontStyle ( Cell cell , Workbook wb ) {
public String getFontStyle ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 无 " ;
@@ -190,7 +208,7 @@ public class CellIng {
// 获取单元格下划线
// 获取单元格下划线类型
public String getUnderline ( Cell cell , Workbook wb ) {
public String getUnderline ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 无 " ;
@@ -217,7 +235,7 @@ public class CellIng {
}
// 获取单元格颜色
public String getFontColor ( Cell cell , Workbook wb ) {
public String getFontColor ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 无 " ;
@@ -242,7 +260,7 @@ public class CellIng {
return " 无 " ;
}
// 删除线
public static String getCellStrikeThrough ( Cell cell , Workbook wb ) {
public static String getCellStrikeThrough ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 否 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 否 " ;
@@ -251,7 +269,7 @@ public class CellIng {
}
// 上标
public static String getCellSuperScript ( Cell cell , Workbook wb ) {
public static String getCellSuperScript ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 否 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 否 " ;
@@ -260,7 +278,7 @@ public class CellIng {
}
// 下标
public static String getCellSubScript ( Cell cell , Workbook wb ) {
public static String getCellSubScript ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 否 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 否 " ;
@@ -271,7 +289,7 @@ public class CellIng {
// 获取斜下框线样式
public static String getDiagonalDownBorderStyle ( Cell cell , Workbook wb ) {
public static String getDiagonalDownBorderStyle ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null | | ! ( cell instanceof XSSFCell ) ) return " 无 " ;
XSSFCellStyle style = ( XSSFCellStyle ) cell . getCellStyle ( ) ;
@@ -297,7 +315,7 @@ public class CellIng {
}
// 斜下框线→颜色
public static String getDiagonalDownBorderColor ( Cell cell , Workbook wb ) {
public static String getDiagonalDownBorderColor ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null | | ! ( cell instanceof XSSFCell ) ) return " 无 " ;
XSSFCellStyle style = ( XSSFCellStyle ) cell . getCellStyle ( ) ;
@@ -320,7 +338,7 @@ public class CellIng {
}
// 斜上框线→样式
public static String getDiagonalUpBorderStyle ( Cell cell , Workbook wb ) {
public static String getDiagonalUpBorderStyle ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null | | ! ( cell instanceof XSSFCell ) ) return " 无 " ;
XSSFCellStyle style = ( XSSFCellStyle ) cell . getCellStyle ( ) ;
@@ -342,7 +360,7 @@ public class CellIng {
}
// 斜上框线→颜色
public static String getDiagonalUpBorderColor ( Cell cell , Workbook wb ) {
public static String getDiagonalUpBorderColor ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null | | ! ( cell instanceof XSSFCell ) ) return " 无 " ;
XSSFCellStyle style = ( XSSFCellStyle ) cell . getCellStyle ( ) ;
@@ -380,14 +398,14 @@ public class CellIng {
// ===== 获取单元格文本( String) =====
public String getCellText ( Cell cell , Workbook wb ) {
public String getCellText ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
DataFormatter formatter = new DataFormatter ( ) ;
return formatter . formatCellValue ( cell ) ;
}
// ===== 获取单元格值
public String getCellValue ( Cell cell , Workbook wb ) {
public String getCellValue ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " " ;
switch ( cell . getCellType ( ) ) {
@@ -436,7 +454,7 @@ public class CellIng {
}
// 数字格式
public static String getCellDataFormat ( Cell cell , Workbook wb ) {
public static String getCellDataFormat ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 无 " ;
@@ -444,7 +462,7 @@ public class CellIng {
}
// 水平对齐
public static String getCellHorizontalAlignment ( Cell cell , Workbook wb ) {
public static String getCellHorizontalAlignment ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 无 " ;
@@ -453,7 +471,7 @@ public class CellIng {
}
// 垂直对齐
public static String getCellVerticalAlignment ( Cell cell , Workbook wb ) {
public static String getCellVerticalAlignment ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 无 " ;
@@ -462,7 +480,7 @@ public class CellIng {
}
// 缩进
public static String getCellIndent ( Cell cell , Workbook wb ) {
public static String getCellIndent ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 0 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 0 " ;
@@ -470,7 +488,7 @@ public class CellIng {
}
// 自动换行
public static String getCellWrapText ( Cell cell , Workbook wb ) {
public static String getCellWrapText ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 否 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 否 " ;
@@ -478,7 +496,7 @@ public class CellIng {
}
// 缩小字体填充( ShrinkToFit)
public static String getCellShrinkToFit ( Cell cell , Workbook wb ) {
public static String getCellShrinkToFit ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 否 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 否 " ;
@@ -486,7 +504,7 @@ public class CellIng {
}
// 合并单元格
public static String getCellMerged ( Cell cell , Workbook wb ) {
public static String getCellMerged ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null | | wb = = null ) return " 否 " ;
Sheet sheet = cell . getSheet ( ) ;
if ( sheet = = null ) return " 否 " ;
@@ -505,7 +523,7 @@ public class CellIng {
// 文本方向( rotation)
public static String getCellTextRotation ( Cell cell , Workbook wb ) {
public static String getCellTextRotation ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 0 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 0 " ;
@@ -513,7 +531,7 @@ public class CellIng {
}
// 文本样式(加粗/斜体/下划线等)
public static String getCellFontStyle ( Cell cell , Workbook wb ) {
public static String getCellFontStyle ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null ) return " 无 " ;
CellStyle style = cell . getCellStyle ( ) ;
if ( style = = null ) return " 无 " ;
@@ -536,7 +554,7 @@ public class CellIng {
}
// 高度(行高)
public static String getCellRowHeight ( Cell cell , Workbook wb ) {
public static String getCellRowHeight ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null | | cell . getSheet ( ) = = null ) return " 默认 " ;
Row row = cell . getRow ( ) ;
if ( row = = null ) return " 默认 " ;
@@ -544,7 +562,7 @@ public class CellIng {
}
// 宽度(列宽)
public static String getCellColumnWidth ( Cell cell , Workbook wb ) {
public static String getCellColumnWidth ( Cell cell , Workbook wb , String keyWords ) {
if ( cell = = null | | cell . getSheet ( ) = = null ) return " 默认 " ;
int colWidth = cell . getSheet ( ) . getColumnWidth ( cell . getColumnIndex ( ) ) ; // 单位 1/256字符
return String . format ( " %.2f pt " , colWidth / 256 . 0 * 7 ) ; // 约 7pt/字符宽,可根据字体调整