|
@@ -16,8 +16,9 @@
|
|
|
*/
|
|
|
package org.springblade.manager.controller;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.spire.xls.Workbook;
|
|
|
import com.spire.xls.Worksheet;
|
|
|
import io.swagger.annotations.*;
|
|
@@ -43,26 +44,18 @@ import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.constant.BladeConstant;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.StringPool;
|
|
|
-import org.springblade.manager.entity.ExctabCell;
|
|
|
-import org.springblade.manager.entity.WbsTreePrivate;
|
|
|
-import org.springblade.manager.service.IExctabCellService;
|
|
|
-import org.springblade.manager.service.IWbsTreePrivateService;
|
|
|
-import org.springblade.manager.service.IWbsTreeService;
|
|
|
+import org.springblade.manager.entity.*;
|
|
|
+import org.springblade.manager.service.*;
|
|
|
import org.springblade.manager.vo.*;
|
|
|
import org.springblade.manager.wrapper.ExcelTabWrapper;
|
|
|
import org.springblade.resource.feign.IOSSClient;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import org.springblade.manager.entity.ExcelTab;
|
|
|
-import org.springblade.manager.service.IExcelTabService;
|
|
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.*;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
@@ -90,6 +83,12 @@ public class ExcelTabController extends BladeController {
|
|
|
// 私有项目wbs
|
|
|
private final IWbsTreePrivateService wbsTreePrivateService;
|
|
|
|
|
|
+ // 清表表格解析信息
|
|
|
+ private final ILinkdataInfoService linkdataInfoService;
|
|
|
+
|
|
|
+ // 元素信息表-
|
|
|
+ private final IWbsFormElementService wbsFormElementService;
|
|
|
+
|
|
|
/**
|
|
|
* 详情
|
|
|
*/
|
|
@@ -247,41 +246,6 @@ public class ExcelTabController extends BladeController {
|
|
|
detail.setFileType(3); // 表示为清表信息 1 表示祖节点 2 表示为节点信息 3 表示清表
|
|
|
detail.setHtmlUrl(thmlUrl);
|
|
|
excelTabService.saveOrUpdate(detail);
|
|
|
-/*
|
|
|
- //解析数据
|
|
|
- Thread.sleep(200);
|
|
|
- String htmlString = readfile(thmlUrl);
|
|
|
-
|
|
|
- String htmlString2= getBody(htmlString);
|
|
|
-
|
|
|
- Document doc = Jsoup.parse(htmlString2);
|
|
|
-
|
|
|
- Elements trs = doc.select("tr");
|
|
|
- List<ExctabCell> cellList = new ArrayList<>();
|
|
|
-
|
|
|
- for(int i = 0 ;i < trs.size() ;i++){
|
|
|
- Element tr = trs.get(i);
|
|
|
- Elements tds = tr.select("td");
|
|
|
- for( int j = 0 ; j < tds.size();j++ ){
|
|
|
- ExctabCell cell = new ExctabCell();
|
|
|
- Element data = tds.get(j);
|
|
|
- int colspan = Integer.parseInt(data.attr("COLSPAN").equals("")?"0":data.attr("COLSPAN"));
|
|
|
- int rowspan = Integer.parseInt(data.attr("ROWSPAN").equals("")?"0":data.attr("ROWSPAN"));
|
|
|
- String textInfo = data.text();
|
|
|
- cell.setExctabId(nodeId);
|
|
|
- cell.setTrIndex(i);
|
|
|
- cell.setTdIndex(j);
|
|
|
- cell.setColIndex(colspan);
|
|
|
- cell.setRowIndex(rowspan);
|
|
|
- cell.setTextInfo(textInfo);
|
|
|
- cellList.add(cell);
|
|
|
- System.out.print("COLSPAN:" +colspan+" ROWSPAN:"+rowspan+" "+textInfo);
|
|
|
- }
|
|
|
- System.out.println();
|
|
|
- }
|
|
|
-
|
|
|
- // 保存结构
|
|
|
- exctabCellService.saveOrUpdateBatch(cellList);*/
|
|
|
return R.success("上传成功");
|
|
|
}
|
|
|
|
|
@@ -385,23 +349,25 @@ public class ExcelTabController extends BladeController {
|
|
|
return buffer.toString();
|
|
|
}
|
|
|
|
|
|
- public static String getBody(String val) {
|
|
|
- String start = "<body>";
|
|
|
- String end = "</body>";
|
|
|
- int s = val.indexOf(start) + start.length();
|
|
|
- int e = val.indexOf(end);
|
|
|
- return val.substring(s, e);
|
|
|
- }
|
|
|
|
|
|
- public static String getStyle(String val) {
|
|
|
- String start = "<<style type=\"text/css\">";
|
|
|
- String end = "</style>";
|
|
|
- int s = val.indexOf(start) + start.length();
|
|
|
- int e = val.indexOf(end);
|
|
|
- return val.substring(s, e);
|
|
|
+ private static void saveAsFileWriter(String content ,String filePath) {
|
|
|
+ Writer fwriter = null;
|
|
|
+ try {
|
|
|
+ // true表示不覆盖原来的内容,而是加到文件的后面。若要覆盖原来的内容,直接省略这个参数就好
|
|
|
+ fwriter = new BufferedWriter((new OutputStreamWriter(new FileOutputStream(filePath),"UTF-8")));
|
|
|
+ fwriter.write(content);
|
|
|
+ } catch (IOException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ fwriter.flush();
|
|
|
+ fwriter.close();
|
|
|
+ } catch (IOException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 关联清表树
|
|
|
*/
|
|
@@ -431,19 +397,31 @@ public class ExcelTabController extends BladeController {
|
|
|
WbsTreePrivate aPrivate = wbsTreePrivateService.getOne(Condition.getQueryWrapper(wbsTree));
|
|
|
aPrivate.setIsLinkTable(1); // 已关联
|
|
|
aPrivate.setExcelId(exceTabId);
|
|
|
- wbsTreePrivateService.saveOrUpdate(aPrivate);
|
|
|
+
|
|
|
+ UpdateWrapper<WbsTreePrivate> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.in("p_key_id",tabId);
|
|
|
+ updateWrapper.set("is_link_table",1);
|
|
|
+ updateWrapper.set("excel_id",exceTabId);
|
|
|
+
|
|
|
+ wbsTreePrivateService.update(updateWrapper);
|
|
|
+ // 获取excel 基本信息
|
|
|
+ ExcelTab excelTab = excelTabService.getById(exceTabId);
|
|
|
// 解析
|
|
|
- return R.success("关联成功");
|
|
|
- }
|
|
|
|
|
|
+ // 获取元素列表
|
|
|
+ WbsFormElement wbsFormElement = new WbsFormElement();
|
|
|
+ QueryWrapper<WbsFormElement> queryWrapper = new QueryWrapper<>();
|
|
|
+ List<WbsFormElement> detail = wbsFormElementService.selectElementListByFid(aPrivate.getId()+"");
|
|
|
+ // 解析html
|
|
|
+ getExcelHtml1(excelTab.getHtmlUrl());
|
|
|
|
|
|
+ return R.success("关联成功");
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ public void getExcelHtml1(String thmlUrl) {
|
|
|
|
|
|
- /*public static void main(String[] args) {
|
|
|
- String thmlUrl = "/Users/hongchuangyanfa/Desktop/ToHtml.html";
|
|
|
String htmlString = readfile(thmlUrl);
|
|
|
- String htmlBody= getBody(htmlString);
|
|
|
Map<String ,String > styleMap = new HashMap<>();
|
|
|
|
|
|
// 解析 style
|
|
@@ -453,11 +431,7 @@ public class ExcelTabController extends BladeController {
|
|
|
while (cssMatcher.find()) {
|
|
|
styleMap.put(cssMatcher.group(1),cssMatcher.group(2));
|
|
|
}
|
|
|
-
|
|
|
// 解析 总行和总列
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// 解析
|
|
|
Element table = doc.select("table").first();
|
|
|
Elements trs = table.select("tr");
|
|
@@ -465,126 +439,189 @@ public class ExcelTabController extends BladeController {
|
|
|
// 获取总行列数
|
|
|
int maxCol = doc.select("Col").size();
|
|
|
|
|
|
- System.out.println(trs.size());
|
|
|
- System.out.println( maxCol );
|
|
|
- List<Map<String,String>> textlist = new ArrayList();
|
|
|
+ List<Map<String,String>> textlist = new ArrayList<>() ;
|
|
|
+
|
|
|
+ String [] rowData = new String[trs.size()+1];
|
|
|
|
|
|
- // 计算 单元格的每个坐标
|
|
|
-*//* for(int i = 0 ;i < trs.size() ;i++) {
|
|
|
+ int s_index = 0;
|
|
|
+ // 横向计算
|
|
|
+ for(int i = 0 ;i < trs.size() ;i++) {
|
|
|
Element tr = trs.get(i);
|
|
|
Elements tds = tr.select("td");
|
|
|
- int tdw =1;
|
|
|
+ int x= 0;
|
|
|
for (int j = 0; j < tds.size(); j++) {
|
|
|
ExctabCell cell = new ExctabCell();
|
|
|
Element data = tds.get(j);
|
|
|
- String textInfo = data.text();
|
|
|
- int colspan = data.attr("COLSPAN").equals("") ? 1: Integer.parseInt(data.attr("COLSPAN"))-1;
|
|
|
- int rowspan = data.attr("ROWSPAN").equals("") ? 1: Integer.parseInt(data.attr("ROWSPAN"))-1;
|
|
|
-
|
|
|
- //if(!textInfo.equals("/") && !textInfo.isEmpty()){
|
|
|
- *//**//*Map<String,String> textObject = new HashMap<>();
|
|
|
- textObject.put("text",textInfo);
|
|
|
- textObject.put("x1",tdw+"");
|
|
|
- textObject.put("x2",tdw+colspan+"");
|
|
|
- textObject.put("y1",i+"");
|
|
|
- textObject.put("y2",(i+rowspan)+"");*//**//*
|
|
|
- //textlist.add(textObject);
|
|
|
- //}
|
|
|
-// System.out.print(textInfo +":x1:"+tdw +":x2:"+(tdw+colspan) + " ");
|
|
|
- }
|
|
|
- System.out.println();
|
|
|
- }*//*
|
|
|
+ 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();
|
|
|
+ // y 坐标
|
|
|
+ textObject.put("text",textInfo);
|
|
|
+ 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 ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- *//*for(Map<String,String> m:textlist){
|
|
|
- System.out.println(m.get("text")+":"+m.get("x1")+":"+m.get("x2")+":"+m.get("y1")+":"+m.get("y1"));
|
|
|
- }*//*
|
|
|
|
|
|
- for(int i = 0 ;i < trs.size() ;i++){
|
|
|
- Element tr = trs.get(i);
|
|
|
- Elements tds = tr.select("td");
|
|
|
- int tdw =0;
|
|
|
- for( int j = 0 ; j < tds.size();j++ ){
|
|
|
- ExctabCell cell = new ExctabCell();
|
|
|
- Element data = tds.get(j);
|
|
|
- boolean isadd = false ;
|
|
|
- // 更改样式
|
|
|
String keyId = data.attr("class");
|
|
|
if(!keyId.isEmpty()){
|
|
|
data.removeAttr("class");
|
|
|
data.attr("style",styleMap.get(keyId));
|
|
|
- }
|
|
|
-
|
|
|
- int colspan = data.attr("COLSPAN").equals("") ? 1: Integer.parseInt(data.attr("COLSPAN"))-1;
|
|
|
- int rowspan = data.attr("ROWSPAN").equals("") ? 1: Integer.parseInt(data.attr("ROWSPAN"))-1;
|
|
|
-
|
|
|
- // 决定输入啥文本框
|
|
|
- String textInfo = data.text();
|
|
|
-
|
|
|
- //data
|
|
|
-
|
|
|
- System.out.println(textInfo + ":" +data.attr("offsetTop"));
|
|
|
- *//*if(textlist.size()>=1){
|
|
|
- for(Map<String,String> m:textlist) {
|
|
|
- int x1 = Integer.parseInt(m.get("x1"));
|
|
|
- int x2 = Integer.parseInt(m.get("x2"));
|
|
|
- int y1 = Integer.parseInt(m.get("y1"));
|
|
|
- int y2 = Integer.parseInt(m.get("y2"));
|
|
|
- System.out.println(m.get("text")+":"+m.get("x1")+":"+m.get("x2")+":"+m.get("y1")+":"+m.get("y2"));
|
|
|
-
|
|
|
|
|
|
+ // 封版
|
|
|
+ if(styleMap.get(keyId).indexOf("border-top-style")>=0 && styleMap.get(keyId).indexOf("border-bottom-style")>=0){
|
|
|
+ s_index = y1;
|
|
|
}
|
|
|
- }else{
|
|
|
- Map<String,String> textObject = new HashMap<>();
|
|
|
- textObject.put("text",textInfo);
|
|
|
- textObject.put("x1",tdw+"");
|
|
|
- textObject.put("x2",tdw+colspan+"");
|
|
|
- textObject.put("y1",(i)+"");
|
|
|
- textObject.put("y2",(i+rowspan)+"");
|
|
|
- textlist.add(textObject);
|
|
|
- }*//*
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ if(styleMap.get(keyId).indexOf("border-top-style")>=0 && styleMap.get(keyId).indexOf("border-bottom-style")<0){
|
|
|
+ s_index = y1;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- *//*if(textInfo.equals("/")|| textInfo.isEmpty()){
|
|
|
+ LinkdataInfo linkdataInfo = new LinkdataInfo();
|
|
|
+ linkdataInfo.setTrIndex(i);
|
|
|
+ linkdataInfo.setTdIndex(j);
|
|
|
+ linkdataInfo.setTabId(Long.parseLong("123456789"));
|
|
|
+ boolean isadd = false;
|
|
|
+ // 组装 html 数据
|
|
|
+ boolean istopVal =false;
|
|
|
+ boolean isleftVal =false;
|
|
|
+ int inputType = 1; //1 输入框 2 时间
|
|
|
+ if(textInfo.equals("/")|| textInfo.isEmpty() || textInfo.equals("—")){
|
|
|
if(i== 0 && j==0 && maxCol==colspan ){ // 第一行为空
|
|
|
isadd = false;
|
|
|
}else{
|
|
|
// 得到 当前位置 获取值
|
|
|
- for(Map<String,String> m:textlist){
|
|
|
- int x1 = Integer.parseInt(m.get("x1"));
|
|
|
- int x2 = Integer.parseInt(m.get("x2"));
|
|
|
- int y1 = Integer.parseInt(m.get("y1"));
|
|
|
- int y2 = Integer.parseInt(m.get("y2"));
|
|
|
+ for(int k=textlist.size()-1;k>=0;k--){
|
|
|
+ Map<String,String> m = textlist.get(k);
|
|
|
+ int xx1 = Integer.parseInt(m.get("x1"));
|
|
|
+ int xx2 = Integer.parseInt(m.get("x2"));
|
|
|
+ int yy1 = Integer.parseInt(m.get("y1"));
|
|
|
+ int yy2 = Integer.parseInt(m.get("y2"));
|
|
|
String kekval = m.get("text");
|
|
|
|
|
|
- //||(i>= y1 && (i+rowspan)<=y2 && x2 <tdw && !kekval.isEmpty())
|
|
|
- //(tdw >= x1 && (tdw+colspan)<=x2 && y1<=i && !kekval.isEmpty())
|
|
|
-
|
|
|
- if((i>= y1 && (i+rowspan)<=y2 && x2 < tdw && !kekval.isEmpty())){ // 向上取值
|
|
|
- System.out.print(i+":"+j);
|
|
|
- System.out.println(":"+m.get("text"));
|
|
|
+ if(xx1<=x1 && xx2>=x2 && yy2<y1 && !istopVal && y1>=s_index){ // 向上取值
|
|
|
+ if(!kekval.isEmpty() && !kekval.equals("/") && kekval.indexOf("检验单")<0 && kekval.indexOf("表")<0 && kekval.indexOf("—")<0){
|
|
|
+ if(kekval.indexOf("日期")>=0){
|
|
|
+ inputType=2;
|
|
|
+ }
|
|
|
+ linkdataInfo.setColName(kekval);
|
|
|
+ istopVal = true ;
|
|
|
+ System.out.println(x1 +"-"+x2 +":"+y1+"-"+y2 + "--"+s_index +"val:"+kekval);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(yy1<=y1 && yy2>=y2 && xx2<x1 && !isleftVal && y1>=s_index){ // 向左取
|
|
|
+ if(!kekval.isEmpty() && !kekval.equals("/") && kekval.indexOf("检验单")<0 && kekval.indexOf("表")<0&& kekval.indexOf("—")<0){
|
|
|
+ isleftVal = true ;
|
|
|
+ if(kekval.indexOf("日期")>=0){
|
|
|
+ inputType=2;
|
|
|
+ }
|
|
|
+ linkdataInfo.setColName(kekval);
|
|
|
+ // System.out.println(x1 +"-"+x2 +":"+y1+"-"+y2 + "--"+s_index +"val:"+kekval);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(isleftVal || istopVal){
|
|
|
isadd = true ;
|
|
|
}
|
|
|
+ if (istopVal&&isleftVal){
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
isadd = false;
|
|
|
- }*//*
|
|
|
+ }
|
|
|
+
|
|
|
+ if(textInfo.indexOf("年")>=0 && textInfo.indexOf("月")>=0&& textInfo.indexOf("日")>=0){
|
|
|
+ data.empty().append("<el-date-picker style='width:100%;height:100%' type='date' format='yyyy 年 MM 月 dd 日' placeholder='请选择时间'> </el-date-picker>");
|
|
|
+ }
|
|
|
|
|
|
if(isadd){
|
|
|
- data.empty().append("<el-input type='text' placeholder='请输入内容'> </el-input>");
|
|
|
+
|
|
|
+ if(inputType==2){
|
|
|
+ data.empty().append("<el-date-picker type='date' style='width:100%;height:100%' > </el-date-picker>");
|
|
|
+ }else{
|
|
|
+ if(rowspan>=1){
|
|
|
+ data.empty().append("<el-input type='textarea' style='width:100%;height:100%' :rows="+rowspan*2+" placeholder=''> </el-input>");
|
|
|
+ }else{
|
|
|
+ data.empty().append("<el-input type='text' style='width:100%;height:100%' placeholder=''> </el-input>");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //linkdataInfoService.save(linkdataInfo);
|
|
|
}
|
|
|
- tdw = tdw + colspan;
|
|
|
+
|
|
|
+ textObject.put("x1",x1+"");
|
|
|
+ textObject.put("x2",x2+"");
|
|
|
+ textObject.put("y1",y1+"");
|
|
|
+ textObject.put("y2",y2+"");
|
|
|
+ textObject.put("rowSpan",rowspan+"");
|
|
|
+ textlist.add(textObject);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //System.out.println(table+"");
|
|
|
+ saveAsFileWriter(doc+"",thmlUrl);
|
|
|
}
|
|
|
|
|
|
-*/
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -593,106 +630,23 @@ public class ExcelTabController extends BladeController {
|
|
|
@GetMapping("/get-excel-html")
|
|
|
@ApiOperationSupport(order = 15)
|
|
|
@ApiOperation(value = "清表生成html", notes = "清表生成html")
|
|
|
- public R getExcelHtml() {
|
|
|
- String thmlUrl = "/Users/hongchuangyanfa/Desktop/ToHtml.html";
|
|
|
- String htmlString = readfile(thmlUrl);
|
|
|
- String htmlBody= getBody(htmlString);
|
|
|
- Map<String ,String > styleMap = new HashMap<>();
|
|
|
-
|
|
|
- // 解析 style
|
|
|
- Document doc = Jsoup.parse(htmlString);
|
|
|
- Element style = doc.select("style").first();
|
|
|
- Matcher cssMatcher = Pattern.compile("(\\w+)\\s*[{]([^}]+)[}]").matcher(style.html());
|
|
|
- while (cssMatcher.find()) {
|
|
|
- styleMap.put(cssMatcher.group(1),cssMatcher.group(2));
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(name = "excelId", value = "excelId", required = true)
|
|
|
+ })
|
|
|
+ public R getExcelHtml(Long excelId) {
|
|
|
+ ExcelTab excelTab = excelTabService.getById(excelId);
|
|
|
+ if(excelTab ==null ){
|
|
|
+ return R.fail("该数据下无此节点!");
|
|
|
}
|
|
|
|
|
|
- // 解析
|
|
|
- Element table = doc.select("table").first();
|
|
|
- Elements trs = table.select("tr");
|
|
|
-
|
|
|
- // 获取总行列数
|
|
|
- int maxCol = doc.select("Col").size();
|
|
|
-
|
|
|
- List<Map<String,String>> textlist = new ArrayList();
|
|
|
- // 计算 单元格的每个坐标
|
|
|
- int trh = 0;
|
|
|
- for(int i = 0 ;i < trs.size() ;i++) {
|
|
|
- Element tr = trs.get(i);
|
|
|
- Elements tds = tr.select("td");
|
|
|
- int tdw =0;
|
|
|
- for (int j = 0; j < tds.size(); j++) {
|
|
|
- ExctabCell cell = new ExctabCell();
|
|
|
- Element data = tds.get(j);
|
|
|
- String textInfo = data.text();
|
|
|
- if(!textInfo.equals("/") && !textInfo.isEmpty()){
|
|
|
- int colspan = Integer.parseInt(data.attr("COLSPAN").equals("")?"0":data.attr("COLSPAN"));
|
|
|
- int rowspan = Integer.parseInt(data.attr("ROWSPAN").equals("")?"0":data.attr("ROWSPAN"));
|
|
|
-
|
|
|
- Map<String,String> textObject = new HashMap<>();
|
|
|
- textObject.put("text",textInfo);
|
|
|
- textObject.put("x1",tdw+"");
|
|
|
- tdw = tdw + colspan;
|
|
|
- textObject.put("x2",tdw+"");
|
|
|
- textObject.put("y1",trh+"");
|
|
|
- trh = trh + rowspan;
|
|
|
- textObject.put("y2",trh+"");
|
|
|
- textlist.add(textObject);
|
|
|
- }
|
|
|
- }
|
|
|
+ if(excelTab.getHtmlUrl()==null){
|
|
|
+ return R.fail("请上传清表!");
|
|
|
}
|
|
|
|
|
|
- for(Map<String,String> m:textlist){
|
|
|
- System.out.println(m.get("text")+":"+m.get("x1")+":"+m.get("x2")+":"+m.get("y1")+":"+m.get("y1"));
|
|
|
- }
|
|
|
-
|
|
|
- /*for(int i = 0 ;i < trs.size() ;i++){
|
|
|
- Element tr = trs.get(i);
|
|
|
- Elements tds = tr.select("td");
|
|
|
-
|
|
|
-
|
|
|
- for( int j = 0 ; j < tds.size();j++ ){
|
|
|
- ExctabCell cell = new ExctabCell();
|
|
|
- Element data = tds.get(j);
|
|
|
-
|
|
|
- boolean isadd = false ;
|
|
|
-
|
|
|
- // 更改样式
|
|
|
- String keyId = data.attr("class");
|
|
|
- if(!keyId.isEmpty()){
|
|
|
- data.removeAttr("class");
|
|
|
- data.attr("style",styleMap.get(keyId));
|
|
|
- }
|
|
|
-
|
|
|
- int colspan = Integer.parseInt(data.attr("COLSPAN").equals("")?"0":data.attr("COLSPAN"));
|
|
|
- int rowspan = Integer.parseInt(data.attr("ROWSPAN").equals("")?"0":data.attr("ROWSPAN"));
|
|
|
- // 决定输入啥文本框
|
|
|
- String textInfo = data.text();
|
|
|
- if(textInfo.equals("/")|| textInfo.isEmpty()){
|
|
|
- String trtopval = "";
|
|
|
- String tdleftval = "";
|
|
|
- if(i==0){ // tr 取值
|
|
|
- trtopval = "";
|
|
|
- }else{
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if(j==0){ // tr 取值
|
|
|
- tdleftval = "";
|
|
|
- }else{
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }else{
|
|
|
- isadd = false;
|
|
|
- }
|
|
|
-
|
|
|
- if(isadd){
|
|
|
- data.empty().append("<el-input type='text' placeholder=''> </el-input>");
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
+ String htmlString = readfile(excelTab.getHtmlUrl());
|
|
|
+ // 解析 style
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ Element table = doc.select("table").first();
|
|
|
return R.data(table+"");
|
|
|
}
|
|
|
}
|