undefined
Blog > Knowledge > Post

3 Methods on How to Export HTML Table to Excel

Friday, September 30, 2022

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 into Excel easily for such analysis.

 

 

Copy HTML Table to Excel/CVS Without Any Coding

One of the easiest ways to export an HTML table into Excel is to use Octoparse. It is one of the best web scraping tools, which is used to extract data from web pages without any coding skills asked. You can set up the whole scraper easily using its point-and-click interface. Also, it provides advanced functions like pagination, loop, scheduled scraping, IP rotation, etc.

 

scrape html table to excel with Octoparse

 

Steps to convert HTML table to Excel with Octoparse

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.

 

 

Step 1: Copy and paste the table page link to Octoparse

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 be scraped

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.

 

Step 3: Run the news scraper and export

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.

 

Export HTML tables to Excel using JavaScript

You can also use Javascript code to export the HTML table into Excel.

<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.

 

So if you want to export any HTML table to Excel Sheets then you can use 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 using Excel "Get data from Web" feature.

 

Related Resources

4 Ways to Scrape Data from a Table

Extract and Monitor Stock Prices from Yahoo Finance

A Full Guide on Scraping Yahoo Finance

6 Tips to Extract Content from Web Page

We use cookies to enhance your browsing experience. Read about how we use cookies and how you can control them by clicking cookie settings. If you continue to use this site, you consent to our use of cookies.
Accept decline