A Step-by-Step Guide to Embedding Excel in HTML

Author

Reads 1K

Monitor Displaying Computer Application
Credit: pexels.com, Monitor Displaying Computer Application

Embedding Excel in HTML can be a game-changer for presenting data in a web-friendly format. To get started, you'll need to have Excel installed on your computer and a basic understanding of HTML.

First, you'll need to create an Excel file with the data you want to embed. This file will serve as the source for your embedded Excel content.

To begin the embedding process, you'll need to use the OBJECT tag in HTML, which is used to embed objects such as Excel files into a webpage.

Take a look at this: B Tag Html

Loading the Spreadsheet

The first step in embedding Excel in an HTML page is to define the options for the EWA object, such as whether or not a download link should be provided.

These options can include showDownloadButton, showGridlines, showRowColumnHeaders, and showParametersTaskPane, which can be set to false to hide them from the user.

To load the Excel file, the Ewa object is called with the loadEwaAsync method, which takes in the fileToken, the ID of the HTML div where the object will be placed, and the options defined earlier.

Additional reading: Object Html Div Element

Credit: youtube.com, How to Convert Excel to HTML table online?

The loadEwaAsync method is an asynchronous call, meaning it doesn't block the execution of the code, and a callback function is set to be called once the Ewa object is done loading the file.

This callback function, in the example, is called OnChartLoaded, but it can be renamed to any function name as needed.

Customizing the Spreadsheet

Customizing the Spreadsheet is a crucial step in embedding Excel in HTML. You can select which cells to appear on the website by clicking the Select a Range option and dragging the cursor over the cells.

To control the appearance, you can hide or show the spreadsheet's grid lines and headers. You can also specify whether or not you want a download link to appear below the website in the right corner.

If you want readers to be able to interact with the spreadsheet, you can specify which options are enabled in the Interaction section. This includes whether or not they can sort and filter data, or type their own data into cells.

File Token

A woman attentively working on a computer in an office setting, focused on a presentation screen.
Credit: pexels.com, A woman attentively working on a computer in an office setting, focused on a presentation screen.

The file token is a unique identifier for your Skydrive file, and it's a good thing it's not something you need to retype every time. It's embedded in the JavaScript code that you can copy from the embed file dialog on Skydrive.

You can find the file token in the JavaScript code between the JavaScript tags, where it's assigned to a variable. For example, the file token for this article is: SDB4A3FCAC9C7848C9!285/-5430218907388983095/t=0&s=0&v=!AK3ybHnbJCLh5H0.

To make it easier to use, you can define a variable and set its value to the file token. This is done by copying the file token and assigning it to a variable, like this: var fileToken = "SDB4A3FCAC9C7848C9!285/-5430218907388983095/t=0&s=0&v=!AJHqJpkd-Q5axR8";

Customizing the Spreadsheet

To customize the spreadsheet, you'll need to make some adjustments to the code first if it's not the first worksheet in the workbook.

You can choose which cells to display on the website by selecting a range of cells, dragging the cursor over them, and then clicking "Select a Range."

Credit: youtube.com, Customizing Spreadsheets

If you have multiple workbooks or tables in the same file, you can select which one to display by choosing the "Table" option.

To make the spreadsheet look the way you want, you can hide or show the grid lines and headers, and decide whether to include a download link in the corner.

You can also control how readers interact with the spreadsheet, including whether they can sort and filter data or type their own data into cells.

If you do want readers to be able to interact, you can specify a cell for the cursor to start in.

To get a sense of how the spreadsheet will look, use the "Preview" section, which shows you a live preview of the changes you make.

Clicking the "View Actual Size" link opens the spreadsheet in a new tab, where you can see it at its actual size.

Explore further: What Does Html Look like

Content Layout Tag

To customize the spreadsheet, you'll need to understand the Content Layout tag. It's used to create a Content Type with a media element that contains the Excel file.

A Man Looking at a Computer Screen with Data
Credit: pexels.com, A Man Looking at a Computer Screen with Data

The Content Layout tag has two attributes: name and output-sheet-name. The name attribute specifies the media element in the content type that contains the Excel file.

To include sheet names on the page, set the output-sheet-name attribute to true. If you don't include this attribute, the sheet names won't be output.

Related reading: Html Include

Integration with Webpage

