With Google Sheets I created a calculation table which I want to copy to a quote template in Google Docs with Google Apps Script. For this I use the solution found here in this question: Using Google Apps Script to Copy from Google Sheets Data Table to Google Documents Table.
I use (literally exactly) the first sample script, without taking care of column width, as this is not an issue for me.
The copying works great, but I still have a few problems:
- all the cell values are copied as text, so in the Google Docs table I have to reformat some values in Euro
- in the Google Docs table all the cells are left aligned, I need to right align the columns with Euro values
- the script uses "body.appendTable(values)" to insert table data at the end of the document, but how can I determine where in the document I want to place the table?
- once created the new document from the template I would like to open it directly in the browser
My script is bound to the Google Sheet document, where I start the script from a custom menu.
You can see the calculation sheet here and the template here.
Hope to find someone who can help.
EDIT to answer questions from comments:
Hey J.G., maybe the problem wasn't explained well enough or I am not smart enough to handle the solutions you proposed:
setNumberFormat()
worked for me only on a spreadsheet, but I have to format the table in Google Docs document.
With theinsertTable(childIndex, table)
I was able to insert the table only at the beginning or the end of the document. What am I missing?OK, it places the table on line 5 in this case, tried also many other indexes and was able to come to the position I want it to be. But this is not reliable enough for me, because if the template changes (and it will change!) I have to find the right index again and change the script. Or is there a possibility to search for a keyword in the doc and get it's childIndex via script?