參考代碼:
import com.spire.xls.*;
public class ExceltoPDF {
public static void main(String[] args) {
//載入一個Excel文檔
Workbook workbook = new Workbook();
workbook.loadFromFile("Sample.xlsx");
//設置轉換時,工作表自適應PDF頁面
workbook.getConverterSetting().setSheetFitToPage(true);
//將Excel保存為PDF
workbook.saveToFile("ToPDF.pdf",FileFormat.PDF);
}
}