How convert HTML to Xlsx in php?

How convert HTML to Xlsx in php?

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
  • Convert Excel Files to HTML
  • Additional Options in Excel to HTML Conversion

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.

  • Java SE Development Kit 1.7 or higher
  • PHP 7.0 or higher
  • Java Bridge
  • Java Inc

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
  1. Run example.php from the API’s root folder using the below command:
> php example.php

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

How convert HTML to Xlsx in 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.

  • 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

https://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 https://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);


  1. Create an account at Dashboard to get free API quota & authorization details
  2. Initialize CellsApi with Client Id, Client Secret, Base URL & API version
  3. Call cellsWorkbookPutConvertWorkBook method to get the resultant stream

System Requirements


  1. PHP 7.4 or newer

How do I convert an HTML file to Xlsx?

How to convert HTML to XLSX.
Upload html-file(s) Select files from Computer, Google Drive, Dropbox, URL or by dragging it on the page..
Choose "to xlsx" Choose xlsx or any other format you need as a result (more than 200 formats supported).
Download your xlsx..

How do I export data from HTML table to Excel using PHP?

$data['heldcls'] . " <td>". $data['attendcls']." </td>"; } Print "</table><br><br><form action = excel. php method = POST><input type = 'submit' name = 'submit' Value = 'Export to excel'></form></center>"; how do i export this table to excel sheet.

Can I convert an HTML file to Excel?

Cells Excel Conversion. This is a free app to convert Html to Excel format, also you can save the result to PDF, DOCX, PPTX, XLS, XLSX, XLSM, XLSB, XLT, ET, ODS, CSV, TSV, HTML, JPG, BMP, PNG, SVG, TIFF, XPS, JSON, XML, SQL, MHTML and Markdown.

Can I convert HTML to PHP?

Just change file extension . html to . php (index. html to index.