Let's start by creating a function that's going to add a table and this is going to be adding a table
to our document, so we need to identify the and we're using a bound script.
So the body contents are going to be contained within the document up and we're going to get that active
document and then the body object from the active document.
And then within the body itself, we want to spend a table.
So let's first or create an array.
And the way that the tables work is that this is a multidimensional array.
So just as we see with spreadsheets where it's an array within an array and each row is a separate array,
and then the columns are separated out by commas.
So we've got the column one, column two and column three, and then the contents again contained within
each one of the columns.
So I'm just adding in some dummy placeholder data and that's going to be our basic area that we're going
to construct the table from.
So that's the only parameter that the array method or the table method needs.
So we can append a table and then it requires the multidimensional array format for the table structure.
And also, we're going to take the body and clear any existing content from within the body, let's
run ad table.
So the bound script and we constructed the table.
So the format, again, is very similar to what we saw with the spreadsheets.
So and with the spreadsheets, we know we can.
Create table contents, so let's grab this content, we're going to create a brand new spreadsheet and
then we're going to copy the spreadsheet content directly into the dock.
So I'm going to add a few more columns there.
And of course, tables are a whole lot easier to work with within the spreadsheet.
And I'll just call it test data.
So the objective is to take the data that's contained within the spreadsheet and then apply it and added
into the table that we have.
So let's first select the data that's in the spreadsheet and create another function for that.
Get data and we can use this to return the data.
So using the sheet.
And within here, we can use the spreadsheet app, we can open by ID and then we're going to identify
the sheet with the ID, so we're calling it externally, give it an object of ID, a variable name of
ID.
And then from here we want to get all of the sheets so we get the sheet object and then return back,
whatever the first one is.
So we're just going to be using whatever the first sheet is and that's going to return back to the first
spreadsheet.
And in order to get the data where you use the spreadsheet object and we're going to get the data arrange,
so it's going to return back all of the data and then get values in order to get the array of values
and within the logger log.
Let's look at what we have so far for data within the get data function.
So run the data function.
We need to provide permissions because we're connecting to another.
We're getting additional permissions where we're viewing the spreadsheet.
And we see that we get this nice structured data, and this is the same thing that we have within the
array.
So for the array itself, when we create three, we can run a function called get data and this is going
to return back the data from the spreadsheet in an array format.
And all we have to do here is do a return of the data.
So now let's try to run at the table and see what we get for the bound script so we can effectively
bring the table data from the spreadsheet into the dock.
So this is from an external spreadsheet just by going through all of the available data.
The structure is the same and adding two tables.
It's really easy format when you're spending to the table and within the logger log.
Let's return back, Val.
So this is going to be the table object that we just created and this is now a table object.
So for Val, we can use the insert table roll and this is just expecting an index.
And the table row itself is going to be an object that we can then again reference so we can insert
table cells into the role as well as we can set attributes.
So I'm going to be showing you how to do that.
So what happens is that whenever we do the insert table role, it's going to return the table role object
that then we can use within the script and let's assign an object value to this role.
So insert table role and then within a role.
We can insert table cells, and if you want to insert data into the table cells, we need to specify
the data that we want to, as well as the index value of the child.
So within this table, we've got three columns so we can start with the index value of zero and then
one and two and insert some content into our newly created role within the table.
So let's consider that first and then we'll insert in some text.
And insert it within the first index there and you can specify which index value, and that's going
to be where you want to place the.
So add table and we've insert it right here in the top, so let's go ahead and add some more content.
So we already inserted one cell and then we can illustrate which cell we want to add the value to.
So let's try that one more time.
And that way we can add in all of the cells there at the top, or we can also specify which index value
for the road that we want to set them.
And now we're going to set it up for so it's going to pull in all of the data from the spreadsheet and
then add all of the table cell values within the specified rule.
We can also set attributes to the table itself.
So we're going to set attributes of style, selecting the style object that we had worked with in the
earlier lesson.
I'm going to bring it into this project.
So I'm going to just copy and paste the style object that we had before and for the attributes of the
cell, we're just going to drop in the style object and see what happens.
So that provided us and gave us an option to style the content of the role that we've just added, and
so that's how you can add Teda tables with data within the tables, within your Google Docs.