| | |
| | | |
| | | package com.zt.modules.oss.cloud; |
| | | |
| | | import com.aspose.words.Document; |
| | | import com.aspose.words.SaveFormat; |
| | | import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
| | | import com.spire.xls.Workbook; |
| | | import com.zt.common.exception.ErrorCode; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | /** |
| | | * 本地上传 |
| | |
| | | documentBytes = outputStream.toByteArray(); |
| | | headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); |
| | | } |
| | | if (filename.endsWith(".doc") || filename.endsWith(".docx") || filename.endsWith(".xlsx")) { |
| | | |
| | | if (filename.endsWith(".doc")) { |
| | | // 使用 Aspose.Words 进行文档转换 |
| | | Document doc = new Document(in); |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | doc.save(outputStream, SaveFormat.DOCX); |
| | | |
| | | documentBytes = outputStream.toByteArray(); |
| | | headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); |
| | | headers.setContentDispositionFormData("attachment", filename.replace(".doc", ".docx")); |
| | | |
| | | } else if (filename.endsWith(".docx") || filename.endsWith(".xlsx")) { |
| | | documentBytes = FileCopyUtils.copyToByteArray(in); |
| | | headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); |
| | | headers.setContentDispositionFormData("attachment", filename); |
| | |
| | | is.close(); |
| | | out.flush(); |
| | | out.close(); |
| | | |
| | | } |
| | | } |
| | | } |