|
@@ -1,427 +1,320 @@
|
|
package org.springblade.manager.controller;
|
|
package org.springblade.manager.controller;
|
|
|
|
|
|
-import com.spire.xls.Workbook;
|
|
|
|
-import com.spire.xls.Worksheet;
|
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Element;
|
|
import org.jsoup.nodes.Element;
|
|
import org.jsoup.select.Elements;
|
|
import org.jsoup.select.Elements;
|
|
-import org.springblade.common.utils.MathUtil;
|
|
|
|
import org.springblade.core.tool.utils.FileUtil;
|
|
import org.springblade.core.tool.utils.FileUtil;
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
import org.springblade.core.tool.utils.ResourceUtil;
|
|
import org.springblade.core.tool.utils.ResourceUtil;
|
|
-import org.springblade.manager.entity.WbsFormElement;
|
|
|
|
|
|
+import org.springblade.manager.service.IExctabCellService;
|
|
|
|
|
|
-import java.io.*;
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
-import java.util.stream.Collectors;
|
|
|
|
-import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
-public class ExpaileHtml {
|
|
|
|
|
|
+public class ExpaileHtml {
|
|
|
|
|
|
- public static void main(String[] args) throws IOException {
|
|
|
|
- // getHtmlInfo();
|
|
|
|
- try {
|
|
|
|
- Thread.sleep(500);
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- //String inHtmlUrl = "/Users/hongchuangyanfa/Desktop/123654.html";
|
|
|
|
- getjiexiInfo();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- public static void getjiexiInfo() throws IOException {
|
|
|
|
- String inHtmlUrl = "/Users/hongchuangyanfa/Desktop/123654.html";
|
|
|
|
- File file = ResourceUtil.getFile(inHtmlUrl);
|
|
|
|
- FileInputStream inputStream = new FileInputStream(file);
|
|
|
|
- String htmlString = IoUtil.readToString(inputStream);
|
|
|
|
|
|
+ // private final IExctabCellService exctabCellService;
|
|
|
|
|
|
- // 获取比对数据
|
|
|
|
- List<WbsFormElement> dataList = getWbsInfo();
|
|
|
|
|
|
+ /* public static void main(String[] args) throws IOException {
|
|
|
|
+ String thmlUrl = "/Users/hongchuangyanfa/Desktop/1539066383856304128.html" ;
|
|
|
|
+ expailHtmlInfo(thmlUrl);
|
|
|
|
+ }
|
|
|
|
+*/
|
|
|
|
+ // 清表上传解析方案
|
|
|
|
+ public static void expailHtmlInfo(String thmlUrl) throws FileNotFoundException {
|
|
|
|
|
|
- String dataInfox = dataList.stream().map(WbsFormElement::getEName).collect(Collectors.joining(","));
|
|
|
|
|
|
+ // 读取
|
|
|
|
+ File file1 = ResourceUtil.getFile(thmlUrl);
|
|
|
|
+ String htmlString = IoUtil.readToString(new FileInputStream(file1));
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ 解析
|
|
|
|
+ 1 解析样式
|
|
|
|
+ 2 计算坐标
|
|
|
|
+ 3 计算区域位置
|
|
|
|
+ */
|
|
|
|
+ // 样式集合
|
|
Document doc = Jsoup.parse(htmlString);
|
|
Document doc = Jsoup.parse(htmlString);
|
|
|
|
+ // 解析 style
|
|
|
|
+ Map<String ,String > styleMap = getHtmlStyle(doc);
|
|
|
|
+
|
|
|
|
+ //解析
|
|
Element table = doc.select("table").first();
|
|
Element table = doc.select("table").first();
|
|
Elements trs = table.select("tr");
|
|
Elements trs = table.select("tr");
|
|
|
|
|
|
|
|
+ // 获取总行列数
|
|
|
|
+ int maxCol = doc.select("Col").size();
|
|
|
|
+ String [] rowData = new String[trs.size()+1];
|
|
|
|
|
|
- // 标题坐标
|
|
|
|
- List<Map<String,String>> zikey = new ArrayList<>();
|
|
|
|
|
|
+ // 行的状态
|
|
|
|
+ boolean index_state = false;
|
|
|
|
+ // 区域划分表示
|
|
|
|
+ int xy_type = 1 ;
|
|
|
|
|
|
- int index_id = 0;
|
|
|
|
- // 循环解析
|
|
|
|
- for(int i = 0 ;i < trs.size() ;i++) {
|
|
|
|
|
|
+ // 解析 excel元素集合
|
|
|
|
+ Set<String> colTitleSet = new HashSet<>();
|
|
|
|
+
|
|
|
|
+// 标题集合信息
|
|
|
|
+ List<Map<String,String>> zikey = new ArrayList<>();
|
|
|
|
+ for(int i = 0 ;i <=trs.size()-1 ;i++) {
|
|
Element tr = trs.get(i);
|
|
Element tr = trs.get(i);
|
|
- boolean index_stat = Boolean.parseBoolean(tr.attr("indexStat"));
|
|
|
|
Elements tds = tr.select("td");
|
|
Elements tds = tr.select("td");
|
|
|
|
+ String xyInof = getTrInfo(tds,styleMap,index_state,xy_type,maxCol);
|
|
|
|
+ xy_type = Integer.parseInt(xyInof.split(",")[0]);
|
|
|
|
+ tr.attr("xy_type",xyInof);
|
|
|
|
+ index_state = Boolean.parseBoolean(xyInof.split(",")[1]);
|
|
|
|
+ boolean isMaxCol = Integer.parseInt(xyInof.split(",")[2])==maxCol;
|
|
|
|
+ // 计算单元格坐标
|
|
|
|
+ int x= 0;
|
|
for (int j = 0; j < tds.size(); j++) {
|
|
for (int j = 0; j < tds.size(); j++) {
|
|
- Element data = tds.get(j);
|
|
|
|
- String textInfo = data.text();
|
|
|
|
- int x1 = Integer.parseInt( data.attr("x1"));
|
|
|
|
- int x2 = Integer.parseInt( data.attr("x2"));
|
|
|
|
- int y1 = Integer.parseInt( data.attr("y1"));
|
|
|
|
- int y2 = Integer.parseInt( data.attr("y2"));
|
|
|
|
- int xytype = Integer.parseInt( data.attr("xytype"));
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if(!textInfo.isEmpty() && !textInfo.equals("/")){
|
|
|
|
- Map<String,String> dataInfo =new HashMap<String,String>();
|
|
|
|
- dataInfo.put("name",textInfo);
|
|
|
|
- dataInfo.put("x1",data.attr("x1"));
|
|
|
|
- dataInfo.put("x2",data.attr("x2"));
|
|
|
|
- dataInfo.put("y1",data.attr("y1"));
|
|
|
|
- dataInfo.put("y2",data.attr("y2"));
|
|
|
|
- dataInfo.put("xytype",data.attr("xytype"));
|
|
|
|
- zikey.add(dataInfo);
|
|
|
|
- }else if(data.html().indexOf("input")>=0){
|
|
|
|
-
|
|
|
|
- List arrayList = new ArrayList<>();
|
|
|
|
- List left = new ArrayList<>();
|
|
|
|
- List top = new ArrayList<>();
|
|
|
|
- for(int k=0 ; k< zikey.size() ;k++){
|
|
|
|
- String name = zikey.get(k).get("name").replaceAll("[^\u4E00-\u9FA5]", "");
|
|
|
|
- int xx1 = Integer.parseInt( zikey.get(k).get("x1"));
|
|
|
|
- int xx2 = Integer.parseInt( zikey.get(k).get("x2"));
|
|
|
|
- int yy1 = Integer.parseInt( zikey.get(k).get("y1"));
|
|
|
|
- int yy2 = Integer.parseInt( zikey.get(k).get("y2"));
|
|
|
|
- int xytype2 = Integer.parseInt( zikey.get(k).get("xytype"));
|
|
|
|
-
|
|
|
|
- // 左匹配
|
|
|
|
- if( yy1<=y1 && yy2>=y2 && xx2<x1 && StringUtils.isNotEmpty(name) && xytype2==xytype){
|
|
|
|
- left.add(name);
|
|
|
|
- if(!index_stat){
|
|
|
|
- break;
|
|
|
|
|
|
+ {
|
|
|
|
+ Element data = tds.get(j);
|
|
|
|
+ int colspan = data.attr("COLSPAN").equals("") ? 0 : Integer.parseInt(data.attr("COLSPAN"));
|
|
|
|
+ int rowspan = data.attr("ROWSPAN").equals("") ? 0 : Integer.parseInt(data.attr("ROWSPAN"));
|
|
|
|
+ Map<String, String> textObject = new HashMap<>();
|
|
|
|
+ // 计算
|
|
|
|
+ int x1 =0;
|
|
|
|
+ int x2 =0;
|
|
|
|
+ int y1 =0;
|
|
|
|
+ int y2 =0;
|
|
|
|
+
|
|
|
|
+ String textInfo = data.text().trim().replaceAll(" ","");
|
|
|
|
+
|
|
|
|
+ y1=i+1;
|
|
|
|
+ //x 移位 算法
|
|
|
|
+ String getRowInfo = rowData[y1];
|
|
|
|
+ if(getRowInfo!=null){
|
|
|
|
+ String [] dataInfo2 = getRowInfo.split(",");
|
|
|
|
+ if(getRowInfo.indexOf("1")>=0 && j==0){
|
|
|
|
+ x= Integer.parseInt(dataInfo2[0].split(":")[1]);
|
|
|
|
+ }else{
|
|
|
|
+ for(int m =0;m<dataInfo2.length ;m++){
|
|
|
|
+ int mx1 = Integer.parseInt(dataInfo2[m].split(":")[0]);
|
|
|
|
+ int mx2 = Integer.parseInt(dataInfo2[m].split(":")[1]);
|
|
|
|
+ if((mx1-x)==1 && mx1>x){
|
|
|
|
+ x = mx2 ;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- //向 上 匹配
|
|
|
|
- if(index_stat){
|
|
|
|
- if( xx1<=x1 && xx2 >=x2 && yy2<y1 && xytype2==xytype){
|
|
|
|
- top.add(name);
|
|
|
|
|
|
+ // X 坐标
|
|
|
|
+ if(colspan==0){
|
|
|
|
+ x1 = x+1;
|
|
|
|
+ x2 = x+1;
|
|
|
|
+ x= x +1;
|
|
|
|
+ }else{
|
|
|
|
+ x1 = x+1;
|
|
|
|
+ x2 = x+colspan;
|
|
|
|
+ x = x+colspan;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //x y 坐标
|
|
|
|
+ if(rowspan==0){
|
|
|
|
+ y2 = i+1;
|
|
|
|
+ }else{
|
|
|
|
+ y2 = i+rowspan;
|
|
|
|
+ for(int k=0;k<rowspan-1;k++){
|
|
|
|
+ String dataInfo = rowData[k+2+i];
|
|
|
|
+ if(dataInfo==null){
|
|
|
|
+ dataInfo = x1+":"+x2;
|
|
|
|
+ }else{
|
|
|
|
+ String [] dataInfo2 = dataInfo.split(",");
|
|
|
|
+ String dataInfo3 = dataInfo2[dataInfo2.length-1];
|
|
|
|
+ int mx1 = Integer.parseInt(dataInfo3.split(":")[0]);
|
|
|
|
+ int mx2 = Integer.parseInt(dataInfo3.split(":")[1]);
|
|
|
|
+ if(mx2+1==x1){
|
|
|
|
+ dataInfo = dataInfo+","+mx1+":"+x2;
|
|
|
|
+ }else{
|
|
|
|
+ dataInfo = dataInfo+","+x1+":"+x2;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ rowData[k+2+i] = dataInfo;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- arrayList.addAll(left);
|
|
|
|
- arrayList.addAll(top);
|
|
|
|
-
|
|
|
|
- // 计算匹配
|
|
|
|
- Set<String> resultSet = new HashSet<>();
|
|
|
|
-
|
|
|
|
- MathUtil.getCombination(arrayList, resultSet);
|
|
|
|
-
|
|
|
|
- System.out.println(data.children().get(0).attr("value","1"));
|
|
|
|
- //System.out.println("x1-x2="+x1+","+x2+"y1-y2="+y1+","+y2+"——"+arrayList+"_jieh="+resultSet);
|
|
|
|
- double maxInfo = 0;
|
|
|
|
- if (!resultSet.isEmpty()) {
|
|
|
|
- for (String bx : resultSet) {
|
|
|
|
- for (WbsFormElement wbsFormElement : dataList) {
|
|
|
|
- if(bx.equals(wbsFormElement.getEName())){
|
|
|
|
- data.empty().text(wbsFormElement.getEName());
|
|
|
|
- // dataList.remove(wbsFormElement);
|
|
|
|
- break;
|
|
|
|
- }else {
|
|
|
|
- double dataxx = MathUtil.sim(bx, wbsFormElement.getEName());
|
|
|
|
- if (maxInfo < dataxx) {
|
|
|
|
- data.empty().text(wbsFormElement.getEName());
|
|
|
|
- maxInfo = dataxx;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // System.out.println(x1+"_"+x2+"_"+y1+"_"+y2+"_"+textInfo);
|
|
|
|
+ // data.text(textInfo.replaceAll(" ",""));
|
|
|
|
+ if(!textInfo.isEmpty() && !textInfo.equals("/") && !(textInfo.indexOf("年")>=0 && textInfo.indexOf("月")>=0&& textInfo.indexOf("日")>=0)&& !textInfo.equals("—") && !textInfo.equals("-") ){ // 标题区域
|
|
|
|
+ Map<String,String> dataInfo =new HashMap<String,String>();
|
|
|
|
+ dataInfo.put("name",textInfo);
|
|
|
|
+ dataInfo.put("x1",x1+"");
|
|
|
|
+ dataInfo.put("x2",x2+"");
|
|
|
|
+ dataInfo.put("y1",y1+"");
|
|
|
|
+ dataInfo.put("y2",y2+"");
|
|
|
|
+ dataInfo.put("xytype",xy_type+"");
|
|
|
|
+ zikey.add(dataInfo);
|
|
|
|
+ }else{ //空行
|
|
|
|
+ List<Map<String,String>> left = new ArrayList<>();
|
|
|
|
+ List<Map<String,String>> top = new ArrayList<>();
|
|
|
|
+ for(int k=0 ; k< zikey.size() ;k++){
|
|
|
|
+ String name = zikey.get(k).get("name");
|
|
|
|
+ // String name2 = zikey.get(k).get("name").replaceAll("[^\u4E00-\u9FA5]", "");
|
|
|
|
+ int xx1 = Integer.parseInt( zikey.get(k).get("x1"));
|
|
|
|
+ int xx2 = Integer.parseInt( zikey.get(k).get("x2"));
|
|
|
|
+ int yy1 = Integer.parseInt( zikey.get(k).get("y1"));
|
|
|
|
+ int yy2 = Integer.parseInt( zikey.get(k).get("y2"));
|
|
|
|
+ int xytype2 = Integer.parseInt( zikey.get(k).get("xytype"));
|
|
|
|
+ // 左匹配
|
|
|
|
+ if( yy1<=y1 && yy2>=y2 && xx2<x1 && xytype2==xy_type){
|
|
|
|
+ left.add(zikey.get(k));
|
|
|
|
+ }
|
|
|
|
+ //向 上 匹配
|
|
|
|
+ if(index_state){
|
|
|
|
+ if( xx1<=x1 && xx2 >=x2 && yy2<y1 && xytype2==xy_type){
|
|
|
|
+ top.add(zikey.get(k));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String inputText ="";
|
|
|
|
+ // 特征值赛选 规则
|
|
|
|
+ for(int k=0 ; k< left.size() ;k++){ // 左计算
|
|
|
|
+ String name = left.get(k).get("name") ;//.replaceAll("[^\u4E00-\u9FA5]", "");
|
|
|
|
+ int xx1 = Integer.parseInt( left.get(k).get("x1"));
|
|
|
|
+ int xx2 = Integer.parseInt( left.get(k).get("x2"));
|
|
|
|
+ int yy1 = Integer.parseInt( left.get(k).get("y1"));
|
|
|
|
+ int yy2 = Integer.parseInt( left.get(k).get("y2"));
|
|
|
|
+ if(index_state){ // 正向规则匹配
|
|
|
|
+ inputText+=name+"_";
|
|
|
|
+ }else{
|
|
|
|
+ if(x1-xx2<=1 && y1==yy2){
|
|
|
|
+ inputText = name;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 特征值赛选 规则
|
|
|
|
+ if(top!=null && top.size()>=1){
|
|
|
|
+ for(int k=0 ; k< top.size() ;k++){ // 向上计算
|
|
|
|
+ String name = top.get(k).get("name") ;//.replaceAll("[^\u4E00-\u9FA5]", "");
|
|
|
|
+ int xx1 = Integer.parseInt( top.get(k).get("x1"));
|
|
|
|
+ int xx2 = Integer.parseInt( top.get(k).get("x2"));
|
|
|
|
+ int yy1 = Integer.parseInt( top.get(k).get("y1"));
|
|
|
|
+ int yy2 = Integer.parseInt( top.get(k).get("y2"));
|
|
|
|
+ inputText+=name+"_";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(inputText!=null && inputText!="" && inputText.indexOf("_")>=0){
|
|
|
|
+ inputText = inputText.substring(0,inputText.lastIndexOf("_"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 计算当前 输入框 标题匹配原则(左 - 上- 下)
|
|
|
|
+ // System.out.println(x1+"_"+x2+","+y1+"_"+y2+"=="+textInfo+"=left"+left.toString() +"===top"+top.toString()+"__index_state="+index_state+"inputtext="+inputText);
|
|
|
|
+
|
|
|
|
+ // 设置文本信息
|
|
|
|
+ if(textInfo.indexOf("年")>=0 && textInfo.indexOf("月")>=0&& textInfo.indexOf("日")>=0){
|
|
|
|
+ data.empty().append("<input type='time' style='width:100%;height:100%' placeholder=''> </input>");
|
|
|
|
+ colTitleSet.add(inputText+"签字时间");
|
|
|
|
+ }else {
|
|
|
|
+ if (index_state) {
|
|
|
|
+ data.empty().append("<input type='text' style='width:100%;height:100%' placeholder='" + inputText + "' > </input>");
|
|
|
|
+ } else {
|
|
|
|
+ if (j == 0) {
|
|
|
|
+ if (colspan == maxCol && i >= 1 && i <= 2) {
|
|
|
|
+ data.empty().append("<input type='text' style='width:100%;height:100%' placeholder='" + inputText + "'> </input>");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ Element bforData = tds.get(j - 1);
|
|
|
|
+ if (!bforData.text().isEmpty()) {
|
|
|
|
+ data.empty().append("<input type='text' style='width:100%;height:100%' placeholder='" + inputText + "'> </input>");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ colTitleSet.add(inputText);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ // data.text(textInfo.replaceAll(" ",""));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ for (String keys:colTitleSet){
|
|
|
|
+ System.out.println(keys.replaceAll("[^(\u4E00-\u9FA5_)]", ""));
|
|
|
|
+ }
|
|
|
|
|
|
- inputStream.close();
|
|
|
|
- String inHtmlUrl2 = "/Users/hongchuangyanfa/Desktop/123654321.html";
|
|
|
|
- File writefile = new File(inHtmlUrl2);
|
|
|
|
|
|
+ // 保存
|
|
|
|
+ File writefile = new File("/Users/hongchuangyanfa/Desktop/123654.html");
|
|
FileUtil.writeToFile(writefile, doc.html(), Boolean.parseBoolean("UTF-8"));
|
|
FileUtil.writeToFile(writefile, doc.html(), Boolean.parseBoolean("UTF-8"));
|
|
- System.out.println("完成");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public static List<WbsFormElement> getWbsInfo(){
|
|
|
|
- List<WbsFormElement> elementList = new ArrayList<>();
|
|
|
|
- WbsFormElement info = new WbsFormElement();
|
|
|
|
- info.setEName("承包单位");
|
|
|
|
-
|
|
|
|
- WbsFormElement info1 = new WbsFormElement();
|
|
|
|
- info1.setEName("合同段");
|
|
|
|
-
|
|
|
|
- WbsFormElement info2 = new WbsFormElement();
|
|
|
|
- info2.setEName("监理单位");
|
|
|
|
-
|
|
|
|
- WbsFormElement info3 = new WbsFormElement();
|
|
|
|
- info3.setEName("编号");
|
|
|
|
-
|
|
|
|
|
|
|
|
- WbsFormElement info4 = new WbsFormElement();
|
|
|
|
- info4.setEName("工程名称");
|
|
|
|
|
|
|
|
- WbsFormElement info5 = new WbsFormElement();
|
|
|
|
- info5.setEName("施工日期");
|
|
|
|
|
|
+ //计算区域坐标
|
|
|
|
+ public static String getTrInfo(Elements tds,Map<String ,String > styleMap,boolean index_state,Integer xy_type,int maxCol){
|
|
|
|
|
|
- WbsFormElement info6 = new WbsFormElement();
|
|
|
|
- info6.setEName("桩号及部位");
|
|
|
|
|
|
+ int x_width = 0 ;
|
|
|
|
+ int y_width = 0 ;
|
|
|
|
+ int text_width = 0;
|
|
|
|
+ int width = 0;
|
|
|
|
|
|
- WbsFormElement info7 = new WbsFormElement();
|
|
|
|
- info7.setEName("检验日期");
|
|
|
|
|
|
+ //区域计算
|
|
|
|
+ for (int j = 0; j < tds.size(); j++) {
|
|
|
|
+ Element data = tds.get(j);
|
|
|
|
+ String keyId = data.attr("class");
|
|
|
|
|
|
- WbsFormElement info8 = new WbsFormElement();
|
|
|
|
- info8.setEName("基坑尺寸长设计值");
|
|
|
|
-
|
|
|
|
- WbsFormElement info9 = new WbsFormElement();
|
|
|
|
- info9.setEName("基坑尺寸宽设计值");
|
|
|
|
-
|
|
|
|
- WbsFormElement info10 = new WbsFormElement();
|
|
|
|
- info10.setEName("基坑尺寸宽实测值");
|
|
|
|
-
|
|
|
|
- WbsFormElement info11 = new WbsFormElement();
|
|
|
|
- info11.setEName("基坑尺寸长实测值");
|
|
|
|
-
|
|
|
|
- WbsFormElement info12 = new WbsFormElement();
|
|
|
|
- info12.setEName("结论");
|
|
|
|
-
|
|
|
|
- WbsFormElement info13 = new WbsFormElement();
|
|
|
|
- info13.setEName("检查人结论");
|
|
|
|
|
|
+ int colspan = data.attr("COLSPAN").equals("") ? 1 : Integer.parseInt(data.attr("COLSPAN"));
|
|
|
|
+ String classInfo = styleMap.get(keyId);
|
|
|
|
+ if(classInfo ==null){
|
|
|
|
+ classInfo = data.attr("style");
|
|
|
|
+ }else{
|
|
|
|
+ data.removeAttr("class");
|
|
|
|
+ data.attr("style",styleMap.get(keyId).replaceAll("break-word","inherit"));
|
|
|
|
+ }
|
|
|
|
|
|
- WbsFormElement info14 = new WbsFormElement();
|
|
|
|
- info14.setEName("日期");
|
|
|
|
|
|
+ // 计算线开始
|
|
|
|
+ if(classInfo.indexOf("border-left-style")>=0 && classInfo.indexOf("border-top-style")>=0 && classInfo.indexOf("border-bottom-style")>=0 && classInfo.indexOf("border-right-style")>=0){
|
|
|
|
+ x_width += colspan;
|
|
|
|
+ }
|
|
|
|
|
|
- WbsFormElement info15 = new WbsFormElement();
|
|
|
|
- info15.setEName("承包人专业工程师");
|
|
|
|
|
|
+ // 计算结束
|
|
|
|
+ if(classInfo.indexOf("border-left-style")< 0 && (classInfo.indexOf("border-top-style")<0 ||classInfo.indexOf("border-top-style")>=0) && classInfo.indexOf("border-bottom-style")<0 && classInfo.indexOf("border-right-style")<0){
|
|
|
|
+ y_width += colspan;
|
|
|
|
+ }
|
|
|
|
|
|
- WbsFormElement info16 = new WbsFormElement();
|
|
|
|
- info16.setEName("现场监理");
|
|
|
|
|
|
+ String name = data.text().replaceAll("[^\u4E00-\u9FA5]", "");
|
|
|
|
+ if(!name.isEmpty()){
|
|
|
|
+ text_width += colspan;
|
|
|
|
+ }
|
|
|
|
+ width +=colspan;
|
|
|
|
+ }
|
|
|
|
|
|
- elementList.add(info);
|
|
|
|
- elementList.add(info1);
|
|
|
|
- elementList.add(info2);
|
|
|
|
- elementList.add(info3);
|
|
|
|
- elementList.add(info4);
|
|
|
|
- elementList.add(info5);
|
|
|
|
- elementList.add(info6);
|
|
|
|
- elementList.add(info7);
|
|
|
|
- elementList.add(info8);
|
|
|
|
- elementList.add(info9);
|
|
|
|
- elementList.add(info10);
|
|
|
|
- elementList.add(info11);
|
|
|
|
- elementList.add(info12);
|
|
|
|
- elementList.add(info13);
|
|
|
|
- elementList.add(info14);
|
|
|
|
- elementList.add(info15);
|
|
|
|
- elementList.add(info16);
|
|
|
|
- return elementList;
|
|
|
|
|
|
+ // 在区域内
|
|
|
|
+ if(index_state){
|
|
|
|
+ //是否需要改变
|
|
|
|
+ if(maxCol == y_width ){
|
|
|
|
+ index_state = false ;
|
|
|
|
+ xy_type+=1;
|
|
|
|
+ }
|
|
|
|
+ if(maxCol == text_width){
|
|
|
|
+ xy_type+=1;
|
|
|
|
+ }
|
|
|
|
+ }else{ // 区域外
|
|
|
|
+ if(maxCol == x_width ){
|
|
|
|
+ index_state = true ;
|
|
|
|
+ xy_type+=1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return xy_type+","+index_state+","+width;
|
|
}
|
|
}
|
|
|
|
|
|
- public static void getHtmlInfo() throws IOException {
|
|
|
|
- String thmlUrl = "/Users/hongchuangyanfa/Desktop/1539066383856304128.html";
|
|
|
|
-
|
|
|
|
- File file = new File("/Users/hongchuangyanfa/Desktop/test001231.xlsx");
|
|
|
|
-
|
|
|
|
- FileInputStream inputStream = new FileInputStream(file);
|
|
|
|
- // 解析excel
|
|
|
|
- Workbook wb = new Workbook();
|
|
|
|
- wb.loadFromMHtml(inputStream);
|
|
|
|
- //获取工作表
|
|
|
|
- Worksheet sheet = wb.getWorksheets().get(0);
|
|
|
|
- sheet.saveToHtml(thmlUrl);
|
|
|
|
-
|
|
|
|
- // 测试
|
|
|
|
- File file1 = ResourceUtil.getFile(thmlUrl);
|
|
|
|
- String htmlString = IoUtil.readToString(new FileInputStream(file1));
|
|
|
|
-
|
|
|
|
- // 样式集合
|
|
|
|
|
|
+ // 获取解析样式
|
|
|
|
+ public static Map<String ,String > getHtmlStyle(Document doc){
|
|
Map<String ,String > styleMap = new HashMap<>();
|
|
Map<String ,String > styleMap = new HashMap<>();
|
|
- // 解析 style
|
|
|
|
- Document doc = Jsoup.parse(htmlString);
|
|
|
|
Element style = doc.select("style").first();
|
|
Element style = doc.select("style").first();
|
|
-
|
|
|
|
Matcher cssMatcher = Pattern.compile("(\\w+)\\s*[{]([^}]+)[}]").matcher(style.html());
|
|
Matcher cssMatcher = Pattern.compile("(\\w+)\\s*[{]([^}]+)[}]").matcher(style.html());
|
|
while (cssMatcher.find()) {
|
|
while (cssMatcher.find()) {
|
|
styleMap.put(cssMatcher.group(1),cssMatcher.group(2));
|
|
styleMap.put(cssMatcher.group(1),cssMatcher.group(2));
|
|
}
|
|
}
|
|
- // 解析 总行和总列
|
|
|
|
- Element table = doc.select("table").first();
|
|
|
|
- Elements trs = table.select("tr");
|
|
|
|
-
|
|
|
|
- // 获取总行列数
|
|
|
|
- int maxCol = doc.select("Col").size();
|
|
|
|
- String [] rowData = new String[trs.size()+1];
|
|
|
|
-
|
|
|
|
- boolean index_stat = false;
|
|
|
|
- int xy_type = 1 ;
|
|
|
|
- // 横向计算
|
|
|
|
- for(int i = 0 ;i < trs.size() ;i++) {
|
|
|
|
- Element tr = trs.get(i);
|
|
|
|
- Elements tds = tr.select("td");
|
|
|
|
-
|
|
|
|
- int x_width = 0 ;
|
|
|
|
- int y_width = 0 ;
|
|
|
|
- int text_width = 0;
|
|
|
|
-
|
|
|
|
- //区域计算
|
|
|
|
- for (int j = 0; j < tds.size(); j++) {
|
|
|
|
- Element data = tds.get(j);
|
|
|
|
- String keyId = data.attr("class");
|
|
|
|
-
|
|
|
|
- int colspan = data.attr("COLSPAN").equals("") ? 1 : Integer.parseInt(data.attr("COLSPAN"));
|
|
|
|
- String classInfo = styleMap.get(keyId);
|
|
|
|
- data.removeAttr("class");
|
|
|
|
- data.attr("style",styleMap.get(keyId).replaceAll("break-word","inherit"));
|
|
|
|
-
|
|
|
|
- // 计算线开始
|
|
|
|
- if(classInfo.indexOf("border-left-style")>=0 && classInfo.indexOf("border-top-style")>=0 && classInfo.indexOf("border-bottom-style")>=0 && classInfo.indexOf("border-right-style")>=0){
|
|
|
|
- x_width += colspan;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 计算结束
|
|
|
|
- if(classInfo.indexOf("border-left-style")< 0 && classInfo.indexOf("border-top-style")<0 && classInfo.indexOf("border-bottom-style")<0 && classInfo.indexOf("border-right-style")<0){
|
|
|
|
- y_width += colspan;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String name = data.text().replaceAll("[^\u4E00-\u9FA5]", "");
|
|
|
|
- if(!name.isEmpty()){
|
|
|
|
- text_width += colspan;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 在区域内
|
|
|
|
- if(index_stat){
|
|
|
|
- //是否需要改变
|
|
|
|
- if(maxCol == y_width ){
|
|
|
|
- index_stat = false ;
|
|
|
|
- xy_type+=1;
|
|
|
|
- }
|
|
|
|
- if(maxCol == text_width){
|
|
|
|
- xy_type+=1;
|
|
|
|
- }
|
|
|
|
- }else{ // 区域外
|
|
|
|
- if(maxCol == x_width ){
|
|
|
|
- index_stat = true ;
|
|
|
|
- xy_type+=1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- tr.attr("indexStat",index_stat+"");
|
|
|
|
-
|
|
|
|
- // 计算单元格坐标
|
|
|
|
- int x= 0;
|
|
|
|
- for (int j = 0; j < tds.size(); j++) {
|
|
|
|
- Element data = tds.get(j);
|
|
|
|
- int colspan = data.attr("COLSPAN").equals("") ? 0 : Integer.parseInt(data.attr("COLSPAN"));
|
|
|
|
- int rowspan = data.attr("ROWSPAN").equals("") ? 0 : Integer.parseInt(data.attr("ROWSPAN"));
|
|
|
|
- Map<String, String> textObject = new HashMap<>();
|
|
|
|
- // 计算
|
|
|
|
- int x1 =0;
|
|
|
|
- int x2 =0;
|
|
|
|
- int y1 =0;
|
|
|
|
- int y2 =0;
|
|
|
|
- //x
|
|
|
|
- // X 坐标
|
|
|
|
- if(colspan==0){
|
|
|
|
- x1 = x+1;
|
|
|
|
- x2 = x+1;
|
|
|
|
- x= x +1;
|
|
|
|
- }else{
|
|
|
|
- x1 = x+1;
|
|
|
|
- x2 = x+colspan;
|
|
|
|
- x = x+colspan;
|
|
|
|
- }
|
|
|
|
- String textInfo = data.text().trim();
|
|
|
|
-
|
|
|
|
- //x y 坐标
|
|
|
|
- y1=i+1;
|
|
|
|
- if(rowspan==0){
|
|
|
|
- y2 = i+1;
|
|
|
|
- }else{
|
|
|
|
- y2 = i+rowspan;
|
|
|
|
- for(int k=0;k<rowspan-1;k++){
|
|
|
|
- String dataInfo = rowData[k+2+i];
|
|
|
|
- if(dataInfo==null){
|
|
|
|
- dataInfo = x1+":"+x2;
|
|
|
|
- }else{
|
|
|
|
- String [] dataInfo2 = dataInfo.split(",");
|
|
|
|
- String dataInfo3 = dataInfo2[dataInfo2.length-1];
|
|
|
|
- int mx1 = Integer.parseInt(dataInfo3.split(":")[0]);
|
|
|
|
- int mx2 = Integer.parseInt(dataInfo3.split(":")[1]);
|
|
|
|
- if(mx2+1==x1){
|
|
|
|
- dataInfo = dataInfo+","+mx1+":"+x2;
|
|
|
|
- }else{
|
|
|
|
- dataInfo = dataInfo+","+x1+":"+x2;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- rowData[k+2+i] = dataInfo;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String getRowInfo = rowData[y1];
|
|
|
|
- if(getRowInfo!=null){
|
|
|
|
- String [] dataInfo2 = getRowInfo.split(",");
|
|
|
|
- if(getRowInfo.indexOf("1")>=0 && j==0){
|
|
|
|
- for(int m =0;m<dataInfo2.length ;m++){
|
|
|
|
- int mx1 = Integer.parseInt(dataInfo2[m].split(":")[0]);
|
|
|
|
- int mx2 = Integer.parseInt(dataInfo2[m].split(":")[1]);
|
|
|
|
- x = mx2;
|
|
|
|
- }
|
|
|
|
- x1 = x+x1;
|
|
|
|
- x2 = x+x2;
|
|
|
|
- x = x+1 ; //计算自己
|
|
|
|
- }else{
|
|
|
|
- for(int m =0;m<dataInfo2.length ;m++){
|
|
|
|
- int mx1 = Integer.parseInt(dataInfo2[m].split(":")[0]);
|
|
|
|
- int mx2 = Integer.parseInt(dataInfo2[m].split(":")[1]);
|
|
|
|
- if(x2+1 == mx1){
|
|
|
|
- x = mx2 ;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- data.text(textInfo.replaceAll(" ",""));
|
|
|
|
- // 设置td 属性
|
|
|
|
- data.attr("trIndex",i+"");
|
|
|
|
- data.attr("tdIndex",j+"");
|
|
|
|
- data.attr("x1",x1+"");
|
|
|
|
- data.attr("x2",x2+"");
|
|
|
|
- data.attr("y1",y1+"");
|
|
|
|
- data.attr("y2",y2+"");
|
|
|
|
- data.attr("xytype",xy_type+"");
|
|
|
|
-
|
|
|
|
- // 设置文本信息
|
|
|
|
- if(textInfo.indexOf("年")>=0 && textInfo.indexOf("月")>=0&& textInfo.indexOf("日")>=0){
|
|
|
|
- data.empty().append("<input type='time' style='width:100%;height:100%' placeholder=''> </input>");
|
|
|
|
- }
|
|
|
|
- if(textInfo.isEmpty() || textInfo.equals("/") || textInfo.equals("—") || textInfo.equals("—") || textInfo.equals("-")){
|
|
|
|
- if(index_stat){
|
|
|
|
- data.empty().append("<input type='text' style='width:100%;height:100%' placeholder=''> </input>");
|
|
|
|
- }else{
|
|
|
|
- if(j==0 ){
|
|
|
|
- if(colspan ==maxCol && i>=1 && i<=2){
|
|
|
|
- data.empty().append("<input type='text' style='width:100%;height:100%' placeholder=''> </input>");
|
|
|
|
- }
|
|
|
|
- }else{
|
|
|
|
- Element bforData = tds.get(j-1);
|
|
|
|
- if(!bforData.text().isEmpty()){
|
|
|
|
- data.empty().append("<input type='text' style='width:100%;height:100%' placeholder=''> </input>");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 写入
|
|
|
|
- inputStream.close();
|
|
|
|
- String inHtmlUrl = "/Users/hongchuangyanfa/Desktop/123654.html";
|
|
|
|
- //saveAsFileWriter(doc.html(),inHtmlUrl);
|
|
|
|
- File writefile = new File(inHtmlUrl);
|
|
|
|
- FileUtil.writeToFile(writefile, doc.html(), Boolean.parseBoolean("UTF-8"));
|
|
|
|
|
|
+ return styleMap;
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|