excel to html

How to convert XLS to HTML online in Java.

The era of online communication, the dynamic content is a key to success. Therefore, the need to effortlessly convert Excel data to HTML using Java has become more crucial than ever. Furthermore, this ability to seamlessly translate Excel spreadsheets into HTML is a game-changer. This article delves into the pivotal role that Java Cloud SDK plays in this conversion process, offering insights, techniques, and practical steps to meet the demands of a visually driven online landscape.

REST API for Excel to HTML Conversion

Converting Excel to HTML becomes a seamless and efficient process when using Aspose.Cells Cloud SDK for Java, a powerful toolkit designed to streamline Excel operations in a cloud-based environment. This robust SDK empowers you with a range of features to precisely control the conversion process, ensuring that the resulting HTML mirrors the nuances of the original Excel workbook. So, whether you’re aiming to preserve formatting, enhance interactivity, or create a responsive layout, this SDK offers granular control over various conversion parameters.

Now, in order to use the SDK, please add the following details in pom.xml to add the Cloud SDK reference in your project.

<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>https://repository.aspose.cloud/repo/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-cells-cloud</artifactId>
        <version>24.1.1</version>
    </dependency>
</dependencies>

Obtain your client credentials from cloud dashboard. If you do not have an existing account, simply create a free account by following the instructions specified in the quick start article.

Convert Excel to HTML in Java

As stated above, the Aspose.Cells Cloud SDK for Java can initiate the Excel to HTML conversion through intuitive API calls, providing you with the flexibility and customization options. It delivers dynamic and visually appealing HTML content, ensuring a seamless integration of Excel data into modern web applications and presentations. The following section explains the steps on transforming Excel to HTML in Java.

 CellsApi api = new CellsApi(clientId,clientSecret);

Create an object of CellsApi class where we pass client credentials as arguments.

 cellsInstance.uploadFile("input.xlsx", file, "Internal");

Upload the input Excel workbook to cloud storage.

File response = api.cellsWorkbookGetWorkbook("input.xlsx",  password,format, 
    			            isAutoFit, onlySaveTable, null,"Internal",  "Resultant.html","Internal", null);  

Initiate the Excel to HTML conversion. After successful operation, the resultant HTML is stored in storage named Internal.

excel to html

Excel to HTML conversion preview in Java.

The input Excel workbook and the resultant HTML generated in the above example can be downloaded from:

Please rename the extension of the downloaded HTML file from .hml to .html.

Microsoft Excel Online Conversion to HTML with cURL Commands

Aspose.Cells Cloud provides a versatile cloud-based environment where developers can harness the power of its API to perform various Excel operations, including the transformation of Excel data into HTML. When paired with cURL commands, this process becomes scriptable and adaptable, allowing for easy integration into diverse development environments.

The first step in this approach is to generate a JWT access token using the following command:

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=921363a8-b195-426c-85f7-7d458b112383&client_secret=2bf81fca2f3ca1790e405c904b94d233" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Now, please execute the following command to convert XLS to HTML online. This method expects the input Excel to be already available in cloud storage and after conversion, the resultant HTML is also stored in cloud storage.

>curl -v "https://api.aspose.cloud/v3.0/cells/{inputExcel}?format=HTML&isAutoFit=true&onlySaveTable=false&outPath={outputFile}&checkExcelRestriction=true" \
-X GET \
-H  "accept: application/json" \
-H  "authorization: Bearer {accessToken}"

Replace inputExcel with the name of input Excel workbook available in cloud storage, outputFile with the name of resultant HTML to be generated and accessToken with a JWT access token generated above.

In case we need to save the resultant HTML on local drive, please use the following cURL command.

curl -v "https://api.aspose.cloud/v3.0/cells/{sourceFile}?format=HTML&isAutoFit=true&onlySaveTable=false&checkExcelRestriction=true&pageWideFitOnPerSheet=true&pageTallFitOnPerSheet=true" \
-X GET \
-H  "accept: application/json" \
-H  "authorization: Bearer {accessToken}" \
-o "myOutput.html"

Conclusion

In conclusion, the journey of converting Excel to HTML is marked by two distinct yet complementary approaches. Either you opt for the comprehensive and feature-rich toolkit provided by the SDK or the scriptable efficiency and cross-platform adaptability of cURL commands. However, both approaches converge on the common goal of seamlessly translating Excel data into responsive and visually engaging HTML. Nonetheless, the power of these approaches ensures a reliable and efficient solution, unlocking the full potential of Excel to HTML conversion for developers and users alike.

We highly recommend visiting the following blogs: