Home > Net >  How to protect the positions to place the data in the worksheet when some values are not retrieved?
How to protect the positions to place the data in the worksheet when some values are not retrieved?

Time:02-20

I'm using the CheerioGS library:

ID → 1ReeQ6WO8kKNxoaA_O0XEQ589cIrRvEBA9qcWpNqdOP17i47u6N9M5Xh0
Project → enter image description here

Some values in the last column for some reason are not collected, so the position of some of these values in the worksheet is in the wrong place.

For example: If the first value is not collected but the second is, the second will be in row 1 of the column, then it would be wrong.

How could I add a dash - in the lines that the value is not collected?

CodePudding user response:

Instead of using Array.prototype.forEach and Range.setValue for filling cell by cell one column at a time, build an Array of Array of values, then add all the values at once by using Range.setValues.

In order to do this, instead of grabbing one cell (td) from all tables (tbody) at once, grab the whole table (tbody) and check if the required cell / content exists , if not add an empty string ('') to the corresponding position in the Array that is being build.

Resources

CodePudding user response:

You want to iterate those tr's. This will give a 2d array (untested)

$('tr').get().map(tr => $(tr).find("h4,.col-md-12").get().map(el => $(el).text()))
  • Related