liusheng
2024-07-04 6a58a5a148c27c9ff66901bfbae6e52c1a56b5d2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
@@ -21,6 +21,7 @@
import com.ruoyi.common.enums.PhotoEnum;
import com.ruoyi.common.enums.RadioEnum;
import com.ruoyi.common.enums.VadioEnum;
import com.smartor.domain.HtmlContentVO;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.converter.PicturesManager;
import org.apache.poi.hwpf.converter.WordToHtmlConverter;
@@ -32,10 +33,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
@@ -224,6 +222,26 @@
        }
    }
    /**
     * @param HtmlContentVO
     * @return
     */
    @GetMapping("/common/htmlContent")
    public AjaxResult htmlContent(@RequestBody HtmlContentVO htmlContentVO) {
        // 获取文件的原始名称
        String fileName = htmlContentVO.getFileName();
        // 将文件保存到指定目录
        File outputFile = new File(RuoYiConfig.getUploadPath() + "/show/" + fileName.split("\\.", 2)[0] + fileName);
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
            writer.write(htmlContentVO.getContent());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return AjaxResult.success();
    }
    public static void convertDocToHtml(String docFilePath, String outputHtmlFilePath) throws TransformerException, IOException, ParserConfigurationException {
        InputStream inputStream = new FileInputStream(docFilePath);
@@ -244,8 +262,6 @@
        } catch (Exception e) {
            e.getMessage();
        }
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
@@ -257,7 +273,7 @@
        StreamResult streamResult = new StreamResult(new File(outputHtmlFilePath));
        transformer.transform(domSource, streamResult);
        System.out.println("Conversion completed successfully.");
        System.out.println("word转html成功");
    }