我想用腳本將A欄裡面的文字,刪除韓文部分後,貼到B欄(B欄中文段落字體樣式要取A欄一樣)
如圖
使用以下chatGPT給的語法卻無法作用,請問我該如何修改呢?謝謝!
function copyAndRemoveKorean() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('test');
var sourceCell = sheet.getRange('A1');
var sourceValue = sourceCell.getValue();
var sourceRichTextValue = sourceCell.getRichTextValue();
var targetCell = sheet.getRange('B1');
targetCell.setValue(sourceValue);
targetCell.setRichTextValue(sourceRichTextValue);
var targetText = targetCell.getValue();
var cleanedText = removeKoreanAndNumberedItems(targetText);
targetCell.setValue(cleanedText);
}
function removeKoreanAndNumberedItems(text) {
var lines = text.split('\n');
var cleanedLines = [];
var isPreviousLineEmpty = false;
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line.trim() !== '' && !containsKorean(line)) {
cleanedLines.push(line);
isPreviousLineEmpty = false;
} else {
if (line.trim() === '') {
cleanedLines.push(line);
isPreviousLineEmpty = true;
} else {
if (!isPreviousLineEmpty) {
continue;
}
}
}
}
return cleanedLines.join('\n');
}
function containsKorean(text) {
var koreanPattern = /[\u3131-\uD79D]/;
return koreanPattern.test(text);
}
使用以下chatGPT給的語法卻無法作用,請問我該如何修改呢?謝謝!
你可以繼續再追問下去
ChatGPT會給你不同的答案/程式碼