69 lines
3.4 KiB
Java
69 lines
3.4 KiB
Java
package com.adc.da.common;
|
|
|
|
import com.adc.da.slrs.standardSplit.vo.MarkTextVO;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @Description:
|
|
* @Author: yangxuenan
|
|
* date: 2020/3/24 15:28
|
|
*/
|
|
public class HtmlTextExcel {
|
|
|
|
public static String changeHtmlToExcel (String itemContent, List<MarkTextVO> addList, List<MarkTextVO> delList) {
|
|
if (StringUtils.isNotEmpty(itemContent)) {
|
|
itemContent = itemContent.replaceAll("<div>","");
|
|
itemContent = itemContent.replaceAll("<div class=\"compareBackgroundColor\">","");
|
|
itemContent = itemContent.replaceAll("</div>","\n");
|
|
itemContent = itemContent.replaceAll("<p>","");
|
|
itemContent = itemContent.replaceAll("</p>","\n");
|
|
//获取所有新增内容的位置
|
|
String splitContentAdd = itemContent;
|
|
int addSpiltIndex = 0;
|
|
int cirIndex = 0;
|
|
int stLen = "<span class=\"insertClass\">".length();
|
|
int edLen = "</span>".length();
|
|
while (splitContentAdd.contains("<span class=\"insertClass\">")) {
|
|
int addStIndex = splitContentAdd.indexOf("<span class=\"insertClass\">");
|
|
int addEdIndex = splitContentAdd.indexOf("</span>");
|
|
if (addStIndex > -1) {
|
|
MarkTextVO markTextVO = new MarkTextVO();
|
|
markTextVO.setStartIndex(addSpiltIndex + addStIndex - (cirIndex*(stLen+edLen)));
|
|
markTextVO.setEndIndex(addSpiltIndex + addEdIndex - (cirIndex*(stLen+edLen)) - stLen);
|
|
addList.add(markTextVO);
|
|
addSpiltIndex = addSpiltIndex + addEdIndex + 7;
|
|
// String replaceStr = splitContentAdd.substring(0,addStIndex);
|
|
splitContentAdd = splitContentAdd.substring(addEdIndex + 7,splitContentAdd.length());
|
|
cirIndex++;
|
|
}
|
|
}
|
|
//获取所有删除内容的位置
|
|
String splitContentDel = itemContent;
|
|
int delSpiltIndex = 0;
|
|
int cirIndexDel = 0;
|
|
int stLenDel = "<span class=\"delClass\">".length();
|
|
int edLenDel = "</span>".length();
|
|
while (splitContentDel.contains("<span class=\"delClass\">")) {
|
|
int delStIndex = splitContentDel.indexOf("<span class=\"delClass\">");
|
|
int delEdIndex = splitContentDel.indexOf("</span>");
|
|
if (delStIndex > -1) {
|
|
MarkTextVO markTextVO = new MarkTextVO();
|
|
markTextVO.setStartIndex(delSpiltIndex + delStIndex - (cirIndexDel*(stLenDel+edLenDel)));
|
|
markTextVO.setEndIndex(delSpiltIndex + delEdIndex - (cirIndexDel*(stLenDel+edLenDel)) - stLenDel);
|
|
delList.add(markTextVO);
|
|
delSpiltIndex = delSpiltIndex + delEdIndex + 7;
|
|
// String replaceStr = splitContentDel.substring(0,delStIndex);
|
|
splitContentDel = splitContentDel.substring(delEdIndex + 7,splitContentDel.length());
|
|
cirIndexDel++;
|
|
}
|
|
}
|
|
itemContent = itemContent.replaceAll("<span class=\"insertClass\">","");
|
|
itemContent = itemContent.replaceAll("</span>","");
|
|
itemContent = itemContent.replaceAll("<span class=\"delClass\">","");
|
|
itemContent = itemContent.replaceAll("</span>","");
|
|
}
|
|
return itemContent;
|
|
}
|
|
}
|