How to convert an Excel file to HTML and JSON with DHTMLX open-source tools

| Leave a comment

While working on the latest releases of dhtmlxSpreadsheet, our development team created three new tools, which assisted us in converting Excel data into the JSON format (and vice versa) and generating HTML tables from Excel files. We didn’t think long and made these tools open-source and available to everyone. So, what are these three libraries and how do they work?

Based on WebAssembly and Rust

All three libraries were developed using the WebAssembly standard and Rust programming language. These technologies contribute to highly reliable code and fast performance. There are no vulnerabilities in the process of conversion, and you don’t have to worry about the safety of your data while it’s being processed. The small size of code allows you to perform the operations extremely quickly. Thus, you can use our open-source tools in your projects to maintain high-speed and secure websites and web apps.

Turning your Excel data into JSON and back

The first two open-source libraries enable you to transform the data kept in your Excel files into the JSON format and back from JSON to Excel. You can find a detailed description and instructions on GitHub:

You can install the libraries in two ways: via npm or cdn. After the data conversion, you’ll have both data and styles saved in Excel or JSON.

One of the most common use cases, when you might need to convert Excel into JSON and vice versa, is embedding your Excel sheets into a web-based spreadsheet. For example, our JavaScript spreadsheet makes use of the Excel2Json and Json2Excel libraries to provide end users with the ability to import and export Excel files. The spreadsheet has a set of features for further styling and formatting data to achieve the desired appearance.

Displaying Excel data as HTML tables

The third open-source tool Excel2Table was built on the basis of the Excel2Json library, which parses Excel files. The data is rendered as an HTML table preserving all the styles from Excel sheets.

Using the Excel2Table is very straightforward and simple:

1. The first step is to run the following command line to install the library:

npm i excel2table

2. Then import the library into your project:

import "excel2table";

3. And all that is left is to call the render function:

excel2table.render(html_container, data, config);

You can find all the parameters of this function and other technical details described in our GitHub repository.

As a result, you’ll have a precise HTML version of your Excel sheet:
Convert Excel to HTML

Generating such HTML tables comes in useful if you need to equip your app with a preview feature like an Excel file viewer. Or you may link an Excel file to a particular HTML table on your website and update your webpage with the table dynamically when something has changed in Excel sheets. It reduces the amount of manual work on website administration and helps you keep important information up-to-the-minute. Additionally, you can always style your HTML table in accordance to your webpage design to unify their look and feel.

All the three libraries are distributed under the MIT license, which allows you to use them both in non-commercial and commercial projects. If you have any questions regarding the usage of these libraries, please refer them to our team.

We’ll be looking forward to your feedback!

Leave a Reply