This paper introduces how to convert an Excel workbook into a PDF document with a Java program, including
Tools used: Free Spire.XLS for Java (free version) https://www.e-iceblue.com/Introduce/free-xls-for-java.html
Getting and installing Jar files: Method 1: Download the jar file bag through the homepage. After downloading, unzip the file and install the Spire.xls.jar file under the lib folder into your Java program. https://www.e-iceblue.com/Download/xls-for-java-free.html
Method 2: Introduction by maven warehouse installation: https://www.e-iceblue.com/Tutorials/Licensing/How-to-install-Spire.PDF-for-Java-from-Maven-Repository.html
The Excel test document is as follows. Includes two sheets:
JAVA Samples
Demo 1. Change the entire workbook to PDF
import com.spire.xls.*;
public class ExcelToPDF {
public static void main(String[] args) {
//Import an Excel document
Workbook wb = new Workbook();
wb.loadFromFile("test.xlsx");
//Save the calling method in PDF format
wb.saveToFile("ToPDF.pdf",FileFormat.PDF);
}
}
Effect diagram:
Demo 2. Change the specified sheet to PDF
import com.spire.xls.*;
public class ExcelToPDF {
public static void main(String[] args) {
//Import an Excel document
Workbook wb = new Workbook();
wb.loadFromFile("test.xlsx");
//Get the second sheet
Worksheet sheet = wb.getWorksheets().get(1);
//Save the calling method in PDF format
sheet.saveToPdf("ToPDF2.pdf");
}
}
Effect diagram:
The END
Recommended Posts