Google表格公式可确定单元格中的文本是否为斜体

时间:2019-01-22 12:43:51

标签: google-apps-script google-sheets

是否可以在Google表格中运行公式以确定单元格中的文本是否为斜体

类似于@Override public void update(final ViewerCell cell) { super.update(cell); ... your code 的事物将返回isItalic(a1) / TRUE,以便可以对该列进行过滤?

3 个答案:

答案 0 :(得分:2)

您还可以在Google表格中执行以下操作。

.getFontStyle()方法可能就是您想要的。

nnoremap <leader>tcd :execute "tcd " . getcwd()<CR>:pwd<CR>

可以找到here到文档的链接。

答案 1 :(得分:1)

=CHECKSTYLE(A1, "italic")

function CHECKSTYLE(range, styleElement) {
    var arr = [],
        ret;
    var styleEl = ["line-through", "underline", "italic", "bold"]
    var range = SpreadsheetApp.getActiveSheet()
        .getRange(range);
    var styles;
    if (styleEl.indexOf(styleElement) == 2) {
        styles = range.getFontStyles()
    } else if (styleEl.indexOf(styleElement) == 3) {
        styles = range.getFontWeights()
    } else if (styleEl.indexOf(styleElement) != -1) {
        styles = range.getFontLines();
    } else {
        throw "the 2nd parameter can only be " + styleEl.toString()
            .replace(",", ", ")
    }
    styles.reduce(function (a, b) {
        return a.concat(b);
    })
        .forEach(function (el) {
            el === styleElement ? arr.push(["TRUE"]) : arr.push(["FALSE"])
        });
    range.getNumRows() == 1 ? ret = transpose(arr) : ret = arr;
    return ret;
}

答案 2 :(得分:0)

//在单元格中= ISSTYLE((CELL(“ address”,D4)&“:”&CELL(“ address”,D4)),“斜体”)

function ISSTYLE(pRange, styleElement) {  
                 // thanks to Https://stackoverflow.com/questions/54308576/google-sheets-formula-to-determine-if-text-in-a-cell-is-italic

                // thanks to https://webapps.stackexchange.com/questions/10629/how-to-pass-a-range-into-a-custom-function-in-google-spreadsheets/92156

    var range = SpreadsheetApp.getActiveSpreadsheet().getRange(pRange);
    return range.getFontStyle() == styleElement;
}