As I'm trying to format google doc tables and in reference to this thread I was able to add some formatting to the header row, to the table data and was able to create a doc in a landscape layout.

However, I still didn't find a solution to:

Making all the table cells to be RTL (it seems like I can only RTL paragraphs)

Here is the code I have so far

function createDoc() {
  var ssUrl = 'https://docs.google.com/spreadsheets/d/1ZWbAOdOfRSJtrfmLWjX6Q6cPT-YztII_uVdsBzWcQ_I/edit#gid=1116846206';
  var sheetName = 'paycall';   // name of sheet to use

   var values = SpreadsheetApp.openByUrl(ssUrl)

  var doc = DocumentApp.create('Sample Document 1');
  var body = doc.getBody();

  var tableStyle = {}; 
   tableStyle[DocumentApp.Attribute.FONT_SIZE] = 10; 

  var rowsData = values;
  body.insertParagraph(0, doc.getName())
  table = body.appendTable(rowsData).setAttributes(tableStyle);


1 Answer 1


Based on https://developers.google.com/apps-script/reference/document, there are only two methods to set text direction RTL, one for Class List and another for Class Paragraph. Consider to use one of them to set the text direction to RTL.

Here is a code snippet taken from the answer to Setting Text Direction in Google Scripts

function table(){
  Code: var cells = [ ["EnglishTitle", "HebrewTitle"], ["Text", ""] ]; 
  var tableStyle = {}; 
  tableStyle[DocumentApp.Attribute.FONT_FAMILY] = DocumentApp.FontFamily.TIMES_NEW_ROMAN;
  tableStyle[DocumentApp.Attribute.FONT_SIZE] = 12; 
  var doc = DocumentApp.getActiveDocument().getBody();
  doc.appendTable(cells).setAttributes(tableStyle).getCell(1,1).insertParagraph(0, "Top line not moved. \nText Should Be Right to left, but it's not, \nThis text is correctly on the right.").setLeftToRight(false).appendText('\nThis is the appended text,\ncorrectly set right to left.');
  • It looks like this code good for setting up a specific cell to RTL, but not for the whole table. So, if there's a table with 100 cells, I'm not if this code would do the work Feb 24, 2020 at 11:17
  • @AzrielLider You could use a loop to iterate over all the cells.
    – Rubén
    Feb 24, 2020 at 12:50
  • that does make sense. There is still an issue with un-needed spaces in the cells that are added due to using "insertParagraph" . I think that could be solved here. Hope I'm on the right track... Feb 24, 2020 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.