TransWikia.com

How to Add RTL Tables to a Google Document

Web Applications Asked by Azriel Lider on December 1, 2021

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)
                             .getSheetByName(sheetName)
                             .getDataRange()
                             .getDisplayValues();


  var doc = DocumentApp.create('Sample Document 1');
  var body = doc.getBody();
  body.setPageHeight(595).setPageWidth(842);

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

  var rowsData = values;
  body.insertParagraph(0, doc.getName())
      .setHeading(DocumentApp.ParagraphHeading.HEADING1).setLeftToRight(false);
  table = body.appendTable(rowsData).setAttributes(tableStyle);
  table.getRow(0).editAsText().setFontSize(12).setBold(true).a;


}

One Answer

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.');
}

Answered by Rubén on December 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP