新增前端解析xlsx方法

This commit is contained in:
gaoxiongzaq
2023-06-02 14:55:32 +08:00
parent 8135fce136
commit b9f438bc01
69 changed files with 56978 additions and 5 deletions

View File

@ -47,6 +47,7 @@ public class ConfigConstants {
private static String size;
private static String password;
private static int pdf2JpgDpi;
private static String officeTypeWeb;
private static Boolean deleteSourceFile;
public static final String DEFAULT_CACHE_ENABLED = "true";
@ -73,6 +74,7 @@ public class ConfigConstants {
public static final String DEFAULT_PROHIBIT = "exe,dll";
public static final String DEFAULT_PASSWORD = "123456";
public static final String DEFAULT_PDF2_JPG_DPI = "105";
public static final String DEFAULT_OFFICE_TyPEWEB_DISABLE = "web";
public static final String DEFAULT_DELETE_SOURCE_FILE = "true";
public static Boolean isCacheEnabled() {
@ -414,7 +416,7 @@ public class ConfigConstants {
public static int getPdf2JpgDpi() {
return pdf2JpgDpi;
}
@Value("${pdf.picture.size:105}")
@Value("${pdf2jpg.dpi:105}")
public void pdf2JpgDpi(int pdf2JpgDpi) {
setPdf2JpgDpiValue(pdf2JpgDpi);
}
@ -422,6 +424,17 @@ public class ConfigConstants {
ConfigConstants.pdf2JpgDpi = pdf2JpgDpi;
}
public static String getofficeTypeWeb() {
return officeTypeWeb;
}
@Value("${office.type.web:web}")
public void setofficeTypeWeb(String officeTypeWeb) {
setofficeTypeWebValue(officeTypeWeb);
}
public static void setofficeTypeWebValue(String officeTypeWeb) {
ConfigConstants.officeTypeWeb = officeTypeWeb;
}
public static Boolean getDeleteSourceFile() {
return deleteSourceFile;

View File

@ -59,6 +59,7 @@ public class ConfigRefreshComponent {
String size;
String password;
int pdf2JpgDpi;
String officeTypeWeb;
boolean deleteSourceFile;
while (true) {
FileReader fileReader = new FileReader(configFilePath);
@ -89,6 +90,7 @@ public class ConfigRefreshComponent {
prohibit = properties.getProperty("prohibit", ConfigConstants.DEFAULT_PROHIBIT);
password = properties.getProperty("sc.password", ConfigConstants.DEFAULT_PASSWORD);
pdf2JpgDpi = Integer.parseInt(properties.getProperty("pdf2jpg.dpi", ConfigConstants.DEFAULT_PDF2_JPG_DPI));
officeTypeWeb = properties.getProperty("office.type.web", ConfigConstants.DEFAULT_OFFICE_TyPEWEB_DISABLE);
deleteSourceFile = Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_DELETE_SOURCE_FILE));
prohibitArray = prohibit.split(",");
@ -114,6 +116,7 @@ public class ConfigRefreshComponent {
ConfigConstants.setProhibitValue(prohibitArray);
ConfigConstants.setPasswordValue(password);
ConfigConstants.setPdf2JpgDpiValue(pdf2JpgDpi);
ConfigConstants.setofficeTypeWebValue(officeTypeWeb);
ConfigConstants.setDeleteSourceFileValue(deleteSourceFile);
setWatermarkConfig(properties);
bufferedReader.close();

View File

@ -32,6 +32,7 @@ public interface FilePreview {
String DCM_FILE_PREVIEW_PAGE = "dcm";
String DRAWUI_FILE_PREVIEW_PAGE = "drawio";
String NOT_SUPPORTED_FILE_PAGE = "fileNotSupported";
String XLSX_FILE_PREVIEW_PAGE = "officeweb";
String filePreviewHandle(String url, Model model, FileAttribute fileAttribute);
}

View File

@ -57,6 +57,14 @@ public class OfficeFilePreviewImpl implements FilePreview {
String pdfName = fileName.substring(0, fileName.lastIndexOf(".") ) + suffix +"." +(isHtml ? "html" : "pdf"); //生成文件添加类型后缀 防止同名文件
String cacheFileName = userToken == null ? pdfName : userToken + "_" + pdfName;
String outFilePath = FILE_DIR + cacheFileName;
if(!officePreviewType.equalsIgnoreCase("html")){
if(officePreviewType.equalsIgnoreCase("web")|| ConfigConstants.getofficeTypeWeb() .equalsIgnoreCase("web") ){
if(suffix.equalsIgnoreCase("xlsx")){
model.addAttribute("pdfUrl", url);
return XLSX_FILE_PREVIEW_PAGE;
}
}
}
if (forceUpdatedCache|| !fileHandlerService.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) {
// 下载远程文件到本地,如果文件在本地已存在不会重复下载
ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);