How to Convert Excel to HTML

Converting Excel to HTML opens doors to endless benefits. For instance, it makes embedding your data on a website easy, and many people can view the document using browsers. These two are two easy ways to do it. You can either use Excel software or a Free online HTML converter. In this article, I will guide you step by step on how to convert Excel files to HTML.

What is HTML?

HTML is the markup language of the World Wide Web. It is a standard for describing the structure of web pages and enables tags to be embedded in a document to control the presentation of that document. HTML tags are characters between < and > that identify a document's tags, attributes, and other elements.

Advantages of HTML

  • HTML is free
  • HTML is easy to learn
  • HTML is Easy to Use
  • HTML is supported by all browsers
  • HTML is lightweight and fast to load
  • It is easy to code, even for beginners
  • HTML is user friendly

How to convert Excel to HTML using the Excel application

1. Click on the File in the top left corner

2. Click on Save as

 

 

 

 

 

 

 

 

 

 

 

3. Select your preferred location

4. Click the drop-down menu

5. Select as web page, .html or .htm

6. Click on Save

7. Open the file explorer and view your file

How to convert Excel to HTML using online tools

1. Open Knigtsheets.com Excel to HTML converter

2. Upload and click convert

3. Wait a few seconds for your file to process and download automatically.

How to convert Excel to HTML using PHP

You can convert Excel to HTML using an open-source library known as PHPspreadsheet. Here is how to do it. First, install composer on your PC, which you will use to install the library.

Prerequisites

  • Composer
  • PHPspreadsheet library
  • Server (Local or Live server)

1. Create a new folder and label it exceltohtml inside htdocs

2. Create a new folder inside exceltohtml and label it files (The uploaded files will be moved here temporarily before being processed and deleted)

3. Launch CMD and run this command to install phpspreadsheet library (composer require phpoffice/phpspreadsheet)


4. Create an index file(index.php) and create an upload form (Copy and paste the code below)


<html>
<body>
<?php
<form action="upload.php" enctype="multipart/form-data" method="POST">
<input id="fileToUpload" name="fileToUpload" required="" type="file" value="Select File" />
<button class="btn" name="upload">Upload</button>
</form>
<?PHP
</body>
</html>

5. Create an upload file(Upload.php) (Copy and paste the following code)


<?php
require 'vendor/autoload.php';
if (($_FILES['fileToUpload']['name'] != "")) {
// Where the file is going to be stored
$target_dir = 'files/';
$file = $_FILES['fileToUpload']['name'];
$path = pathinfo($file);
$filename = $path['filename'];
$ext = $path['extension'];
$temp_name = $_FILES['fileToUpload']['tmp_name'];
$path_filename_ext = $target_dir . $filename . "." . $ext;
// Check if file already exists
if (file_exists($path_filename_ext)) {
echo "";
} else {
move_uploaded_file($temp_name, $path_filename_ext);
// echo "Congratulations! File Uploaded Successfully.";
}
}
use \PhpOffice\PhpSpreadsheet\IOFactory;
use \PhpOffice\PhpSpreadsheet\Writer\Html;
//load the uploaded spreadsheet
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load("$path_filename_ext");
//create a new pdf using mdf library
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Html($spreadsheet);
$date = date('d-m-y-' . substr((string)microtime(), 1, 8));
$date = str_replace(".", "", $date);
$newfilename = "export_" . $date . ".html";
try {
$writer->save($newfilename);
$content = file_get_contents($newfilename);
} catch (Exception $e) {
exit($e->getMessage());
}
//make the file downloadable
header("Content-Disposition: attachment; filename=" . $newfilename);
unlink($newfilename);
exit($content);

6. Start the webserver and open the exceltohtml. Viola!
Your excel to HTML converter is ready for use.

Final Thoughts

HTML is the most viewed format in the world. This is because most, if not all, websites feature HTML. Excel is limited to people with only specific software. Converting your Excel to HTML makes it more accessible to anyone accessing a device with a browser. You can use Excel software to convert your file or use a free online converter.