SheetData sheetData=getSheetData(sc.sheetName);
sc.cellChangeDTOs.forEach(cc->{
Row row= sheetData.getRow().stream().filter(r-> r.getR()==cc.rowIndex).findFirst().get();
Cell cell= row.getC().stream().filter(c-> c.getR().equals(cc.cellIndex)).findFirst().get();
STCellType stCellType= cell.getT();
Params params= new Params();
params.cell=cell;
params.sharedStrings=sharedStrings;
typeHandlersMap.get(stCellType).apply(params).replaceText("{"+cc.identifier+"}", cc.value);
private static class SCellType extends CellTypeHandler{
SharedStrings sharedStrings;
@Override
String getCellText() {
//CTRst sharedElement=sharedStrings.getJaxbElement().getSi().get(Integer.parseInt(cell.getV()));
CTRst sharedElement=getShredStringElement();
CTXstringWhitespace ctXstringWhitespace=sharedElement.getT();
String text=null;
if(ctXstringWhitespace!=null){
text=ctXstringWhitespace.getValue();
}else{
if(!sharedElement.getR().isEmpty()){
StringBuffer stringBuffer= new StringBuffer();
for(CTRElt ctrElt:sharedElement.getR() ){
stringBuffer.append(ctrElt.getT().getValue());
}
text=stringBuffer.toString();
}
}
return text;
}
synchronized CTRst getShredStringElement(){
return sharedStrings.getJaxbElement().getSi().get(Integer.parseInt(cell.getV()));
}
@Override
void replaceText(String identifier, String value) {
CTRst sharedElement=getShredStringElement();
CTXstringWhitespace ctXstringWhitespace=sharedElement.getT();
String text=ctXstringWhitespace.getValue();
text=StringUtils.replace(text, identifier, value);
ctXstringWhitespace.setValue(text);
}
}
private static class StrTypeHandler extends CellTypeHandler{
@Override
String getCellText() {
return cell.getV();
}
@Override
void replaceText(String identifier, String value) {
String text=cell.getV();
text=StringUtils.replace(text, identifier, value);
cell.setV(text);
}
}
private static Map<STCellType, Function<Params, CellTypeHandler>> typeHandlersMap = new HashMap<STCellType, Function<Params, CellTypeHandler>>(){{
put(STCellType.S, t->{
SCellType sCellType= new SCellType();
sCellType.cell=t.cell;
sCellType.sharedStrings=t.sharedStrings;
return sCellType;
}
);
put(STCellType.STR, t-> {
StrTypeHandler strTypeHandler= new StrTypeHandler();
strTypeHandler.cell=t.cell;
return strTypeHandler;
}
);
}};
cell.setT(org.xlsx4j.sml.STCellType.S);
Users browsing this forum: No registered users and 2 guests