First published on TECHNET on Oct 18, 2018
This post is a contribution from Mustaq Patel, an engineer with the SharePoint Developer Support team
Requirement: In SharePoint online page, how to show excel workbook dynamically using JSLink without O365 Global Suite Navigation bar.
In SharePoint online we can use script or content editor webpart to show the excel workbook in an iframe. The script webpart can also contain jquery code to set the iframe’s src to the excel workbook dynamically using some business logic. Due to cross domain calls, we cannot write jquery or css to hide the global suite bar that Excel office web app loads in the iframe. So how to show excel workbook without global suite bar and still have workbook url set dynamically. This blog post will address this requirement.
We will use Excel Web Access Webpart and list view webpart. We will connect this 2 webparts, so the Excel Web Access Webpart receives the workbook url from list view webpart. We will also be using JSLink to filter items in the listview webpart, there by only files that meet particular criteria shows up in the list view webpart.
Below are the steps to demonstrate the solution:
Create a document library. Create a View Called “MyExcelFileView” and make sure to include “Created By” Field. You can include any other fields in this view. Upload few excel files under different user so “Created By “ field have different user.
Create a webpart page or use any existing wiki page. Edit the Page. Add 2 webparts in same order as below
List View Webpart showing all the files from document library where all workbook are present.
Edit this listview webpart and under Miscellaneous, set the JS Link property as below. If you are referring jquery from cdn, you can change below
~site/SiteAssets/jquery-1.9.1.js | ~site/SiteAssets/POC_ListItemFiltering.js
Set Appearance, layouts etc as per your needs, you can also set what view to show, to not take lot of space on the page. Select View “MyExcelFileView”. You may select any out of box view as well. Just make sure the field “Created By” is also part of the view.
Once jslink works, it will filter and show workbooks for current logged in user.
The Page still in edit mode, add Excel Web Access webpart from Business Data. Edit its properties and make connection as below
click Connections -> Get Workbook Url from -> above list view webpart -> A connection setting popup will load. Select Field Name “Document URL” finish and save the excel webpart.
I have also uncheck both checkboxes in “Title Bar” and Type of ToolBar: “No ToolBar”.
Save the webpart. Save the page and publish, approve if required.
The page should look as below, and you can see the first excel is already being loaded in the excel webpart. If you click that small icon in listview webpart to select another workbook, it will show in the excel webpart.