To integrate an Excel sheet with your webpage, you can use either HTML iframe or JavaScript embedding. The HTML iframe method allows for easy embedding, but it has a bug that shows white spaces before the table in most browsers. A workaround for this issue is to use the Brave browser.

You can generate the Excel embed code by clicking File → Share → Embed → Generate HTML in OneDrive. This will provide you with a HTML iframe code or a JavaScript code that you can insert into your website. The default HTML iframe code may not work as expected, but you can customize it by changing the wdAllowInteractivity argument to 1, which allows users to input values.

Worth a look: Iframe Html

Credit: youtube.com, Publish/Embed Excel PowerPoint & Word docs to website or a Sway

To use JavaScript embedding, you can specify a custom div id for embedding Excel sheets by changing the wdDivId argument. This allows you to have multiple Excel sheets embedded on the same webpage without any issues. By using JavaScript embedding, you can also respond to events in the Excel file, change values in cells, and update form controls on your web page.

Here is a list of the main differences between HTML iframe and JavaScript embedding:

  • HTML iframe: Easy to embed, but has a bug that shows white spaces before the table in most browsers.
  • JavaScript embedding: Allows for custom div id, multiple Excel sheets on the same webpage, and more advanced functionality.

HTML Requirements

To embed an Excel sheet in HTML, you'll need to meet some basic requirements. The first requirement is that the Excel sheet must be created or uploaded to Microsoft OneDrive.

The Excel sheet can be embedded using either the HTML iframe code or the JavaScript code. Both methods have their own set of requirements. For the HTML iframe code, the width and height of the embedded Excel sheet can be modified by changing the values in the style attribute.

Crop estate agent working with computer in office
Credit: pexels.com, Crop estate agent working with computer in office

However, using the default HTML iframe code can result in an embedded Excel sheet with lots of white spaces before the table, which is a bug from Microsoft. This bug is visible in most browsers except the Brave browser.

To fix this issue, you can use the JavaScript code, which allows for more customization and flexibility. The JavaScript code uses the Microsoft Office Excel JavaScript object model to programmatically insert the Excel Web App into a div.

Loading App

Loading the Excel Web Application is a crucial step in integrating it with your webpage. This is done by attaching an event handler to the page's load event.

You can use either the default HTML code or JavaScript to embed the Excel file. If you choose JavaScript, you can respond to events in the Excel file, change values in cells, update form controls, and more. JavaScript offers a lot of flexibility when it comes to embedding the Excel file.

Here's an interesting read: Html Form Submit Event

Credit: youtube.com, Web App - Load Data From Spreadsheet - Google Apps Script Web App Tutorial - Part 4

To load the Excel Web Application, you need to define the options for the EWA object. This includes settings such as whether to show a download link, gridlines, row and column headers, and the parameters task pane.

The options for the EWA object are defined as follows:

Once the options are defined, you can use the loadEwaAsync function to load the Excel file. This function takes several parameters, including the file token, the div ID where the file will be loaded, and the options object. It also takes a callback function that will be called once the file is loaded.

Related reading: Require Once Html

Copy HTML snippet to webpage

To copy the HTML snippet to your webpage, simply click the "Embeddable Table" button on your Spreadsheet API. This will display a HTML snippet for embedding your spreadsheet.

The HTML snippet will be displayed in a format that can be easily copied and pasted into your webpage. You can then see the live spreadsheet displayed on your webpage, and any updates to the spreadsheet will be reflected on your webpage as well.

Credit: youtube.com, Including HTML Snippets

To embed the spreadsheet, simply copy the HTML snippet and paste it into your webpage. That's it!

Here's a simple step-by-step guide to copying the HTML snippet:

1. Click the "Embeddable Table" button on your Spreadsheet API.

2. Copy the HTML snippet that is displayed.

3. Paste the HTML snippet into your webpage.

That's it! Your spreadsheet will now be embedded in your webpage, and any updates to the spreadsheet will be reflected on your webpage as well.

Expand your knowledge: Multi Step Html Form

Viola Morissette

Assigning Editor

Viola Morissette is a seasoned Assigning Editor with a passion for curating high-quality content. With a keen eye for detail and a knack for identifying emerging trends, she has successfully guided numerous articles to publication. Her expertise spans a wide range of topics, including technology and software tutorials, such as her work on "OneDrive Tutorials," where she expertly assigned and edited pieces that have resonated with readers worldwide.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.