In various cases, you may need to share Excel files over the Internet. To avoid tampering, it is best practice to convert these files to PDF format before sharing them. So, in this article, you’ll learn how to convert Excel XLSX or XLS files to PDF in an Android application. Customizing the Excel to PDF conversion will also be discussed.

  • Convert Excel XLSX or XLS to PDF
  • Convert from Excel to PDF with other options

To convert Excel spreadsheets to PDF, we’ll use Aspose.Cells for Android via Java, a features-rich Android library that lets you seamlessly create, modify, and convert Excel XLSX/XLS files. You can use it by clicking on the button below. Aspose.Cells for Python via Java

Convert Excel XLSX or XLS to PDF on Android

Here are the steps to convert Excel XLSX files to PDF on Android.

  1. Create an object of the Workbook class and initialize it using the path to an Excel file.
  2. Save the Excel file as a PDF using the workbook.save (String, SaveFormat) method.

The following code example shows how to convert an XLSX file to a PDF on Android.

// Create Workbook to load Excel file
Workbook workbook = new Workbook("Book1.xlsx");

// Save the document in PDF format
workbook.save("Excel-to-PDF.pdf", SaveFormat.PDF);
Copy the code

Convert Android Excel to PDF with additional options

You can also control the Excel to PDF conversion to customize the converted PDF as needed. For example, you can define PDF compliance, number of pages per paper, gridline style, scope of drawings to convert, and so on. To do this, Aspose.Cells provides the PdfSaveOptions class. Here are the steps for customizing the XLSX/XLS to PDF conversion.

  1. Use the Workbook class to load Excel files.
  2. Create an instance of the PdfSaveOptions class.
  3. Using PdfSaveoptions. SetCompliance (PdfCompliance) method to set the required options, such as PDF compatible.
  4. Save the Excel file as a PDF using the workbook.save (String, PdfSaveOptions) method.

The following code example shows how to customize Excel to PDF conversion in Android.

// Create Workbook to load Excel file
Workbook workbook = new Workbook("Book1.xlsx");

// Create PDF options
PdfSaveOptions options = new PdfSaveOptions();
options.setCompliance(PdfCompliance.PDF_A_1_A);

// Save the document in PDF format
workbook.save("Excel-to-PDF.pdf", options);
Copy the code

If you have any questions or requirements, please feel free to join the Aspose Technology Exchange Group (761297826), we are happy to provide you with inquiries and consultation.