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. 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. 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. Place Java.inc file in the root folder of the API’s package that you have
downloaded. Run JavaBridge.jar using the below commands in the command prompt:PHP Excel to HTML Conversion API
Usage
- Run example.php from the API’s root folder using the below command:
The following are the steps to convert Excel files to HTML.
- Load the Excel file using the Workbook class.
- Convert Excel to HTML using Workbook->save(string, SaveFormat::HTML) method.
The following code sample shows how to convert an Excel XLSX file to HTML in PHP.
Excel to HTML
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.
- Load the Excel file using the Workbook class.
- Create an object of HtmlSaveOptions class and set options, such as HtmlSaveOptions->setAddTooltipText(true).
- Convert Excel to HTML using Workbook->save(string, HtmlSaveOptions) method.
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
- Convert Excel Files to PDF in PHP
Convert a HTML file to XLSX in PHP
PUT
//api.aspose.cloud/v3.0/cells/convert
Converting file formats from HTML to XLSX is a complex task. All HTML to XLSX format transitions is performed by our PHP SDK while maintaining the source HTML spreadsheet's main structural and logical content. Our PHP library is a professional solution to convert HTML to XLSX files online. This Cloud SDK gives PHP developers powerful functionality and perfect XLSX output.
Code example in PHP using REST API to convert HTML to XLSX format
// For complete examples and data files, please go to //github.com/aspose-cells-cloud/aspose-cells-cloud-php/ <?php require_once('vendor\autoload.php'); use \Aspose\Cells\Cloud\Api\CellsApi; $instance = new CellsApi(getenv("ProductClientId"),getenv("ProductClientSecret")); $path ='Book1.html'; $format ='xlsx'; $password = null; $outPath = null; $result = $this->instance->cellsWorkbookPutConvertWorkBook($path ,$format, $password, $outPath); $size = $result->getSize(); $content = $result->fread($size); $file = fopen("destfile.xlsx", 'w'); fwrite($file,$content); fclose($file);
- Create an account at Dashboard to get free API quota & authorization details
- Initialize CellsApi with Client Id, Client Secret, Base URL & API version
- Call cellsWorkbookPutConvertWorkBook method to get the resultant stream
System Requirements
- PHP 7.4 or newer