CodePhiliaX/fastexcel

导出如何将@ExcelProperty("*名称")中的 * 设置为红色

Closed this issue · 2 comments

This kind of requirement is uncommon, and I’m unsure if adding this functionality is necessary (since it’s a minor formatting adjustment for a table). Nevertheless, I’ll document your suggestion and bring it up for discussion in future development.

可以先基于AbstractVerticalCellStyleStrategy实现:

public class VerticalCellStyleStrategyExt extends AbstractVerticalCellStyleStrategy {
	@Override
	protected void setHeadCellStyle(CellWriteHandlerContext context) {
		super.setHeadCellStyle(context);
		// 如果最后一个字符为*,就改为红色
		String stringValue = context.getCell().getStringCellValue();
		if (stringValue.endsWith("* ")) {
			// 定义红色字体
			XSSFRichTextString xssfRichTextString = new XSSFRichTextString(stringValue);
			xssfRichTextString.applyFont(stringValue.length() - 1, stringValue.length(), Constants.RED_WRITE_FONT);
			context.getCell().setCellValue(xssfRichTextString);
		}
	}
}