📌  相关文章
📜  使用谷歌脚本合并表格中的单元格 - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:59.742000             🧑  作者: Mango

代码示例1
function mergeCellsExample() {
  //We can use an array of arrays to populate our table.
  var cells = [
    ['First cell', 'Second cell'],
    ['First cell second row', 'Second cell second row']
  ];

  //Creates an example document in your Google Drive Root Folder.
  //It will be titled "Cell merge example"
  var table = DocumentApp.create('Cell merge example').getBody().appendTable(cells);

  // Get the first row in the table.
  var row = table.getRow(0);

  // Get the two cells this row.
  var cell1 = row.getCell(0);
  var cell2 = row.getCell(1);

  // Check the contents of cells 1 and 2
  Logger.log('Cell1 contents: %s', cell1.getText());
  Logger.log('Cell2 contents: %s', cell2.getText());

  // TableCell.merge() merges the current cell into its preceding sibling element.
  var merged = cell2.merge();  
  Logger.log('Merged cell contents: %s', merged.getText());

  // Cell1 and merged are the same cell
  Logger.log('Cell1 == Merged cell: %s', cell1.getText() == merged.getText());
  // Cell2 no longer exists
  Logger.log('Cell2 contents: %s', cell2.getText());
}