TagUtil.checkTags方法主要检查报表是否含有重复标签,代码如下
public static Set<String> checkTags(String ssjson) {
MyWorkbook workbook = SpreadWorkbook.parse(ssjson);
Set<String> tags = workbook.init();
log.info("重复标签:" + tags);
return tags;
}
GcExcelHelper.showTags(formData, duplicateTags)方法如如下,duplicateTags是TagUtil.checkTags执行之后存在的重复标签:
public static String showTags(String ssjson, Set<String> duplicateTags) {
Workbook workbook = readFromJson(ssjson);
IWorksheets worksheets = workbook.getWorksheets();
worksheets.forEach(worksheet -> {
IRange usedRange = worksheet.getUsedRange();
//去除数据校验
usedRange.getValidation().delete();
if (Objects.nonNull(usedRange)) {
int colCount = usedRange.getColumnCount();
int rowCount = usedRange.getRowCount();
for (int i = 0; i < rowCount; i++) {
for (int j = 0; j < colCount; j++) {
IRange cell = worksheet.getRange(i, j);
if (Objects.nonNull(cell.getTag())) {
String tag = cell.getTag().toString();
cell.setValue(tag);
//cell.autoFit();
if (duplicateTags.contains(tag)) {
//重复标签需要标红
cell.getInterior().setColor(Color.GetRed());
}
}
}
}
}
});
return workbook.toJson();
} |