Convert Excel Files to HTML in PHP

PHP Excel to HTML

In order to embed Excel spreadsheets within your web pages, you need to convert them into either images or HTML content. Since HTML is more suitable for websites, therefore, this article covers how to convert Excel XLSX or XLS files to HTML pages in PHP.

PHP Excel to HTML Conversion API

In order to convert Excel XLSX or XLS files to HTML, we will use Aspose.Cells for PHP via Java. The API provides a wide range of spreadsheet automation features for PHP based web applications. You can download the API’s package from here.

Usage

The following are the prerequisites that you need to fulfill in order to use Aspose.Cells for PHP via Java.

Once you have completed the prerequisites, follow the below steps to execute the example.php file for testing.

1. Place Java.inc file in the root folder of the API’s package that you have downloaded.

2. Run JavaBridge.jar using the below commands in the command prompt:

> cd aspose.cells
> %JAVA_HOME%\bin\java -Djava.ext.dirs=lib -jar JavaBridge.jar SERVLET_LOCAL:8080

3. Run example.php from the API’s root folder using the below command:

> php example.php

Convert Excel Files to HTML in PHP

The following are the steps to convert Excel files to HTML.

The following code sample shows how to convert an Excel XLSX file to HTML in PHP.

Excel to HTML

Excel to HTML PHP

Excel to HTML – Set Additional Options

Aspose.Cells also allows you to set additional options in Excel to HTML conversion, such as enable tooltip text, show/hide gridlines, etc. To enable or disable these options, HtmlSaveOptions class is used.

The following are the steps to set additional options while converting Excel files to HTML.

The following code sample shows how to set additional options while converting XLSX to HTML in PHP.

Get a Free API License

You can use the API for free without evaluation limitations using a temporary license.

Conclusion

In this article, you have learned how to convert Excel files to HTML using PHP. Furthermore, you have seen how to customize the Excel to HTML conversion. You can explore more about the PHP Excel API using the documentation. In case you would have any questions, feel free to let us know via our forum.

See Also