Ver Fonte

bug 时间问题

hongchuangyanfa há 2 anos atrás
pai
commit
0d688e65c0

+ 30 - 16
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -513,7 +513,7 @@ public class ExcelTabController extends BladeController {
                     String oncklickText = "'" + lastName + "'," + i + "," + j;
 
                     //字段正则表达式校验
-                    String regularExpression = "'" + RegularExpressionUtil.getRegularExpression(filedType) + "'," + "字段类型:" + (StringUtils.isNotEmpty(filedType) ? WbsElementUtil.getTypeName(filedType) : null) + "," + i + "," + j;
+                    String regularExpression = "'" + RegularExpressionUtil.getRegularExpression(filedType) + "'," + "'字段类型:" + (StringUtils.isNotEmpty(filedType) ? WbsElementUtil.getTypeName(filedType) : null) + "'," + i + "," + j;
 
                     if (is_true) {
                         element.children().get(0).attr("placeholder", lastName).attr("@focus", "getInformation(" + oncklickText + ")")
@@ -658,11 +658,12 @@ public class ExcelTabController extends BladeController {
 
 
 
- /*   public static void main(String[] args) throws FileNotFoundException {
+
+   /* public static void main(String[] args) throws FileNotFoundException {
 
         String thmlUrl = "/Users/hongchuangyanfa/Desktop/1234567890.html";
 
-        File file1 = ResourceUtil.getFile("/Users/hongchuangyanfa/Downloads/A16.xlsx");
+        File file1 = ResourceUtil.getFile("/Users/hongchuangyanfa/Downloads/D8.101.xlsx");
 
         Workbook wb = new Workbook();
         wb.loadFromMHtml(new FileInputStream(file1));
@@ -697,6 +698,7 @@ public class ExcelTabController extends BladeController {
         Element table = doc.select("table").first();
 
         Elements trs = table.select("tr");
+
         Element tableinfo = trs.get(0).parent().parent().attr("style", "border-collapse: collapse;");
 
         // 获取图片信息
@@ -957,7 +959,7 @@ public class ExcelTabController extends BladeController {
                         String parm = i + "," + j + "," + x1 + "," + x2 + "," + y1 + "," + y2 + ",$event";
                         // 设置文本信息
                         ExctabCell exctabCell = new ExctabCell();
-                        if (textInfo.indexOf("年") >= 0 && textInfo.indexOf("月") >= 0 && textInfo.indexOf("日") >= 0) {
+                        if ((textInfo.indexOf("年") >= 0 && textInfo.indexOf("月") >= 0 && textInfo.indexOf("日") >= 0)|| textInfo.indexOf("日期")>=0 ) {
 
                             data.empty().append("<el-input type='text'  @contextmenu.prevent.native='RightClick(" + parm + ")' trIndex=" + i + " tdIndex=" + j + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + " style='width:100%;height:100%;' placeholder='年月日'> </el-input>");
                             exctabCell.setExctabId(excelId);
@@ -1347,6 +1349,7 @@ public class ExcelTabController extends BladeController {
                 Document doc = Jsoup.parse(htmlString);
                 Element table = doc.select("table").first();
                 Elements trs = table.select("tr");
+                Elements cols = table.select("col");
 
                 if (ObjectUtil.isNotEmpty(DataInfo)) {
                     for (String val : DataInfo.keySet()) {
@@ -1392,22 +1395,33 @@ public class ExcelTabController extends BladeController {
                                 }
                                 //https:bladex-test-info.oss-cn-chengdu.aliyuncs.com//upload/20220819/b53cb6700db369381e3b03d7737bcdec.jpg__16_1
                                 if (myData.indexOf("https") >= 0 && myData.indexOf("aliyuncs") >= 0) {
-                                  //  Element element = trs.get(y1).select("td").get(x1);
-                                    String styles[] = data.attr("style").split(";");
-                                    int Height = 0;
-                                    for (String sty : styles) {
-                                        if (sty.indexOf("height:") >= 0) {
-                                            Height = Integer.parseInt(sty.replace("height:", "").replace("px", ""));
+
+                                    BufferedImage image = ImageIO.read(CommonUtil.getOSSInputStream(myData));
+
+                                    int colspan = Integer.parseInt(data.attr("colspan"));
+                                    int rowspan = Integer.parseInt(data.attr("rowspan"));
+                                    int picHeight = 0;
+                                    int picWidth = 0;
+                                    for (int i=y1;i<=(y1+rowspan);i++){ // 跨列处理
+                                        String dataInfo = trs.get(i).attr("height");
+                                        if(StringUtils.isNotEmpty(dataInfo)){
+                                            picHeight += Integer.parseInt(dataInfo);
                                         }
                                     }
 
-                                    BufferedImage image = ImageIO.read(CommonUtil.getOSSInputStream(myData));
-                                    ExcelPicture pic = sheet.getPictures().add(y1, x1, image);
-                                    pic.setHeight(Height);
-                                    System.out.println(sheet.getCellRange(y1, x1).getRowHeight());
-                                    System.out.println(sheet.getCellRange(y1, x1).getColumnWidth());
-                                    sheet.getCellRange(y1, x1).getStyle().setShrinkToFit(true);
+                                    if(colspan>=1){ //框行处理
+                                        for(int i=x1-1;i<x1+colspan-1;i++){
+                                            String dataInfo=cols.get(i).attr("width").replaceAll("px","");
+                                            if(StringUtils.isNotEmpty(dataInfo)){
+                                                picWidth += Integer.parseInt(dataInfo);
+                                            }
+                                        }
+                                    }
 
+                                    ExcelPicture pic = sheet.getPictures().add(y1, x1, image);
+                                    pic.setWidth(picWidth-10);
+                                    pic.setHeight(picHeight);
+                                    pic.setLeft(5);
                                 } else {
                                     final CellRange cellRange = sheet.getCellRange(y1, x1);
                                     cellRange.setText(myData);