please help, I am stuck with splitting listview text at "&". I want to pass splitted text each to different inputbox.
$('#art1popsel ul').children('li').on('click', function () {
event.preventDefault();
var selected = $('#art1popsel ul').text();
var substr = selected.split('&');
var artikl = substr[0];
var cijena = substr[1];
$("#art1").val($('artikl').text());
$("#cij1").val($('cijena').text());
});
It is a listview value: <li>122331 SOMETHING&42,00</li>
Where did I go wrong? Tnx in advance.
Related
Is there a way to take the Title Text from the Google Sheets cell?
So whenever I change the cell string then it should appear in the Chart automatically.
For example: I have May - 2021 in cell A1. Can I reference this in Title Text, like using =A1 or =Sheet1!A1? But it does not work.
I got this code, but how do I reference the cell into the code?
function onOpen() {
SpreadsheetApp.getUi().createMenu('Charts').addItem('Update', 'myFunction').addToUi();
}
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
var chart = sheet.getCharts()[0];
chart = chart.modify()
.setOption('Summary!Q123', sheet.getActiveCell().getValue() || 'Summary!Q123')
.build();
sheet.updateChart(chart);
}
Although it is not possible to link a cell value as title, there is a trick that may solve your problem by creating a merge cell, camouflage, as the title. Then it will be changed, based on the text value you enter :)
Script:
You may use the following script to update the title by referring to A3 every time you execute the code. Basically, you are almost correct:
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
var newtitle = sheet.getRange(3, 1).getValue();
var charts = sheet.getCharts()[0];
var chart = charts.modify()
.setOption('title', newtitle)
.build()
sheet.updateChart(chart)
var scnCharts = sheet.getCharts()[1];
var chart2 = scnCharts.modify()
.setOption('title', newtitle)
.build()
sheet.updateChart(chart2)
}
I'm trying to get this code to work but keep getting a "TypeError: offset.copyTo is not a function". The script is supposed to take one value from sheet "Budget" and copy it into the next available row in column F on sheet "Projected".
I have tried playing around with syntax and other ways to copy but to now avail, any help would be greatly appreciated
function OffsetRecord() {
var sheet = SpreadsheetApp.openById("xx").getSheetByName("Budget");
var offset = sheet.getRange('I5').getValue();
var destSheet = SpreadsheetApp.openById("xx").getSheetByName("Projected");
var colF = destSheet.getRange('F:F').getValues();
var fcolF = colF.filter(function (e) {return e[0];});
var firstEmptyRowIncolF = fcolF.indexOf('')+1;
offset.copyTo(firstEmptyRowIncolF, {contentsOnly: true});
copyTo expects ranges as parameters, not values or column numbers, see here
Modify your code as following:
function OffsetRecord() {
var spreadsheet = SpreadsheetApp.openById("XX");
var sheet = spreadsheet.getSheetByName("Budget");
var offset = sheet.getRange('I5');//without ".getValue();"!
var destSheet = spreadsheet.getSheetByName("Projected");
...
firstEmptyRowIncolF = ...;
var destinationColumn = 1;
var range = destSheet.getRange(firstEmptyRowIncolF, destinationColumn);
offset.copyTo(range, {contentsOnly: true});
}
I'm still SUPER new to Google Sheets, I've mostly just programmed in VBA before this.
The project I'm working on is for a D&D type game, wherein the DM will use Sheet to record damage dealt to the monster. Basically the DM types the damage, clicks the calculate button, then the code sums up the current damage to baddie.
The code works perfectly. The problem I'm having is a human one. There is a tendency to click the "calculate" button before closing the cell.
For instance, the DM types 31 in the cell and immediately clicks "calculate" before hitting enter. This prevents the damage from being recorded properly and I can't figure out the code to make the cell close first.
Here is my current code:
function DamageRecordEnemy1Copy1() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A1').activate();
var DamageLocation = spreadsheet.getRange('Q4');
var DamageLogLocation = spreadsheet.getRange('Q5');
var DamageLocationValue = DamageLocation.getValue();
var DamageLogLocationValue = DamageLogLocation.getValue();
var NewDamage = DamageLocationValue + DamageLogLocationValue;
DamageLocation.activate();
spreadsheet.getCurrentCell().setValue(NewDamage);
DamageLogLocation.activate();
spreadsheet.getCurrentCell().setValue("");
spreadsheet.getRange('A1').activate();
}
Any idea how to solve the issue? Much appreciated!
Thanks for the help everyone, here is what I ended up doing:
function onEdit(e){
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = e.range;
var DamageLocation = spreadsheet.getRange('Q4');
var DamageLogLocation = spreadsheet.getRange('Q5');
var DamageLocationValue = DamageLocation.getValue()
var DamageLogLocationValue = DamageLogLocation.getValue()
var allRows = [5];
var allColumns = [17, 20, 23, 26, 29, 32];
var EditRow = range.getRow()
var EditColumn = range.getColumn()
if (allColumns.indexOf(EditColumn) > -1)
{
if (allRows.indexOf(EditRow) > -1)
{
var BadDamage = spreadsheet.getRange(EditRow-1,EditColumn)
var BadDamageLog = spreadsheet.getRange(EditRow,EditColumn)
var DamageCalc = BadDamage.getValue() + BadDamageLog.getValue()
BadDamage.setValue(DamageCalc);
BadDamageLog.setValue("");
}
}
};
Replace the "button" with insert->checkbox then use the OnEdit function to check if that cell was set to true, execute your button code and set it back to false. The reason this will work is because Drawings are on it's own layer but the checkbox will force them to have the "hit enter" behavior.
I would like to replace a string between 2 other strings in dart, for example :
var str="<!-- cells -->test<!-- cells -->";
the delimiters around will not change and will be always the same.
How to replace 'test' by 'test2' for example ?
var str = "<!-- cells -->test<!-- cells -->";
var replace = 'foo';
var counter = 0;
final result = str.replaceAllMapped(RegExp(r'(<!-- )(.*?)( -->)'), (m) {
return '${m[1]}$replace${counter++}${m[3]}';
});
print(result);
finally I found a solution quickly: replaceAllMapped
I'm trying to write a script to put data in specific lines based on the id.
I already have that:
function copy(){
var tabelle1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var tabelle2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2 ");
tabelle2.getRange(3,7).copyTo(tabelle1.getRange(tabelle1.getLastRow()+1,1));
tabelle2.getRange(13,4).copyTo(tabelle1.getRange(tabelle1.getLastRow()+0,2));
}
image for the code
Now my question is how can I delete all lines with the same id (1) before copying the lines with the script. (See picture)
Or if my list has each id only once, how can I override the value?
The following should do it. Your code was incorrect in its sheet references. I used setValue instead of copyTo since you need the value selected to pass to the readRows function it just seems cleaner.
function copy(){
var tabelle1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var tabelle2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
var sel=tabelle1.getRange(3,7).getValue()
readRows(sel)
tabelle2.getRange(tabelle2.getLastRow()+1,1).setValue(sel);
var tm=tabelle1.getRange(13,4).getValue()
tabelle2.getRange(tabelle2.getLastRow()+0,2).setValue(tm);
}
function readRows(sel) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
var lr=sheet.getLastRow()
var values = sheet.getRange(1,1,lr,2).getValues();
var rowsDeleted = 0;
for (var i = 0; i <= values.length-1; i++) {
var row = values[i][0];
if (row == sel) {
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}
};