我想讓 RICHTEXT_TO_HTML 的公式動態化,這意味著當我自動填充整行時,它應該從 A2 到 A3 再到 A4,......
- 我使用公式 RICHTEXT_TO_HTML(A1) ;單元格發生變化,因此它是動態的,公式不起作用。
- 我使用公式 RICHTEXT_TO_HTML('A1'); 下降時單元格不會動態變化,公式正在運行。
使用以下腳本時出現問題;
function RICHTEXT_TO_HTML(qRange) {
var indexBool = false;
var indexItalic = false;
var indexUnderline = false;
var indexStrikethrough = false;
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var range = sheet.getRange(qRange);
var cell = range;
var cellValue = cell.getRichTextValue();
var txt = String(cell.getDisplayValue());
var styles = cell.getTextStyles();
var result = '';
for (var i = 0; i < txt.length; i ) {
var style = cellValue.getTextStyle(i, i 1);
if (!indexStrikethrough && style.isStrikethrough()) {
indexStrikethrough = true;
result = '<strike>';
} else if (indexStrikethrough && !style.isStrikethrough()) {
indexStrikethrough = false;
result = '</strike>';
}
if (!indexUnderline && style.isUnderline()) {
indexUnderline = true;
result = '<u>';
} else if (indexUnderline && !style.isUnderline()) {
indexUnderline = false;
result = '</u>';
}
if (!indexBool && style.isBold()) {
indexBool = true;
result = '<strong>';
} else if (indexBool && !style.isBold()) {
indexBool = false;
result = '</strong>';
}
if (!indexItalic && style.isItalic()) {
indexItalic = true;
result = '<i>';
} else if (indexItalic && !style.isItalic()) {
indexItalic = false;
result = '</i>';
}
result = txt[i];
}
if (indexStrikethrough) {
result = '</strike>';
}
if (indexUnderline) {
result = '</u>';
}
if (indexBool) {
result = '</strong>';
}
if (indexItalic) {
result = '</i>';
}
return result;
}
任何人都知道如何解決這個問題,因此如果您不使用“$”,則單元格范圍會像任何其他常規公式一樣動態變化?非常感謝您!
uj5u.com熱心網友回復:
非常感謝!我還發現 =RICHTEXT_TO_HTML(ADDRESS(ROW(A1);COLUMN(A1);4)) 也有效,我認為它們兩者之間的作業量差異不大,但請記住兩者以防萬一1比另一個給出更多的問題。
再次感謝:)這個問題解決了
uj5u.com熱心網友回復:
問題是,如果您使用 RICHTEXT_TO_HTML(A1),qRange 將不是“A1”,而是該單元格中的值,即富文本。我建議像這樣重寫公式:
致電:(在表格中)
=RICHTEXT_TO_HTML(行(A1),列(a1))
公式
function RICHTEXT_TO_HTML(row, column) {
...
var range = sheet.getRange(row, column);
...
在這種情況下,公式將在復制時正確更新,并且作業方式相同
uj5u.com熱心網友回復:
@Roma 是正確的。傳遞給函式的引數 A1 不是范圍,而是范圍的值。一個解決方案是獲取公式并提取括號之間的文本。此示例假定只有一個引數傳遞給函式。
由于引數實際上是一個范圍而不是字串,因此如果將公式復制到其他單元格,它將被更新。
=TestFormula(G99)將回傳 G99
function TestFormula(dummy) {
let formula = SpreadsheetApp.getActiveRange().getFormula();
let range = formula.match(/\((.*)\)/);
return range[1];
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/480305.html
