संक्षिप्त जवाब
सेल सूत्र के अंदर उद्धृत स्ट्रिंग प्राप्त करने के लिए एक कस्टम फ़ंक्शन का उपयोग करें।
कोड
Yisroel Tech द्वारा टिप्पणी में साझा किए गए बाहरी पोस्ट में एक स्क्रिप्ट शामिल है जो प्रत्येक सूत्र को उसी श्रेणी में पहले उद्धृत स्ट्रिंग द्वारा सक्रिय सीमा में बदल देती है। निम्नलिखित उस स्क्रिप्ट के कस्टम फ़ंक्शन के रूप में एक अनुकूलन है।
/**
* Extracts the first text string in double quotes in the formula
* of the referred cell
* @param {"A1"} address Cell address.
* @customfunction
*/
function FirstQuotedTextStringInFormula(address) {
// Checks if the cell address contains a formula, and if so, returns the first
// text string in double quotes in the formula.
// Adapted from https://productforums.google.com/d/msg/docs/ymxKs_QVEbs/pSYrElA0yBQJ
// These regular expressions match the __"__ prefix and the
// __"__ suffix. The search is case-insensitive ("i").
// The backslash has to be doubled so it reaches RegExp correctly.
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp
if(address && typeof(address) == 'string'){
var prefix = '\\"';
var suffix = '\\"';
var prefixToSearchFor = new RegExp(prefix, "i");
var suffixToSearchFor = new RegExp(suffix, "i");
var prefixLength = 1; // counting just the double quote character (")
var ss = SpreadsheetApp.getActiveSpreadsheet();
var cell, cellValue, cellFormula, prefixFoundAt, suffixFoundAt, extractedTextString;
cell = ss.getRange(address);
cellFormula = cell.getFormula();
// only proceed if the cell contains a formula
// if the leftmost character is "=", it contains a formula
// otherwise, the cell contains a constant and is ignored
// does not work correctly with cells that start with '=
if (cellFormula[0] == "=") {
// find the prefix
prefixFoundAt = cellFormula.search(prefixToSearchFor);
if (prefixFoundAt >= 0) { // yes, this cell contains the prefix
// remove everything up to and including the prefix
extractedTextString = cellFormula.slice(prefixFoundAt + prefixLength);
// find the suffix
suffixFoundAt = extractedTextString.search(suffixToSearchFor);
if (suffixFoundAt >= 0) { // yes, this cell contains the suffix
// remove all text from and including the suffix
extractedTextString = extractedTextString.slice(0, suffixFoundAt).trim();
// store the plain hyperlink string in the cell, replacing the formula
//cell.setValue(extractedTextString);
return extractedTextString;
}
}
} else {
throw new Error('The cell in ' + address + ' does not contain a formula');
}
} else {
throw new Error('The address must be a cell address');
}
}