|
|
|
@ -43,7 +43,7 @@ public class PoiUtil {
|
|
|
|
|
txt += "(*)";
|
|
|
|
|
XSSFRichTextString richText = new XSSFRichTextString(txt);//全部文字
|
|
|
|
|
|
|
|
|
|
richText.applyFont(0, len , fontBlack); // 从第0个字符到第2个字符应用font1
|
|
|
|
|
richText.applyFont(0, len, fontBlack); // 从第0个字符到第2个字符应用font1
|
|
|
|
|
richText.applyFont(len, len + 3, fontRed); // 从第2个字符到第4个字符应用font2
|
|
|
|
|
cell.setCellValue(richText);//设置文字
|
|
|
|
|
}
|
|
|
|
@ -273,4 +273,80 @@ public class PoiUtil {
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:设置整数类型格式
|
|
|
|
|
*
|
|
|
|
|
* @param wb
|
|
|
|
|
* @param sheetIdx
|
|
|
|
|
* @param colIdx
|
|
|
|
|
* @param firstRow
|
|
|
|
|
* @param lastRow
|
|
|
|
|
*/
|
|
|
|
|
public static void setIntegerStyle(Workbook wb, int sheetIdx, int colIdx, int firstRow, int lastRow) {
|
|
|
|
|
// 设置整数类型的样式
|
|
|
|
|
CellStyle integerStyle = wb.createCellStyle();
|
|
|
|
|
integerStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("0")); // 设置为整数类型
|
|
|
|
|
|
|
|
|
|
for (int i = firstRow; i <= lastRow; i++) {
|
|
|
|
|
Row row = wb.getSheetAt(sheetIdx).getRow(i);
|
|
|
|
|
if (row == null) row=wb.getSheetAt(sheetIdx).createRow(i);
|
|
|
|
|
// 设置整数类型的值
|
|
|
|
|
Cell integerCell = row.getCell(colIdx);
|
|
|
|
|
if (integerCell == null) {
|
|
|
|
|
integerCell = row.createCell(colIdx);
|
|
|
|
|
}
|
|
|
|
|
integerCell.setCellStyle(integerStyle); // 应用整数类型的样式
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:设置浮点数类型格式
|
|
|
|
|
*
|
|
|
|
|
* @param wb
|
|
|
|
|
* @param sheetIdx
|
|
|
|
|
* @param colIdx
|
|
|
|
|
* @param firstRow
|
|
|
|
|
* @param lastRow
|
|
|
|
|
*/
|
|
|
|
|
public static void setFloatStyle(Workbook wb, int sheetIdx, int colIdx, int firstRow, int lastRow) {
|
|
|
|
|
// 设置浮点数类型的样式
|
|
|
|
|
CellStyle floatStyle = wb.createCellStyle();
|
|
|
|
|
floatStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("0.00")); // 设置为浮点数类型,保留两位小数
|
|
|
|
|
for (int i = firstRow; i <= lastRow; i++) {
|
|
|
|
|
Row row = wb.getSheetAt(sheetIdx).getRow(i);
|
|
|
|
|
if (row == null) row=wb.getSheetAt(sheetIdx).createRow(i);
|
|
|
|
|
// 设置浮点数类型的值
|
|
|
|
|
Cell floatCell = row.getCell(colIdx);
|
|
|
|
|
if (floatCell == null) {
|
|
|
|
|
floatCell = row.createCell(colIdx);
|
|
|
|
|
}
|
|
|
|
|
floatCell.setCellStyle(floatStyle); // 应用浮点数类型的样式
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:设置日期格式
|
|
|
|
|
*
|
|
|
|
|
* @param wb
|
|
|
|
|
* @param sheetIdx
|
|
|
|
|
* @param colIdx
|
|
|
|
|
* @param firstRow
|
|
|
|
|
* @param lastRow
|
|
|
|
|
*/
|
|
|
|
|
public static void setDateStyle(Workbook wb, int sheetIdx, int colIdx, int firstRow, int lastRow) {
|
|
|
|
|
// 设置日期类型的样式
|
|
|
|
|
CellStyle dateStyle = wb.createCellStyle();
|
|
|
|
|
dateStyle.setDataFormat(wb.getCreationHelper().createDataFormat().getFormat("yyyy-mm-dd")); // 设置为日期类型,格式为yyyy-mm-dd
|
|
|
|
|
for (int i = firstRow; i <= lastRow; i++) {
|
|
|
|
|
Row row = wb.getSheetAt(sheetIdx).getRow(i);
|
|
|
|
|
if (row == null) row=wb.getSheetAt(sheetIdx).createRow(i);
|
|
|
|
|
// 设置日期类型的值
|
|
|
|
|
Cell dateCell = row.getCell(colIdx);
|
|
|
|
|
if (dateCell == null) {
|
|
|
|
|
dateCell = row.createCell(colIdx);
|
|
|
|
|
}
|
|
|
|
|
dateCell.setCellStyle(dateStyle); // 应用日期类型的样式
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|