com.kovizone.poi.ooxml.plus.processor.WriteStringReplaceProcessors Maven / Gradle / Ivy
The newest version!
package com.kovizone.poi.ooxml.plus.processor;
import com.kovizone.poi.ooxml.plus.anno.WriteStringReplace;
import com.kovizone.poi.ooxml.plus.api.processor.WriteProcessor;
import com.kovizone.poi.ooxml.plus.command.ExcelCommand;
import java.lang.reflect.Field;
/**
* StringReplace注解处理器
*
* @author KoviChen
*/
public class WriteStringReplaceProcessors implements WriteProcessor {
@Override
public Object dataBodyProcess(WriteStringReplace writeStringReplace,
ExcelCommand excelCommand,
Field targetField,
Object columnValue) {
String[] target = writeStringReplace.target();
String[] replacement = writeStringReplace.replacement();
if (target.length != replacement.length || target.length == 0) {
return columnValue;
}
String strValue = String.valueOf(columnValue);
for (int i = 0; i < target.length; i++) {
String t = excelCommand.parseString(target[i]);
String r = excelCommand.parseString(replacement[i]);
strValue = strValue.replace(t, r);
}
return strValue;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy