Bläddra i källkod

在线excel
1、功能写在user模块中
2、poi生成为5.4.0版本

LHB 2 veckor sedan
förälder
incheckning
324c4afc04

+ 8 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/feign/ExcelTabClient.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import org.springblade.business.dto.ReSigningEntrustDto;
 import org.springblade.business.dto.TrialSelfInspectionRecordDTO;
 import org.springblade.core.tool.api.R;
+import org.springblade.manager.entity.ExcelEditCallback;
 import org.springblade.manager.entity.ExcelTab;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.*;
@@ -99,4 +100,11 @@ public interface ExcelTabClient {
 
     @PostMapping(API_PREFIX + "/getTheLogPdInfo")
     void getTheLogPdInfo(@RequestParam String logPkeyId,  @RequestParam String nodePrimaryKeyId, @RequestParam String recordTime, @RequestParam String contractId,@RequestParam Long createUser) throws Exception;
+
+    /**
+     * 在线excel 保存
+     * @param excelEditCallback
+     */
+    @PostMapping(API_PREFIX + "/saveExcelTableLink")
+    boolean saveExcelTableLink(@RequestBody ExcelEditCallback excelEditCallback);
 }

+ 6 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/feign/ExcelTabClientFallBack.java

@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
 import org.springblade.business.dto.ReSigningEntrustDto;
 import org.springblade.business.dto.TrialSelfInspectionRecordDTO;
 import org.springblade.core.tool.api.R;
+import org.springblade.manager.entity.ExcelEditCallback;
 import org.springblade.manager.entity.ExcelTab;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -106,5 +107,10 @@ public class ExcelTabClientFallBack implements ExcelTabClient {
 
     }
 
+    @Override
+    public boolean saveExcelTableLink(ExcelEditCallback excelEditCallback) {
+        return false;
+    }
+
 
 }

+ 0 - 7
blade-service/blade-manager/pom.xml

@@ -178,13 +178,6 @@
             <scope>system</scope>
             <systemPath>${basedir}/../../doc/lib/eVisaLib/spire.office.free-5.3.1.jar</systemPath>
         </dependency>
-        <dependency>
-            <groupId>io.github.autoffice</groupId>
-            <artifactId>luckysheet-lib</artifactId>
-            <version>1.1.0</version>
-            <scope>system</scope>
-            <systemPath>${basedir}/../../doc/lib/excelLib/luckysheet-lib-1.1.0.jar</systemPath>
-        </dependency>
 
         <!--计量-->
         <dependency>

+ 0 - 25
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -4988,29 +4988,4 @@ public class ExcelTabController extends BladeController {
         return R.status(true);
     }
 
-    /**
-     * 在线excel 获取文件json数据
-     *
-     * @throws IOException
-     */
-    @PostMapping(value = "/getExcelUrl")
-    @ApiOperation(value = "获取文件json数据", notes = "获取文件json数据")
-    @ApiOperationSupport(order = 35)
-    @ResponseBody
-    public R getExcelUrl(@RequestBody ExcelEditCallback callback) {
-        return excelTabService.getExcelUrl(callback);
-    }
-
-    /**
-     * 在线excel 保存
-     *
-     * @throws IOException
-     */
-    @PostMapping(value = "/saveExcel")
-    @ApiOperation(value = "在线excel 保存", notes = "在线excel 保存")
-    @ApiOperationSupport(order = 35)
-    @ResponseBody
-    public R saveExcel(@RequestBody ExcelEditCallback callback) {
-        return excelTabService.saveExcel(callback);
-    }
 }

+ 4 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/feign/ExcelTabClientImpl.java

@@ -519,6 +519,10 @@ public class ExcelTabClientImpl implements ExcelTabClient {
         excelTabController.getTheLogPdInfo(logPkeyId, nodePrimaryKeyId, recordTime, contractId,createUser);
     }
 
