The Java Excel to PDF
This article describes how to Excel workbooks into PDF documents in Java programs, including:
the entire workbook to PDF
assign worksheets to PDF
using the tool: Free Spire.XLS for Java ( free version)
Jar file download and import:
Method 1: download through the official website. After the download, unzip the file, the lib folder under the Spire.Xls.jar files into Java programs.
Method 2: By introducing maven repository
JAVA code samples
[Example 1] The entire workbook into PDF
the Java Code Collection Code
import com.spire.xls *.;
public class ExcelToPDF {
public static void main(String[] args) {
//加载Excel文档
Workbook wb = new Workbook();
wb.loadFromFile("test.xlsx");
//调用方法保存为PDF格式
wb.saveToFile("ToPDF.pdf",FileFormat.PDF);
}
}
[Example 2] specifies the worksheet into PDF
the Java Code Collection Code
import com.spire.xls *.;
public class ExcelToPDF {
public static void main(String[] args) {
//加载Excel文档
Workbook wb = new Workbook();
wb.loadFromFile("test.xlsx");
//获取第2个工作表
Worksheet sheet = wb.getWorksheets().get(1);
//调用方法保存为PDF格式
sheet.saveToPdf("ToPDF2.pdf");
}
}