Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert Excel Spreadsheet to PDF in Java
/*
* Convert the specified Cell Range of specified Excel sheets to PDF format in Java
*/
// Prepare Load options and Range for the source XLSX file
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.setConvertRange("A1:C20");
Converter converter = new Converter("path/spreadsheet.xlsx", loadOptions);
PdfConvertOptions convertOptions = new PdfConvertOptions();
convertOptions.setPageNumber(1);
convertOptions.setPagesCount(1);
converter.convert("path/convert-cell-range.pdf", convertOptions);
/*
* Convert all the Excel sheets to PDF format in Java
*/
Converter converter = new Converter("path/spreadsheet.xlsx");
converter.convert("path/all-sheets-converted.pdf", new PdfConvertOptions());
/*
* Convert sequence of Excel sheets to PDF format in Java
*/
Converter converter = new Converter("path/spreadsheet.xlsx");
PdfConvertOptions convertOptions = new PdfConvertOptions();
convertOptions.setPageNumber(1);
convertOptions.setPagesCount(2);
converter.convert("path/sequential-conversion.pdf", convertOptions);
/*
* Convert the specified list of Excel sheets to PDF format in Java
*/
Converter converter = new Converter("path/spreadsheet.xlsx");
PdfConvertOptions convertOptions = new PdfConvertOptions();
convertOptions.setPages(Arrays.asList(1,3));
converter.convert("path/specific-sheets-conversion.pdf", convertOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment