In various cases, you may need to share the Excel files over the internet. To avoid tampering, it is a best practice to convert these files to PDF format before sharing. Accordingly, in this article, you will learn how to convert Excel XLSX or XLS files to PDF in Android apps. In addition, customization of Excel to PDF conversion will also be discussed.
- Android Library for Excel to PDF Conversion
- Convert Excel XLSX or XLS to PDF
- Excel to PDF with Additional Options
- Get a Free API License
Android Excel to PDF Converter Library
To convert Excel spreadsheets to PDF, we’ll use Aspose.Cells for Android via Java. It is a feature-rich Android library that lets you create, modify and convert Excel XLSX/XLS files seamlessly. You can either download the library or install it using the following configurations in build.gradle.
maven {
url "https://repository.aspose.com/repo/" }
compile (
group: 'com.aspose',
name: 'aspose-cells',
version: '21.3',
classifier: 'android.via.java')
Convert Excel XLSX or XLS to PDF in Android
The following are the steps to convert an Excel XLSX file to PDF in Android.
- Create an object of the Workbook class and initialize it with the path to the Excel file.
- Save the Excel file as a PDF using Workbook.save(String, SaveFormat) method.
The following code sample shows how to convert an XLSX file to PDF in Android.
Android Excel to PDF with Additional Options
You can also control the Excel to PDF conversion to customize the converted PDF as required. For example, you can define the PDF compliance, pages per sheet, gridlines style, a range of sheets to convert, etc. To achieve this, Aspose.Cells provides PdfSaveOptions class. The following are the steps of how to customize the XLSX/XLS to PDF conversion.
- Load the Excel file using the Workbook class.
- Create an instance of the PdfSaveOptions class.
- Set the desired option such as PDF compliance using PdfSaveoptions.setCompliance(PdfCompliance) method.
- Save the Excel file as a PDF using Workbook.save(String, PdfSaveOptions) method.
The following code sample shows how to customize Excel to PDF conversion in Android.
Get a Free API License
You can request a free temporary license to use the API without evaluation limitations.
Conclusion
In this article, you have learned how to convert Excel XLSX or XLS files to PDF from within the Android apps. Furthermore, you have seen how to customize the Excel to PDF conversion using different options. You can explore more about Aspose.Cells for Android via Java using the documentation. In case you would have any queries, feel free to let us know via our forum.