Я пытаюсь завершить сценарий Google, чтобы переформатировать поле, которое в идеале хотелось бы превратить в гиперссылку.
Это обычный формат текста в электронной таблице:
tistaff: другие разделы: person: randomname
Вот как я хотел бы, чтобы это выглядело:
<li><a href="http://www.thisisstaffordshire.co.uk/topics/person/randomname">randomname</a></li>
Я сделал большую часть работы, кромепоследний бит, который я просто не могу понять.Может кто-нибудь помочь.
Вот мой сценарий:
function HTMLtransform() {
var sheet = SpreadsheetApp.getActiveSheet();
for(var c=1; c<sheet.getLastRow(); c++){
var rng = sheet.getRange("B"+c);
var rplc = sheet.getRange("F"+c);
var value = String(rng.getValue());
var replVal = new String('test');
var target = 'test'; // this variable is designed to capture the unique bit of the variable
target = value.replace(/tistaff: other sections:[a-z]*: ([a-z]*)$/, '$1');// this variable is designed to capture the unique bit of the variable
replVal = value;
replVal = replVal.replace(/ company:/, 'company/');
replVal = replVal.replace(/ person:/, 'person/');
replVal = replVal.replace(/ place:/, 'place/');
replVal = replVal.replace(/tistaff: other sections:/, '<li><a href="http://www.thisisstaffordshire.co.uk/topics/');
replVal = replVal.replace(/ ([a-z]*)$/, '');
replVal = replVal + target + '">' + target + '</a></li>';
rplc.setValue(replVal);
}
}
Это работает до определенного момента, но это вывод:
**<li><a href="http://www.thisisstaffordshire.co.uk/topics/person/tistaff: other sections: person: randomname">tistaff: other sections: person: randomname</a></li>**
Что я делаю не так?