Is it possible to embed a Google Spreadsheet into a Google Document à la Microsoft Excel and Microsoft Word? How about a chart from a Spreadsheet?
5 Answers
From today (2016-05-20) on, Google is starting to roll out the ability to embed a chart from a Google spreadsheet into a Google document. At this point, two of my 3 Google accounts make the option available in the Insert
menu, with a new Insert→Chart
submenu below the Insert→Drawing…
item.
When you insert such charts, they remain linked to the original spreadsheet. If all you want is tabular data, there's a table chart type that you can use to present your data as a simple table.
There are some limitations at this stage (e.g. regarding the size of the chart) and the chart must pre-exist in the spreadsheet before you can insert it, but this is going in the right direction…
To insert a spreadsheet or table, use Add a table from Google Sheets by copy-pasting from Sheets to Docs and choose the linked option.
Linking one cell: If you ever try to copy one cell, you find that it is pasted as plaintext (not table) and no prompt is show for choosing "linking". Simple solution is to paste min. 2 cells, then prompt is shown and you can link them from Sheets to Docs. Then you can edit range via "Change Range" to only one cell.
The chart is not updated live if you modify the source spreadsheet while your document is opened, however, the document will detect changes and give you an Update button above the embedded spreadsheet to reflect the latest changes in the source.
-
Does this mean that if the spreadsheet uses a formula or equation that automatically changes (e.g., based on a certain date) it also will not update? Commented Oct 5, 2016 at 17:47
-
I have not tested this, but I'd suspect that you must open your spreadsheet to refresh your chart and then accept to update the chart in the documents that embed it. If you find otherwise, let us all know. Commented Oct 13, 2016 at 9:36
-
1Starting today, one can also embed a table; since your answer is the accepted one, you may want to edit in this new feature.– user135384Commented Jun 2, 2017 at 15:18
-
1Thanks for the information re. direct table embedding. At this stage the feature doesn't seem to work yet in my Google Apps for work account. I will update my post as soon as I notice it does. Commented Jun 9, 2017 at 17:15
-
@Michelle I tried and it doesn't seem possible. I don't see any "Update" button on a table that was copied from a Sheets file.– ADTCCommented Sep 17, 2017 at 18:11
AFAIK, you can only copy and paste from the spreadsheet to the text document. The spreadsheet is inserted as a table, but they are not linked: if you change something in the Spreadsheet, it will not get reflected in the text document.
Of course, I'd absolutely love to be proved wrong!
-
1
-
1See my answer below, there's a new option now that makes this a bit friendlier and provides for dynamic updates. Commented May 20, 2016 at 8:44
Here is a script-based solution which allows one to insert a table with the contents from a given range within a given spreadsheet. I did not try to find a way to sync data real-time, as it didn't seem practical given potentially large volume of data that would have to be transferred with every edit to the spreadsheet. Instead, the script adds a custom menu item "update data" to the document.
The script should be bound to the document (i.e., created using Tools > Script Editor in the document menu). The spreadsheet URL, as well as the sheet and range to use, are specified within the script. To embed all the data on the sheet, replace .getRange(rangeName)
with .getDataRange()
.
When the function updateData is first executed, it appends the table at the end of document. At subsequent runs, it updates the table in place (i.e., if more text is added after the table, the order will be preserved).
Note that cutting-pasting the table would break the updating process (the script would add a new table at the end) since the pasted copy is a new object. Instead, cut-paste the text around the table.
function onOpen() {
DocumentApp.getUi()
.createMenu('Custom')
.addItem('Update Data', 'updateData')
.addToUi();
}
function updateData() {
var ssUrl = ' spreadsheet url here ';
var sheetName = 'Sheet2'; // name of sheet to use
var rangeName = 'A1:C3'; // range of values to include
var values = SpreadsheetApp.openByUrl(ssUrl)
.getSheetByName(sheetName)
.getRange(rangeName)
.getValues();
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var ranges = doc.getNamedRanges('embeddedSheet-range');
if (ranges.length == 0) {
var table = body.appendTable(values);
}
else {
tableRange = ranges[0];
table = tableRange.getRange().getRangeElements()[0].getElement();
var ind = body.getChildIndex(table);
tableRange.remove();
body.removeChild(table);
table = body.insertTable(ind, values);
}
var rangeBuilder = doc.newRange();
rangeBuilder.addElement(table);
doc.addNamedRange('embeddedSheet-range', rangeBuilder.build());
}
Technical notes
It's also possible to sync the data every hour, in addition to manually. Just add a time-based trigger from Script Editor's Resources menu, so that it runs the function updateData.
One can also adapt this script to be bound to the source spreadsheet instead. This would require changes in how the document is opened (e.g., by URL), but otherwise the logic is the same.
The cumbersome part of the script is getting the handle of the existing table in the document. This requires placing it within a Named Range. Also, it is much more expedient to completely replace the table element than to mess with the entries of an existing table. Since a Named Range is immutable, it is also removed with the table it contains, and then created again, along with the new table.
-
Works great. Any way to get formatting (in particular cell background colors)? Commented May 6, 2016 at 15:42
-
NOTE: The 'spreadsheet URL' should apparently contain the full url including the
/edit#gid=0
stuff at the end. Commented May 6, 2016 at 15:43 -
There is no way to import the formatting of another spreadsheet.– user79865Commented May 6, 2016 at 15:55
-
Links also aren't transfering over, neither are colors. Is there any way to modify this script to include all the formatting? Very clever work around to the cut-paste issue, worked like a charm! Commented Jul 2, 2016 at 17:34
Yes, you can. Copy the contents of a sheet and paste it in your doc, in the right corner it will ask if you'd like to link to the spreadsheet. If you do, after you edit the spreadsheet, you can click the update icon in your docs to incorporate the changes to your doc.
-
As of early 2018, this is the best answer for the part of the question concerning inserting a Google Sheet table into a Google Doc.– dlukesCommented Jan 12, 2018 at 13:06
-
And as far as I can tell, the reason I found this thread, is it is limited to 400 cells.– TC76Commented Aug 14, 2019 at 20:01
An alternative is to use Google Sites, or any other content editor that allow embedding iframes content.
To embed Google spreadsheets in a page of Google Sites
- Create a new site or go to an existing site.
- Create a new page or click on Edit on an existing page.
- Click on Insert > Drive > Spreadsheet
- Select the spreadsheet
- Set the options
- Click on Save