main
黄海 8 months ago
parent 62c0d6816c
commit 6c8ed75295

@ -1,8 +1,6 @@
package com.dsideal.QingLong.DataShare.Controller;
import cn.hutool.core.io.FileUtil;
import com.aspose.cells.PdfSaveOptions;
import com.aspose.cells.Workbook;
import com.dsideal.QingLong.DataShare.Model.DataShareModel;
import com.dsideal.QingLong.Interceptor.*;
import com.dsideal.QingLong.Util.AsposeUtil;
@ -145,70 +143,6 @@ public class DataShareController extends Controller {
renderFile(new File(basePath + file_name), "【" + system_name + "】文档说明.xlsx");
}
/**
* EXCEL
*
* @param system_id
*/
@Before({GET.class})
@IsLoginInterface({})
@IsNumericInterface({"system_id"})
@IsSysAdminInterface({"1"})
public void previewXlsx(int system_id) throws Exception {
Record record = dm.getSystemById(system_id);
boolean Error = false;
String url = "";
if (record == null) {
Error = true;
} else {
url = record.getStr("url");
if (StrKit.isBlank(url)) {
Error = true;
}
}
if (Error) {
Kv kv = Kv.by("success", false);
kv.set("message", "此系统还没有上传说明文档,无法下载!");
renderJson(kv);
return;
}
String[] array = url.split("/");
String file_name = array[array.length - 1];
String basePath = PathKit.getWebRootPath() + "/upload/";
String realPath = basePath + file_name;
realPath = realPath.replace("\\", "/");
String system_name = record.getStr("system_name");
//注册信息
AsposeUtil.getLicense();
Workbook wb = new Workbook(realPath);// 原始excel路径
String targetPath = realPath.replace(".xlsx", ".pdf");
FileOutputStream fileOS = new FileOutputStream(targetPath);
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setOnePagePerSheet(true);
wb.save(fileOS, pdfSaveOptions);
fileOS.flush();
fileOS.close();
HttpServletResponse response = getResponse();
BufferedInputStream br = new BufferedInputStream(new FileInputStream(targetPath));
byte[] buf = new byte[1024];
int len;
response.reset(); // 非常重要
URI uri = new URI("file:///" + targetPath);
URL u = uri.toURL();
response.setContentType(u.openConnection().getContentType());
String fileName = "【" + system_name + "】文档说明.pdf";
response.setHeader("Content-Disposition", "inline; filename=" + fileName);
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
renderNull();
}
/**
* ID
*

Loading…
Cancel
Save