【问题标题】:Problem with RTL in Google Docs preview in androidandroid中Google Docs预览中的RTL问题
【发布时间】:2019-05-01 17:06:35
【问题描述】:

当我尝试在 Google Docs 中从右到左制作文本时,当有人没有登录时,它在每个 android 浏览器中的预览都不好。我的意思是 Android 浏览器仍然以从左到右的格式显示它。 当然登录后,或者使用谷歌文档安卓应用时,就没有这个问题了。 是否有解决此问题的方法,例如使用 Google Apps 脚本等?

我尝试了一些朋友建议的这段代码,但它不能正常工作!

function makeRight(){
    var body =DocumentApp.getActiveDocument().getBody();
    console.log("HERE BM!")
    //var paraghraphs = DocumentApp.getActiveDocument().getBody().findElement(DocumentApp.ElementType.PARAGRAPH);
    for (var i = 0; i < body.length; i++){
        var ithchild = body.getChild(i)
        if (ithchild.getType() == DocumentApp.ElementType.PARAGRAPH){
            ithchild.setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
        }
    }
}

【问题讨论】:

    标签: android google-apps-script


    【解决方案1】:

    看起来您正在尝试在 body.length 上运行 for 语句,但这不会返回数字,因此 for 语句甚至没有运行。

    我获取了您的代码并进行了一些更改,然后在我自己的 Google Doc 上进行了测试,以下代码似乎可以按您的预期工作。

    function makeRight() {
      var body = DocumentApp.getActiveDocument().getBody();
      var numChildren = body.getNumChildren(); //gets number of children for body
    
      //for each child of body, run the below code
      for (var i = 0; i < numChildren; i++) {
        var ithchild = body.getChild(i).asParagraph();
        if (ithchild.getType() == DocumentApp.ElementType.PARAGRAPH) {
          ithchild.setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
        }
      }
    }
    

    我没有尝试运行“body.length”的代码,而是定义了“numChildren”,它获取整个文档的子项数量并将其作为整数返回:

    var numChildren = body.getNumChildren(); //gets number of children for body
    

    您还需要将变量“ithchild”作为段落获取,这就是我将 asParagraph() 添加到该行的原因:

    var ithchild = body.getChild(i).asParagraph();
    

    这可以用来在整个文档上运行你的 for 语句:

    for (var i = 0; i < numChildren; i++) {
    

    【讨论】:

    • 谢谢,成功了!我的意思是当我运行代码时,文档文本在 Android 浏览器上看起来是右(从右到左),但在 PC 浏览器上是从左到右!!!这两个平台,在相反的方向显示相同的文本!换句话说,Android 浏览器显示一个从右到左指向右对齐的文本,左对齐!!!有解决办法吗?
    • 不确定您要解释什么,您能否截取一些屏幕截图比较两者并将其添加到您的帖子中以获取更多信息?
    • 谢谢,试试this document 中的解决方案,看看它是否能解决您的问题。
    猜你喜欢
    • 2018-01-30
    • 2018-06-01
    • 2022-11-12
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多