如何在没有这种奇怪结果的情况下合并 Google 文本文档中表格的两个单元格? [英] How to merge the two cells of a table in a Google text Document without this weird result?

查看:16
本文介绍了如何在没有这种奇怪结果的情况下合并 Google 文本文档中表格的两个单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了这个函数(感谢@Mogsdad)来合并文本谷歌文档中表格中的单元格,如下所示:

I've writen this function (thanks, @Mogsdad) to merge cells in a table in a text google document, like this:

function onOpen() {
  // Add a menu with some items, some separators, and a sub-menu.
  DocumentApp.getUi().createMenu('Sample')
      .addItem('merge cells of a table', 'mergeCells')          
      .addToUi();
}



function mergeCells() {
  var body = DocumentApp.getActiveDocument().getBody();
  for (var p= 0; p< body.getNumChildren(); p++) {
    var child = body.getChild(p);
    if (child.getType() == DocumentApp.ElementType.TABLE){
      // Assume we've already located our table
      var table = child;
      var tableRow = table.getChild(2); // gets third row
      var tableCell = tableRow.getChild(1); // gets second cell in row
      tableCell.merge(); // Merges seconde cell with first cell.      
      }
  }
}

但是当我运行代码时,我得到了这个奇怪的结果(与预期的非常不同,合并的单元格具有相同的表格尺寸):

But when I run the code, I got this weird result (very different of the expected, with the merged cell with the same dimensions of the table):

有办法解决吗?(合并相同尺寸的单元格)

Is there a way to fix it? (merged cell with the same dimensions)

推荐答案

[编辑以解决 Google 文档中的更新]

[edit to address updates in Google Docs]

这目前是不可能的.您可以通过查看调用 getColSpan 来了解单元格是否已合并getRowSpan 但有不是 setter 方法.

This currently not possible. You can know if a cell is merged by looking calling getColSpan and getRowSpan but there are no setter methods.

请在以下问题上加星标,以便收到有关此更新的通知.

Please star the following issue to be notified by updates regarding this.

您发现的 merge 功能不是特定于表格单元格,它可以将任何元素与相同类型的前一个兄弟元素合并,加入它们的内容.

The merge function you found is not specific to table cells, it is there to merge any element with a previous sibling of the same type, joining their content.

[原始答案]

如果您希望合并单元格,就像您在电子表格中可以做的那样,那是不可能的.仅仅是因为这在 Google 文档中是不可能的(至少现在还没有).因此,API 无法执行此操作(它只能执行手动也可以执行的操作).

If you were expecting to have a merged cell that, like what you can do in a spreadsheet, that is not possible. Simply because that's not possible in Google Documents (at least not yet). Therefore the API cannot do this (it can only do things that are also possible manually).

merge 功能并非特定于您可能想象的表格单元格.它按设计工作.

This merge function is not specific to table cells as you probably imagined. It is working as designed.

这篇关于如何在没有这种奇怪结果的情况下合并 Google 文本文档中表格的两个单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