【山东大学项目实训】解决后端报错

pom.xml配置:

修改POI的版本使其保持一致,不然会出现版本不匹配的问题

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>5.2.3</version>
</dependency>

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.2.3</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-scratchpad</artifactId>
    <version>5.2.3</version>
</dependency>

添加xmlbeans (在生成PPT时出现报错发现的问题)

这是因为POI 在处理 Office 文档(如 PPTX、XLSX 等)时,会使用 xmlbeans 来解析和生成 XML 数据。现代 Office 文件格式(如 PPTX 和 XLSX)实际上是以 ZIP 压缩包形式存储的 XML 文件集合。

<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>5.1.1</version>
</dependency>

后端word和pdf文字提取功能,路径写死了,无法跟前端文件上传按钮进行交互

我们是这样解决的:直接在前端实现文件的文字提取,再将前端提取的文字返回给后端进行下一个功能(调用api接口,根据上传的大纲生成具体内容)。

前端实现文字提取代码如下:

    handleFileUpload(event) {

      const file = event.target.files[0];

      if (file) {

        const reader = new FileReader();

        reader.onload = async (e) => {

          const arrayBuffer = e.target.result;

          const fileExtension = file.name.split(".").pop().toLowerCase();

             if (fileExtension === "doc" || fileExtension === "docx") {

            this.fileContent = await this.extractWordText(arrayBuffer);

          }

          // Navigate to the outline page with the file content

          this.$router.push({

            path: '/outline',

            query: { outline: this.fileContent }

          });

        };

        reader.readAsArrayBuffer(file);

      }

    },



    async extractWordText(arrayBuffer) {

      try {

        const result = await mammoth.extractRawText({ arrayBuffer: arrayBuffer });

        return result.value;

      } catch (error) {

        console.error("Error extracting Word text:", error);

        return "Error extracting Word text";

      }

    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值