用Spire工具 把Excel文件轉為pdf文件並保存
參考Java 將Excel轉為PDF 幫助文檔 文檔轉換 Java 將 Excel 轉為 PDF
1.添加jar包 或者 添加依賴
2.把C:/TEST/test.xlsx文件 轉為為C:/TEST/test.pdf文件
import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;
public class ExcelToPdf {
public static void main(String[] args) {
String newFilePath = "C:/TEST/test.xlsx";
String newPDFPath = "C:/TEST/test.pdf";
excelToPdf(newFilePath, newPDFPath);
}
public static void excelToPdf(String excelPath, String pdfPath) {
// load excel file
Workbook wb = new Workbook();
wb.loadFromFile(excelPath);
// convert excel file to pdf file
wb.saveToFile(pdfPath, FileFormat.PDF);
}
}
下載包 地址Free Spire.XLS for Java
下載后 把Spire.Xls-FE_2.2.0.zip 解壓。然后在Spire.Xls-FE_2.2.0\lib文件下找到 Spire.Xls.jar包,把Spire.Xls.jar復制到你自己的項目。就可以用了。