In this spreadsheet, I have a row with all the employee data, with values coming from another table; In order to create the layout requested, I need 3 rows per employee, each row starting with the |1|,|1.1|,|1.1|, I found some code here that allows me to append two rows to every row of data, but no idea how to move the |1.1|,GTF,'100' to the next row, and then, |1.1|,PPA,'15' to the next one.
This is what i have:
|1|,'900','04000','0000','0','0000','0','11','0','S','A',|1.1|,GTF,'100',|1.1|,PPA,'15'
|1|,'986','01000','0000','0','0000','0','14','0','S','A',|1.1|,GTF,'110',|1.1|,PPA,'30'
|1|,'1046','01000','0000','0','0000','0','14','0','S','A',|1.1|,GTF,'120',|1.1|,PPA,'45'
And what Im looking for is to look like this:
|1|,'900','04000','0000','0','0000','0','11','0','S','A'
|1.1|,GTF,'100'
|1.1|,PPA,'15'
|1|,'986','01000','0000','0','0000','0','14','0','S','A',
|1.1|,GTF,'110'
|1.1|,PPA,'30'
function insertRows() {
var startRow = 1;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Prenom");
var sourceRange = sheet.getRange(startRow, 1, sheet.getLastRow());
var sheetData = sourceRange.getValues();
var numRows = sourceRange.getNumRows() - startRow;
// Logger.log(numRows);
for (var i=numRows; i > -1; i--) {
if (sheetData[i].join("")) {
sheet.insertRowsAfter(i startRow, 2);
}
}
}
Which leaves me with two empty rows. ty
CodePudding user response:
function separate() {
const s = `|1|,'900','04000','0000','0','0000','0','11','0','S','A',|1.1|,GTF,'100',|1.1|,PPA,'15'
|1|,'986','01000','0000','0','0000','0','14','0','S','A',|1.1|,GTF,'110',|1.1|,PPA,'30'
|1|,'1046','01000','0000','0','0000','0','14','0','S','A',|1.1|,GTF,'120',|1.1|,PPA,'45'`;
let r = s.match(/([^'] [^|] )/g);
Logger.log(r.join('\n'));
}
Execution log
12:02:55 PM Notice Execution started
12:02:55 PM Info ||1|,'900','04000','0000','0','0000','0','11','0','S','A',
|1.1|,GTF,'100',
|1.1|,PPA,'15'
|1|,'986','01000','0000','0','0000','0','14','0','S','A',
|1.1|,GTF,'110',
|1.1|,PPA,'30'
|1|,'1046','01000','0000','0','0000','0','14','0','S','A',
|1.1|,GTF,'120',
|1.1|,PPA,'45'
12:02:56 PM Notice Execution completed
CodePudding user response:
You have to split the cell value every time |1.1|
is found. There are several ways to do this. For example, you can combine