logo
languageENdown
menu

3 Methods on How to Export HTML Table to Excel

4 min read

“Can I convert HTML table to Excel?”

Many people have similar questions about how to get the table data downloaded to their local devices into an Excel or CSV file for further analysis. However, the answer is totally YES.

Tables are one of the most common data representation structures on websites. Tables make it simple to visualize large amounts of data in rows and columns and make it easier for comparative analysis. And so websites that need to show a lot of data use a table format.

Hence, you will see tables on websites related to sports, finance, and other niches where large amounts of data need to be shown. This data can be important for research and identifying trends and opportunities.

In this blog post, we will talk about 3 different ways to export HTML tables to Excel easily for such analysis.

Export HTML Table to Excel Without Coding

One of the easiest ways to scrape HTML tables to Excel is to use the best web scraping tool – Octoparse, which is used to extract data from web pages without any coding skills. Octoparse provides an automatic scraping process, or you can set up the whole scraper manually using its point-and-click interface. Also, it provides advanced functions like pagination, loop, scheduled scraping, IP rotation, etc. With it, you can easily get the HTML tables into Excel files.

scrape html table to excel with Octoparse

3 Steps to convert HTML table to Excel/CSV

You can easily export HTML tables into Excel or CSV format using Octoparse in the following simple steps. Or, you can watch the video guide to help you understand the whole table data scraping process much better.

Download Octoparse and open it on your device. Then paste the URL that you want to get the data from in the search field in the Octoparse home section.

Step 2: Select the table that needs to scrape

Start auto-detecting by clicking the Start button. Create a workflow and check the scraped data fields in the preview section. Make changes with the tips it gives if you need them.

Step 3: Run the table scraper and export the data

After selecting the table that needs to be exported, click on the Run button to start getting the table data. The extracted data can be exported in formats like CSV, Excel, or JSON. If you want to export directly to a database, you can do that too.

Import HTML Table to Excel Directly

You can also use Excel’s “Get data from Web” feature to directly import the HTML table into Excel. You can follow the below steps to directly import HTML tables into Excel.

Step 1: Open the Excel file into which you want to import the table. Then in the ribbon, at the top, click on Data.

Step 2: Then click on the ‘From Web’ option. Enter the URL from where you want to import the table from.

Step 3: In the ‘Navigator Section’, select the table that you want to import and click ‘Transform Data’.

Step 4: Finally, click on Close and Load and the data from the table will be loaded into the Excel sheet.

Copy HTML Tables to Excel using JavaScript

You can also use Javascript code to export the HTML table into Excel. This method is available for those who have some coding knowledge, and you can try the following steps and coding lines for reference.

<button id="btnExport" onclick="exportReportToExcel(this)">Export HTML Table</button>

<script type="text/javascript">
function exportReportToExcel() {
let table = document.getElementsByID("table");
TableToExcel.convert(table[0], {
name: `file.xlsx`,
sheet: {
name: 'Sheet 1'
}
});
}
</script>

The above code creates a button to export HTML to a table. You can also read more about it from here.

First, we get the table by using the getElementsByID() function. Then, once we get the table from the page, we will use the library TableToExcel and convert it into Excel format.

We will then define the names of the Excel file and Excel sheet after that. In the above example, “file.xlsx” is the name of the file, and the name of the sheet is “Sheet 1”. You can change these values to change the name.

However, if you are not into coding, then you can use the above two methods, with which you can easily export the HTML table into Excel format.

Final Words

So if you want to export any HTML table to Excel Sheets, then you can use any one of the above three methods. If you know how to code, you can use the JavaScript method to extract the HTML table data, or else you can use Octoparse or directly import the data into Excel with its auto-detecting or the preset templates features. What’s more, you can explore more ways to scrape data from a table.

Hot posts

Explore topics

image
Get web automation tips right into your inbox
Subscribe to get Octoparse monthly newsletters about web scraping solutions, product updates, etc.

Get started with Octoparse today

Download

Related Articles