excel to jpg

Convert Excel to JPG in Java

Excel workbooks are one of the primary file formats used for data entry, organize data, conduct financial analysis, time management, task management etc. However, if we need to display an excel worksheet in webpage, it might not be possible without the help of any plugin/extension. However, if we convert Excel to JPG image, then we can easily display the image in a web browser. So in this article, we are going to learn the steps to develop Excel to JPG Converter using REST API.

Excel to Image Conversion API

We are going to use Aspose.Cells Cloud SDK for Java that provides the capabilities to create, edit as well as convert Excel to PDF, Excel to JPG, Excel to HTML, and various other formats. Now in order to use the SDK, we need to add following details in pom.xml of the maven build type project.

        <name>Aspose Java API</name>

Once the SDK reference is added, the next step is to create an account over Aspose Cloud and lookup/create Client ID and Client Secret at Cloud Dashboard.

Convert Excel to JPG in Java

Now lets explore the details on how to convert Excel to JPG using java code snippet. Please note that we are going to read an excel worksheet from local drive and will generate Excel image. In this approach, all the worksheets of input Excel will be converted to JPG image.

  • Create an instance of CellsApi while providing client credentials as input arguments
  • Specify the name of input Excel, resultant format as HTML, and output file name
  • Read Excel file from local storage through File instance
  • Finally, call the method cellsWorkbookPutConvertWorkbook(…) for Excel image conversion operation
excel to JPG file preview

image1:- Excel to JPG Conversion preview

The input Excel workbook used in above example can be downloaded from myDocument.xlsx.

Spreadsheet Picture using cURL Commands

In this section, we are going to discuss the details on how to convert particular worksheet to JPG format. Now in order to initiate the Excel to JPG conversion, we need to generate a JWT access token while executing the following command.

curl -v "https://api.aspose.cloud/connect/token" \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once we have JWT token, we need to execute the following command to convert particular worksheet named “Sheet2” to JPG format. The resultant JPG is returned as response object and can be saved on local drive.

curl -v -X GET "https://api.aspose.cloud/v3.0/cells/myDocument.xlsx/worksheets/Sheet2?format=JPG&verticalResolution=800&horizontalResolution=1024" \ -H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-o  Converted.jpg
spreadsheet to jpg

Image 2:- Single spreadsheet to jpg preview


In this article, we have explored the details on how to convert Excel to JPG using Java code snippets. The API provides the capabilities to perform excel to image conversion as a whole or we can convert selected worksheets inside xls to jpg format. As our SDKs are built under an MIT license, so the complete source code can be downloaded from GitHub.

If case you encounter any issues while using the APIs, please feel free to contact us via the product support forum.

We highly recommend visiting the following links to learn more about: