I want to insert an embedded Google Sheets table into a Google Doc via the Google Doc API. I had hoped that I could do this via an EmbeddedObject. The definition of EmbeddedObject includes a field for LinkedContentReference, but despite the generic name, a LinkedContentReference object seems to refer only to a Sheets chart.
Is there a way to embed a Sheets table in a Google Doc via API?
I did notice that Google Sheets offers a Table Chart as a chart type. This may be an effective workaround.
You need to insert the sheet table as an inline image
An InlineObject contains an EmbeddedObject such as an image.
Now, when you publish a Google Sheets, you have the option to publish it as pdf, but not image. This mean that you would need to perform an additional step of converting the pdf into a supported image format.
Alternatively you can obtain (and save on your Drive) the Sheet as a thumbNail by performing a Files: get request on the Sheet and setting fields to thumbnailLink. Mind that the thumbNail contians the whole sheet view - not only the data range.
Important:
When performing a documents.batchUpdate request InsertInlineImageRequest, you need to specify the uri in the format
https://docs.google.com/uc?export=view&id=PASTE_HERE_YOUR_ID
Related
I have a Google Sheets file I use to enter data on different properties.
Each row in this file represents a single property.
If a certain property is of interest, I would like generate a report for it.
I need a functionality that will extract all data fields from a single row, and insert them in a new file (google sheets or preferably a Google Docs file) with a pre built format that would present the data nicely like a report.
Thanking you in advance
Avi
Here is a very preliminary answer, to see if this is the right direction.
See my sample sheet.
This lets you select, in C3, which address you want a report on. The fields shown in green change as you select a different address. All of the report fields could be modified like this - you just need to point to which column in the Properties database contains the values.
Is this roughly what you were looking to achieve?
I have created a Google Sheet add-on that includes a bunch of Google Apps Scripts plus a bunch of formatting over a number of sheets (tabs). When I publish this to the G Suite Marketplace, will that formatting of the sheets (tabs) be included? For example, I have entered column headers, styled the text (colour, font etc). The formatting and text instructs the user where to enter the needed data that allows the add-on to function.
I have searched through the documentation and other Stackoverflow questions, but have not found a response.
The published Google Sheets add-ons doesn't include a copy of the spreadsheet. To include them you could make that your add-on creates a copy of the spreadsheet that includes the formatted sheets or you could publish that spreadsheet as a template.
Reference
Create a file from template
Look at the Create a template with an add-on section
I have found an answer. #Rubén was likely referring to this solution.
To accomplish this, follow these steps.
Create your spreadsheet with associated formatting, text, colours etc.
Go into Share settings and share the spreadsheet with the option Anyone who has the link can view
Then grab the ID of the spreadsheet within the URL (ex. https://docs.google.com/spreadsheets/d/ID_IS_HERE/edit#gid=0)
To copy that spreadsheet use the following code in your add-on.
function importSheet() {
var ss = SpreadsheetApp.openById("sheet ID goes here");
var sheetToCopy = ss.getSheets()[0]; //gets the first sheet
var destination = SpreadsheetApp.getActiveSpreadsheet();
sheetToCopy.copyTo(destination);
}
If your source spreadsheet has multiple sheets, you can get the number of sheets using var number = ss.getSheets().length; then loop through the above code using number to copy each individual sheet.
Regarding the source spreadsheet, Google provides the following detail
// Note that the spreadsheet is NOT physically opened on the client side.
// It is opened on the server only (for modification by the script).
I hope this helps someone else.
I have a main sheet in witch I copy it and create different versions, kind of like simulating different results.
But every time I want to change something in the main sheet, I have to go in all the other sheets I created and changed.
I don't know if it is possible, but the best way for me would be to create a formula like this:
copyFormula(Sheet1!V2) -> And bringed the exactly same result as if I had gone to Sheet1 copied V2 and pasted it this cell.
I tried to create this formula but failed consistently.
Thanks!!
What you need to do is to manipulate the properties of the sheets.
Here is a reference where you can create those actions.
The Sheets API allows you to create sheets, delete sheets, and control
their properties. The examples on this page illustrate how some common
sheet operations can be achieved with the API.
In these examples, the placeholders spreadsheetId and sheetId are
used to indicate where you would provide those IDs. The spreadsheet
ID can be discovered from the spreadsheet URL; the sheet ID can be
obtained from the spreadsheet.get method.
You can refer to this documentation on how you can read the formula you are needing in the entire sheets.
The Sheets API allows you to read values from cells, ranges, sets of
ranges and entire sheets. The examples on this page illustrate how
some common read operations can be achieved with the
spreadsheets.values collection of this API. You can also read
cell values using the spreadsheets.get method, but in most cases
using spreadsheets.values.get or
spreadsheets.values.batchGet is easier to use.
I want to retrieve only sheet's data from a spreadsheet with formatting.
How to achieve the same with Sheets Api?
It isn't clear from your question just what kind of data you want to get. Do you want to retrieve the values as they're formatted in the Google Sheets UI? If so, then use the spreadsheets.values.get API. The parameter valueRenderOption controls how the values are formatted. By default, the value is FORMATTED_VALUE, which will return the data as it's formatted in the Sheets UI. Other values are listed on the ValueRenderOption reference page. See the Basic Reading sample for more information.
If you want to retrieve the information about the format itself, use the spreadsheets.get API. Format information is in the response's CellData (at sheets.data.rowData.values), in both the userEnteredFormat and effectiveFormat fields.
I know how to query data from google spreadsheet with the general share link, but I want to pull data from specific tabs in that shared workbook. How do I do this?
It is not clear from your question how you are querying a spreadsheet (there are several ways to do it).
If you are using spreadsheet data source url (e.g: https://docs.google.com/spreadsheets/d/{ss_key}/gviz/tq?tq=...), then you can add gid or sheet url parameters to specify which sheet in the spreadsheet to query by its id or name:
https://docs.google.com/spreadsheets/d/{ss_key}/gviz/tq?gid=0&tq=...
https://docs.google.com/spreadsheets/d/{ss_key}/gviz/tq?sheet=Sheet1&tq=...
You can get the gid number of a sheet from the spreadsheet's url when it is open in your browser. More info here: https://developers.google.com/chart/interactive/docs/spreadsheets#Google_Spreadsheets_as_a_Data_Source
Note: data source url examples above are for new google sheets. If you are still using old sheets, the url format will be different: http://spreadsheets.google.com/a/google.com/tq?key=ABCDE&tq=.... The documentation link above still uses old sheets url format.
If you are querying your spreadsheet via QUERY() formula in another sheet, then just specify the name of the sheet you want to query in the data attribute of the function:
=QUERY('Example Data'!$A$2:$H$7, "select A where (B<>'Eng' and G=true) or (D > "&A2&")")