+    @Override
+    public boolean saveExcelTableLink(ExcelEditCallback excelEditCallback) {
+        return excelTabService.saveExcel(excelEditCallback);
+    }
 
     private String getHtmlString(String pkeyId) throws Exception {
         WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectOne(Wrappers.<WbsTreePrivate>query().lambda()

+ 1 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IExcelTabService.java

@@ -223,7 +223,5 @@ public interface IExcelTabService extends BaseService<ExcelTab> {
 
     R batchAddNumbers(BatchAddNumbersDTO dto) throws Exception;
 
-    R getExcelUrl(ExcelEditCallback callback);
-
-    R saveExcel(ExcelEditCallback callback);
+    Boolean saveExcel(ExcelEditCallback callback);
 }

+ 6 - 128
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -20,7 +20,6 @@ import com.spire.xls.ExcelPicture;
 import com.spire.xls.FileFormat;
 import com.spire.xls.Worksheet;
 import com.spire.xls.collections.PicturesCollection;
-import io.github.autoffice.luckysheet.LuckysheetConverter;
 import io.swagger.models.auth.In;
 import lombok.AllArgsConstructor;
 import org.apache.commons.collections4.CollectionUtils;
@@ -6846,74 +6845,29 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         return xy_type + "," + index_state + "," + width + "," + istrue;
     }
 
-    //取文件
-    @Override
-    public R getExcelUrl(ExcelEditCallback callback) {
-        //创建临时文件
-        //获取onlyOffice缓存中的文件流
-        String file_path = FileUtils.getSysLocalFileUrl();
-        String filecode = SnowFlakeUtil.getId() + "";
-        String dataUrl = file_path + "/excel/" + filecode + ".xlsx";
-
-        try {
-            File file = downloadFileToTemp(callback.getUrl(), dataUrl);
-            if(file != null){
-                // 将excel文件转为luckysheet json
-                String json = LuckysheetConverter.excelToLuckySheetJson(dataUrl);
-                cn.hutool.json.JSONObject entries = JSONUtil.parseObj(json);
-                cn.hutool.json.JSONArray sheets = entries.getJSONArray("sheets");
-
-                //删除临时文件
-                if (file.exists()) {
-                    file.delete();
-                }
-                return R.data(sheets.toString());
-            }
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-
-        return R.fail("文件异常");
-    }
-
-
 
     //设置文件
     @Override
-    public R saveExcel(ExcelEditCallback callback) {
+    public Boolean saveExcel(ExcelEditCallback callback) {
         String tabId = callback.getKey();
         if (tabId == null) {
             throw new ServiceException("excel为空");
-        } else {
-            tabId = tabId.substring(0, tabId.lastIndexOf("_"));
         }
+        //poi5.4.0 处理完的excel路径
+        String excelFile = callback.getUrl();
 
         String file_path = FileUtils.getSysLocalFileUrl();
         String filecode = SnowFlakeUtil.getId() + "";
-        //创建临时json文件
-        String jsonFile = file_path + "/excel/" + filecode + ".json";
-        //创建临时excel文件
-        String excelFile = file_path + "/excel/" + filecode + ".xlsx";
-
-        try (FileWriter file = new FileWriter(jsonFile)) {
-            file.write(callback.getJsonExcel());
-            file.flush();
-            System.out.println("JSON数据已成功保存到: " + jsonFile);
-        } catch (IOException e) {
-            System.err.println("保存JSON文件时出错: " + e.getMessage());
-            e.printStackTrace();
-        }
+
         //获取文件流
         File file = new File(excelFile);
 
         try {
-            // 将luckysheet json文件转为excel
-            LuckysheetConverter.luckysheetToExcel(jsonFile, excelFile);
 
             //上传新文件到文件服务器
             //excel修改 同步修改html 对象
             String thmlUrl = file_path + filecode + ".html";
-            ExcelInfoUtils.excelInfo(Files.newInputStream(file.toPath()), excelFile, thmlUrl, "2");
+            ExcelInfoUtils.excelInfo(Files.newInputStream(file.toPath()), excelFile, thmlUrl, "2",1);
             //获取数据库信息
             ExcelTab excelTab = baseMapper.selectById(Long.parseLong(tabId));
             //上传到服务器
@@ -6934,82 +6888,6 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         if(file.exists()){
             file.delete();
         }
-        File file2 = new File(jsonFile);
-        if (file2.exists()) {
-            file2.delete();
-        }
-        return R.success("成功");
-    }
-
-
-
-
-    /**
-     * 从远程URL下载文件到本地临时文件
-     * @param fileUrl 远程文件的URL
-     * @return 本地临时文件
-     * @throws IOException 当下载或文件创建失败时抛出
-     */
-    public static File downloadFileToTemp(String fileUrl,String lsFile) throws IOException {
-        // 创建临时文件
-        File tempFile = new File(lsFile);
-        tempFile.deleteOnExit(); // 确保程序退出时删除临时文件
-
-        HttpURLConnection connection = null;
-        InputStream inputStream = null;
-        FileOutputStream outputStream = null;
-
-        try {
-            URL url = new URL(fileUrl);
-            connection = (HttpURLConnection) url.openConnection();
-            connection.setRequestMethod("GET");
-            connection.setConnectTimeout(30000);
-            connection.setReadTimeout(30000);
-
-            // 检查HTTP响应码
-            int responseCode = connection.getResponseCode();
-            if (responseCode != HttpURLConnection.HTTP_OK) {
-                throw new IOException("服务器返回HTTP响应码: " + responseCode);
-            }
-
-            // 获取输入流
-            inputStream = connection.getInputStream();
-
-            // 创建输出流写入临时文件
-            outputStream = new FileOutputStream(tempFile);
-
-            // 缓冲区大小
-            byte[] buffer = new byte[4096];
-            int bytesRead;
-
-            // 读取数据并写入文件
-            while ((bytesRead = inputStream.read(buffer)) != -1) {
-                outputStream.write(buffer, 0, bytesRead);
-            }
-
-            System.out.println("文件下载成功: " + tempFile.getAbsolutePath());
-            return tempFile;
-
-        } finally {
-            // 确保资源被关闭
-            if (inputStream != null) {
-                try {
-                    inputStream.close();
-                } catch (IOException e) {
-                    System.err.println("关闭输入流时出错: " + e.getMessage());
-                }
-            }
-            if (outputStream != null) {
-                try {
-                    outputStream.close();
-                } catch (IOException e) {
-                    System.err.println("关闭输出流时出错: " + e.getMessage());
-                }
-            }
-            if (connection != null) {
-                connection.disconnect();
-            }
-        }
+        return true;
     }
-
 }

+ 184 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/ExcelInfoUtils.java

@@ -209,6 +209,190 @@ public class ExcelInfoUtils {
     }
 
 
+    public static void excelInfo(InputStream inputStream, String excelURL, String htmlUrl,String type, Integer isSave) {
+        try {
+            String file_path = "/Users/hongchuangyanfa/Desktop//pdf/";
+            String filecode = SnowFlakeUtil.getId() + "";
+            String thmlUrl2 = file_path + filecode + "123.html";
+
+            // 解析原始excel
+            Workbook wb = new Workbook();
+            wb.loadFromStream(getInputStreamByUrl(inputStream));
+            Worksheet sheet = wb.getWorksheets().get(0);
+            HTMLOptions options = new HTMLOptions();
+            options.setImageEmbedded(true);
+
+            // 校验excel 是否正常
+            sheet.saveToHtml(htmlUrl, options);
+            File file1 = ResourceUtil.getFile(htmlUrl);
+            String htmlString = IoUtil.readToString(new FileInputStream(file1));
+            Document doc = Jsoup.parse(htmlString);
+            Element table = doc.select("table").first();
+            Elements trs = table.select("tr");
+            Elements cols = table.select("Col");
+            sheet.deleteRow(trs.size()+1,sheet.getRows().length - trs.size());
+            sheet.deleteColumn(cols.size()+1,sheet.getColumns().length - cols.size());
+            file1.delete();
+            //复制一份
+            if(isSave == null){
+                wb.saveToFile(excelURL,FileFormat.Version2013);
+            }
+            // 操作
+            Workbook wb2 = new Workbook();
+            wb2.loadFromMHtml(excelURL);
+            Worksheet sheet2 = wb2.getWorksheets().get(0);
+
+            // 坐标map
+            Map<String, Map<String, Integer>> xyList = new HashMap<>();
+            int j = 0;
+            int maxVal = 0;
+            if(type.equals("2")){
+                CellRange[] sheet2Cells = sheet2.getCells();
+                for (int i = 0; i < sheet2Cells.length; i++) {
+                    CellRange oldcell = sheet2Cells[i];
+                    String data = oldcell.getDataValidation().getErrorMessage();
+                    int k = 0;
+                    if(Func.isNumeric(data)){
+                        k = Func.toInt(data);
+                    }
+                    if (maxVal < k) {
+                        maxVal = k;
+                    }
+                }
+            }else if(type.equals("1")){
+                CellRange[] sheet2Cells = sheet.getCells();
+                for (int i = 0; i < sheet2Cells.length; i++) {
+                    CellRange oldcell = sheet2Cells[i];
+                    oldcell.getDataValidation().setErrorMessage("");
+                    sheet.get(oldcell.getRow(),oldcell.getColumn()).getDataValidation().setErrorMessage("");
+                }
+            }
+
+            //合并单元格操作
+            CellRange[] mergedCells = sheet.getMergedCells();
+            for (int i = 0; i < mergedCells.length; i++) {
+                Map<String, Integer> dataMap = new HashMap<>();
+                CellRange oldcell = mergedCells[i];
+                CellRange mergedCell = sheet.getCellRange(oldcell.getRow(), oldcell.getColumn());
+                if(type.equals("2")){
+                    String data = mergedCell.getDataValidation().getErrorMessage();
+                    if (StringUtils.isEmpty(data)) {
+                        if(maxVal<=0){
+                            j = j + 1;
+                        }else{
+                            maxVal = maxVal+1;
+                            j=maxVal;
+                        }
+                    } else {
+                        j = Func.toInt(data);
+                    }
+                }else{
+                    j = j + 1;
+                }
+                // 目标表添加备注信息
+                mergedCell.getDataValidation().setErrorMessage(j+"");
+                oldcell.getDataValidation().setErrorMessage(j+"");
+                sheet2.getMergedCells()[i].setText(j+"");
+                dataMap.put("y1", oldcell.getRow());
+                dataMap.put("y2", oldcell.getLastRow());
+                dataMap.put("x1", oldcell.getColumn());
+                dataMap.put("x2", oldcell.getLastColumn());
+                xyList.put(j + "", dataMap);
+            }
+
+            //变更最大值
+            if(maxVal<=0){
+                maxVal = j;
+            }
+
+            // 单个
+            CellRange[] onCell = sheet.getCells();
+            // 单个cell
+            for (int i = 0; i < onCell.length; i++) {
+                CellRange oldcell = onCell[i];
+                String data = oldcell.getDataValidation().getErrorMessage();
+                System.out.println(oldcell.getRow()+"---"+oldcell.getColumn()+"---="+oldcell.getText()+"---x="+data);
+                if (StringUtils.isEmpty(data)) {
+                    if(maxVal<=0){
+                        j = j + 1;
+                    }else{
+                        maxVal = maxVal+1;
+                        j=maxVal;
+                    }
+                } else {
+                    j = Func.toInt(data);
+                }
+
+              /*  if(StringUtils.isEmpty(data)){
+                    oldcell.getDataValidation().setErrorMessage(j+"");
+                    sheet2.getCells()[i].setText(j+"");
+                }*/
+
+                if(!xyList.containsKey(j+"")){
+                    Map<String, Integer> dataMap = new HashMap<>();
+                    dataMap.put("y1", oldcell.getRow());
+                    dataMap.put("y2", oldcell.getLastRow());
+                    dataMap.put("x1", oldcell.getColumn());
+                    dataMap.put("x2", oldcell.getLastColumn());
+                    xyList.put(j + "", dataMap);
+                }
+            }
+
+            // 保存上传的excel
+            if(isSave == null) {
+                wb.saveToFile(excelURL, FileFormat.Version2013);
+            }
+            sheet.saveToHtml(htmlUrl, options);
+            sheet2.saveToHtml(thmlUrl2);
+
+            // html 转换值
+
+            // 组装坐标
+            File html1 = new File(htmlUrl);  // 原始html
+            File html2 = new File(thmlUrl2); // 坐标html
+            InputStream inputStream1 = new FileInputStream(html1);
+            InputStream inputStream2 = new FileInputStream(html2);
+            String htmlString1 = IoUtil.readToString(inputStream1);
+            String htmlString2 = IoUtil.readToString(inputStream2);
+
+            Document doc1 = Jsoup.parse(htmlString1);
+            Element table1 = doc1.select("table").first();
+            Elements trs1 = table1.select("tr");
+            Document doc2 = Jsoup.parse(htmlString2);
+            Element table2 = doc2.select("table").first();
+            Elements trs2 = table2.select("tr");
+
+            for (int i = 0; i < trs1.size(); i++) {
+                Elements td1 = trs1.get(i).select("td");
+                Elements td2 = trs2.get(i).select("td");
+                for (int x = 0; x < td1.size(); x++) {
+                    Element cell1 = td1.get(x);
+                    Element cell2 = td2.get(x);
+                    String html = cell2.text();
+                    Map<String, Integer> xyMap = xyList.get(html);
+                    if (xyMap != null) {
+                        cell1.attr("x1", xyMap.get("x1") + "");
+                        cell1.attr("x2", xyMap.get("x2") + "");
+                        cell1.attr("y1", xyMap.get("y1") + "");
+                        cell1.attr("y2", xyMap.get("y2") + "");
+                        cell1.attr("exceVal",html);
+                    }
+                }
+            }
+
+            File writeFile = new File(htmlUrl);
+            FileUtil.writeToFile(writeFile, doc1.html(), Boolean.parseBoolean("UTF-8"));
+            if (html2.exists()) {
+                // html2.delete();
+            }
+            wb2.dispose();
+            wb.dispose();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+
     /**
      * 解析excel 对隐藏的列设置初始列宽
      * @param inputStream

+ 39 - 0
blade-service/blade-user/pom.xml

@@ -23,6 +23,20 @@
         <dependency>
             <groupId>org.springblade</groupId>
             <artifactId>blade-starter-excel</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.poi</groupId>
+                    <artifactId>poi</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.poi</groupId>
+                    <artifactId>poi-ooxml</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.poi</groupId>
+                    <artifactId>poi-ooxml-schemas</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.springblade</groupId>
@@ -55,6 +69,31 @@
             <version>2.9.1.RELEASE</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>io.github.autoffice</groupId>
+            <artifactId>luckysheet-lib</artifactId>
+            <version>1.1.0</version>
+            <scope>system</scope>
+            <systemPath>${basedir}/../../doc/lib/excelLib/luckysheet-lib-1.1.0.jar</systemPath>
+        </dependency>
+
+        <!-- poi -->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>5.4.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>5.4.0</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.18.0</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 235 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/controller/ExcelTableController.java

@@ -0,0 +1,235 @@
+package org.springblade.system.user.controller;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.json.JSONUtil;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import io.github.autoffice.luckysheet.LuckysheetConverter;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.oss.model.BladeFile;
+import org.springblade.core.tool.api.R;
+import org.springblade.manager.entity.ExcelEditCallback;
+import org.springblade.manager.entity.ExcelTab;
+import org.springblade.manager.feign.ExcelTabClient;
+import org.springblade.resource.feign.NewIOSSClient;
+import org.springblade.system.user.util.FileUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.file.Files;
+
+
+/**
+ * @author LHB
+ */
+@RestController
+@RequestMapping(value = "/excel-table")
+@AllArgsConstructor
+@Api(value = "excel5.4.0接口", tags = "excel5.4.0接口")
+public class ExcelTableController {
+
+    private final ExcelTabClient excelTabClient;
+
+    /**
+     * 在线excel 获取文件json数据
+     *
+     * @throws IOException
+     */
+    @PostMapping(value = "/getExcelUrl")
+    @ApiOperation(value = "获取文件json数据", notes = "获取文件json数据")
+    @ApiOperationSupport(order = 35)
+    @ResponseBody
+    public R getExcelUrl(@RequestBody ExcelEditCallback callback) {
+        //创建临时文件
+        //获取onlyOffice缓存中的文件流
+        String file_path = FileUtils.getSysLocalFileUrl();
+        String filecode = SnowFlakeUtil.getId() + "";
+        String dataUrl = file_path + "/excel/" + filecode + ".xlsx";
+
+        try {
+            boolean b = downloadExcelFile(callback.getUrl(), dataUrl);
+            if(!b){
+                return R.fail("文件加载失败");
+            }
+            File file = new File(dataUrl);
+            if(file != null){
+                // 将excel文件转为luckysheet json
+                String json = LuckysheetConverter.excelToLuckySheetJson(dataUrl);
+                cn.hutool.json.JSONObject entries = JSONUtil.parseObj(json);
+                cn.hutool.json.JSONArray sheets = entries.getJSONArray("sheets");
+
+                //删除临时文件
+                if (file.exists()) {
+                    file.delete();
+                }
+                return R.data(sheets.toString());
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        return R.fail("文件异常");
+    }
+
+    /**
+     * 在线excel 保存
+     *
+     * @throws IOException
+     */
+    @PostMapping(value = "/saveExcel")
+    @ApiOperation(value = "在线excel 保存", notes = "在线excel 保存")
+    @ApiOperationSupport(order = 35)
+    @ResponseBody
+    public R saveExcel(@RequestBody ExcelEditCallback callback) {
+        String tabId = callback.getKey();
+        if (tabId == null) {
+            throw new ServiceException("excel为空");
+        }
+
+        String file_path = FileUtils.getSysLocalFileUrl();
+        String filecode = SnowFlakeUtil.getId() + "";
+        //创建临时json文件
+        String jsonFile = file_path + "/excel/" + filecode + ".json";
+        //创建临时excel文件
+        String excelFile = file_path + "/excel/" + filecode + ".xlsx";
+
+        try (FileWriter file = new FileWriter(jsonFile)) {
+
+            String jsonExcel = callback.getJsonExcel();
+            cn.hutool.json.JSONArray objects = JSONUtil.parseArray(jsonExcel);
+            cn.hutool.json.JSONObject entries = new cn.hutool.json.JSONObject();
+            cn.hutool.json.JSONObject info = new cn.hutool.json.JSONObject();
+            info.set("name","");
+            info.set("createdTime", DateTime.now());
+            info.set("modifiedTime",DateTime.now());
+            entries.set("info",info);
+            entries.set("sheets",objects);
+            jsonExcel = entries.toString();
+
+            file.write(jsonExcel);
+            file.flush();
+            System.out.println("JSON数据已成功保存到: " + jsonFile);
+        } catch (IOException e) {
+            System.err.println("保存JSON文件时出错: " + e.getMessage());
+            e.printStackTrace();
+        }
+        //获取文件流
+        File file = new File(excelFile);
+
+        try {
+            // 将luckysheet json文件转为excel
+            LuckysheetConverter.luckysheetToExcel(jsonFile, excelFile);
+
+            //通过poi5.4.0 转成excel之后
+
+            //记录最新的excel文件
+            callback.setUrl(excelFile);
+            //把文件传到manage 处理文件保存
+            boolean b = excelTabClient.saveExcelTableLink(callback);
+            if(b == false){
+                return R.fail("失败");
+            }
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        File file2 = new File(jsonFile);
+        if (file2.exists()) {
+            file2.delete();
+        }
+        return R.success("成功");
+    }
+
+
+
+
+
+
+
+
+
+    /**
+     * 下载远程Excel文件到本地,保持所有样式不变
+     *
+     * @param remoteFileUrl 远程Excel文件的URL地址
+     * @param localFilePath 本地保存路径(包括文件名)
+     * @return 下载成功返回true,否则返回false
+     */
+    public static boolean downloadExcelFile(String remoteFileUrl, String localFilePath) {
+        HttpURLConnection httpConn = null;
+        BufferedInputStream in = null;
+        FileOutputStream out = null;
+
+        try {
+            // 创建URL对象
+            URL url = new URL(remoteFileUrl);
+
+            // 打开连接
+            httpConn = (HttpURLConnection) url.openConnection();
+            httpConn.setRequestMethod("GET");
+            httpConn.connect();
+
+            // 检查HTTP响应码
+            int responseCode = httpConn.getResponseCode();
+            if (responseCode != HttpURLConnection.HTTP_OK) {
+                System.err.println("服务器返回HTTP代码: " + responseCode);
+                return false;
+            }
+
+            // 获取文件大小(用于可能的进度跟踪)
+            int contentLength = httpConn.getContentLength();
+
+            // 创建保存目录(如果不存在)
+            File localFile = new File(localFilePath);
+            File parentDir = localFile.getParentFile();
+            if (parentDir != null && !parentDir.exists()) {
+                parentDir.mkdirs();
+            }
+
+            // 创建输入输出流
+            in = new BufferedInputStream(httpConn.getInputStream());
+            out = new FileOutputStream(localFile);
+
+            byte[] buffer = new byte[8192];
+            int bytesRead;
+            long totalRead = 0;
+
+            System.out.println("开始下载Excel文件...");
+
+            // 读取数据并写入本地文件
+            while ((bytesRead = in.read(buffer)) != -1) {
+                out.write(buffer, 0, bytesRead);
+                totalRead += bytesRead;
+
+                // 可选:显示下载进度
+                if (contentLength > 0) {
+                    int progress = (int) (totalRead * 100 / contentLength);
+                    System.out.print("\r下载进度: " + progress + "%");
+                }
+            }
+
+            System.out.println("\nExcel文件下载完成: " + localFilePath);
+            return true;
+
+        } catch (IOException ex) {
+            System.err.println("下载过程中发生错误: " + ex.getMessage());
+            ex.printStackTrace();
+            return false;
+        } finally {
+            // 关闭资源
+            try {
+                if (in != null) in.close();
+                if (out != null) out.close();
+                if (httpConn != null) httpConn.disconnect();
+            } catch (IOException ex) {
+                System.err.println("关闭资源时发生错误: " + ex.getMessage());
+            }
+        }
+    }
+}

+ 65 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/util/FileUtils.java

@@ -13,9 +13,12 @@ import org.apache.poi.ss.usermodel.ClientAnchor;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.Units;
+import org.springblade.common.constant.CommonConstant;
 import org.springblade.common.utils.CommonUtil;
+import org.springblade.common.utils.SystemUtils;
 import org.springblade.common.vo.DataVO;
 import org.springblade.core.tool.utils.IoUtil;
+import org.springblade.system.cache.ParamCache;
 
 import javax.imageio.IIOImage;
 import javax.imageio.ImageIO;
@@ -266,6 +269,68 @@ public class FileUtils {
         return -1;
     }
 
+    public static String getNetUrl(String fileUrl) {
+        String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+        String file_path2 = getSysLocalFileUrl();
+        String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
+        String sys_isonline = ParamCache.getValue(CommonConstant.SYS_ISONLINE);
+        if(fileUrl.indexOf("aliyuncs.com") >= 0 || fileUrl.indexOf("xinan1.zos.ctyun.cn")>=0 || fileUrl.indexOf("/mnt/sdc/Users/hongchuangyanfa/Desktop/")>=0){
+            if(fileUrl.indexOf("/mnt/sdc/Users/hongchuangyanfa/Desktop/")>=0){
+                if(SystemUtils.isWindows() || SystemUtils.isMacOs()){
+                    file_path2 = file_path;
+                }else{
+                    return sys_file_net_url + fileUrl.replaceAll("//", "/").replaceAll(file_path2, "");
+                }
+            }else{
+                return fileUrl;
+            }
+        } else {
+            if("20".equals(sys_isonline)){
+                file_path2 = file_path;
+            }
+        }
+        String s1 = fileUrl.replaceAll("//", "/").replace("///","/");
+        file_path2= file_path2.replaceAll("//","/").replaceAll("///","/");
+        String s2= s1.replaceAll(file_path2, "");
+        String path = sys_file_net_url + s2;
+        return path;
+    }
+
+    public static String getSysLocalFileUrl() {
+        String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+        String sys_isonline = ParamCache.getValue(CommonConstant.SYS_ISONLINE);
+
+        if (sys_isonline.equals("1")) { //正式环境
+            if (SystemUtils.isMacOs()) {
+                file_path = "/Users/hongchuangyanfa/Desktop/";
+            } else if (SystemUtils.isWindows()) {
+                file_path = "C://upload//";
+            }
+        } else if (sys_isonline.equals("2")) { //109测试环境
+            if (SystemUtils.isMacOs()) {
+                file_path = "/www/wwwroot/Users/hongchuangyanfa/Desktop/";
+            } else if (SystemUtils.isWindows()) {
+                file_path = "C://upload//";
+            }
+        } else if (sys_isonline.equals("20")) { //183
+            if (SystemUtils.isLinux()) {
+                file_path = "/home/www/wwwroot/Users/hongchuangyanfa/Desktop/";
+            } else if (SystemUtils.isMacOs()) {
+                file_path = "/Users/hongchuangyanfa/Desktop/";
+            } else if (SystemUtils.isWindows()) {
+                file_path = "C://upload//";
+            }
+        } else {  //本地环境
+            if (SystemUtils.isMacOs()) {
+                file_path = "/Users/hongchuangyanfa/Desktop/";
+            } else if (SystemUtils.isWindows()) {
+                file_path = "C://upload//";
+            }
+        }
+        return file_path;
+    }
+
+
     /**
      * 合并方法
      */

BIN
doc/lib/excelLib/luckysheet-lib-1.1.0.jar