简体   繁体   中英

Google Apps Script how to copy a table from a sheet to a docs as if you manually copy-pasted it

I can't seem to find the correct function to do that. I see that I can use appendTable(range.getValues()) to copy the values but I lose the formatting doing so and since I also have some =hyperlink() in the values they also get lost. What I would like to have is a function that does exactly what a manual copy-paste does.

Does anyone know if such function exists?

Thanks!

You could use the getHtmlTable() function from this answer , and adapt it to build a Google Doc Table instead of HTML. Where the HTML table has the spreadsheet tableFormat() attributes turned into HTML style tags, you'd want TableCell.setAttribute() (and other setX things) used to make the table match the source spreadsheet as much as possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM