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 addList, List delList) { if (StringUtils.isNotEmpty(itemContent)) { itemContent = itemContent.replaceAll("
",""); itemContent = itemContent.replaceAll("
",""); itemContent = itemContent.replaceAll("
","\n"); itemContent = itemContent.replaceAll("

",""); itemContent = itemContent.replaceAll("

","\n"); //获取所有新增内容的位置 String splitContentAdd = itemContent; int addSpiltIndex = 0; int cirIndex = 0; int stLen = "".length(); int edLen = "".length(); while (splitContentAdd.contains("")) { int addStIndex = splitContentAdd.indexOf(""); int addEdIndex = splitContentAdd.indexOf(""); 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 = "".length(); int edLenDel = "".length(); while (splitContentDel.contains("")) { int delStIndex = splitContentDel.indexOf(""); int delEdIndex = splitContentDel.indexOf(""); 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("",""); itemContent = itemContent.replaceAll("",""); itemContent = itemContent.replaceAll("",""); itemContent = itemContent.replaceAll("",""); } return itemContent; } }