I want to embed a Google spreadsheet without the header and footer. This post shows the trick, but doesn’t say how to apply it. I tried this, but it doesn’t work:
<iframe id="embeddedthing" width='500' height='300' frameborder='0' src='https://docs.google.com/spreadsheet/pub?key=<DocId>&single=true&gid=12&output=html&widget=false&gridlines=false'></iframe>
<script type="text/javascript">
var f = function(id) {document.getElementById(id).style.display = "none";};
f("header");
f("footer");
</script>
Then I thought I should apply it to the document loaded in the iframe, so I tried to access it using document.getElementById('FrameId').contentWindow.document, but the browser says “Unsafe JavaScript attempt to access frame” and doesn’t allow me to continue.
What is the correct way to run that JavaScript function?
The easiest way to remove headers and footers from a shared Google sheet in an iframe is to specify the sheet and the range to show.
With the following syntax a sheet appears nice and clean, with the exception of a thin gray border on the top and left edge:
src="https://docs.google.com/spreadsheet/pub?key=<DocID>&gid=<SheetID>&gridlines=false&range=A1:Z100"Without the
rangeparameter the behavior is affected by thewidget=trueto show a header row on top orwidget=falseto show headers, footers and links to the other sheets.If the specified
rangeis larger than the actual sheet size, the whole sheet is used. Sorange=A1:Z100will cover most cases with small tables.Creating two adjacent iframes allows to do something similar to the frozen column or row headers.
Here is an example of a page that uses this technique to display 2 fixed columns with the headers on the left and a scrollable area on the right:
This is the website that uses this technique.
EDIT
Google has changed something and my website is suddenly broken.
The solution as suggested here is to add
&widget=false&chrome=false.