Commit 71f7ef06 authored by wangyangyang's avatar wangyangyang

图册:excel转pdf

parent ac187bdd
...@@ -271,7 +271,8 @@ public class ExtAutoTaskServiceImpl implements ExtAutoTaskService { ...@@ -271,7 +271,8 @@ public class ExtAutoTaskServiceImpl implements ExtAutoTaskService {
//转pdf //转pdf
String pdfName = "图册.pdf"; String pdfName = "图册.pdf";
String filePdfPath = dir + File.separator + pdfName; String filePdfPath = dir + File.separator + pdfName;
ExcelUtils.excelToPDF(filePath, filePdfPath); // ExcelUtils.excelToPDF(filePath, filePdfPath);
ConvertExcelToPdf.excelToPDF(filePath, filePdfPath);
//上传文件到文件服务器 //上传文件到文件服务器
MultipartFile multipartFile = new MockMultipartFile("file", pdfName, com.yonde.dcs.plan.common.constants.Constants.CONTENT_TYPE_PDF, new FileInputStream(filePdfPath)); MultipartFile multipartFile = new MockMultipartFile("file", pdfName, com.yonde.dcs.plan.common.constants.Constants.CONTENT_TYPE_PDF, new FileInputStream(filePdfPath));
RepoFileVO fileVO = fileManagerFeignService.uploadFile(multipartFile, CommonUtil.getBucketIdByAppName(com.yonde.dcs.document.core.constants.Constants.APPLICATION_DOC_INNER_NAME)); RepoFileVO fileVO = fileManagerFeignService.uploadFile(multipartFile, CommonUtil.getBucketIdByAppName(com.yonde.dcs.document.core.constants.Constants.APPLICATION_DOC_INNER_NAME));
......
package com.yonde.dcs.document.core.util;
import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;
public class ConvertExcelToPdf {
/**
* excel转pdf
* @param excelPath xlsx
* @param pdfPath
*/
public static void excelToPDF(String excelPath, String pdfPath) {
//创建一个Workbook实例并加载Excel文件
Workbook workbook = new Workbook();
workbook.loadFromFile(excelPath);
//设置转换后的PDF页面高宽适应工作表的内容大小
workbook.getConverterSetting().setSheetFitToPage(true);
//将生成的文档保存到指定路径
workbook.saveToFile(pdfPath, FileFormat.PDF);
}
public static void main(String[] args) {
String dir = "C:\\Users\\Lenovo\\Desktop\\test\\";
excelToPDF(dir + "图册.xlsx", dir + "图.pdf");
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment