Google Sheets 脚本 - 查找单元格中带下划线的文本

问题描述 投票:0回答:1

我需要在单元格中找到带下划线的文本。我知道 TextStyle 类有一个 isUnderlined 布尔函数,但它看起来只适用于 Slide。有谁知道我还能如何找到单元格中带下划线的文本的开始和停止位置?谢谢!

请注意,我没有包含代码,因为我知道为什么这种方法不起作用。只是需要不同的方法!

google-sheets
1个回答
0
投票

这是一种使用谷歌应用程序脚本的方法

function findUnderlinedText() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var range = sheet.getDataRange(); // Get the entire sheet range
  var values = range.getValues(); // Get values of all cells

  // Iterate through each cell in the range
  for (var i = 0; i < values.length; i++) {
    for (var j = 0; j < values[i].length; j++) {
      var cellValue = values[i][j];
      var cell = range.getCell(i + 1, j + 1); // Cell object for formatting

      if (cell.getFontLine() === 'underline') {
        Logger.log('Underlined text found in cell ' + cell.getA1Notation() + ': ' + cellValue);
        // Do something with the underlined text
      }
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.