I am totally new in coding.
I have a code which can retrieve cell value based on the specific range of google published sheet. specific cell value is coming from the google sheet url. Because I added &range=A1 specifically in the URL. The rage can be extended by changing the url into &range=A1:F20 as an example.
my code is working fine. The problem is, it only parses one cell value.
I want to parse more specific cell values (e.g. A1, A3, C5, F9 etc) at the same time without requesting google sheet link for too many times.
By using the following below code I can retrieve and display only one cell value.
<body onload='loadData()'>
<div id="display"></div>
But I want to retrieve more individual cell values. (e.g. A1, A3, C5, F9 etc)
Here's the code:
<!DOCTYPE html>
<html>
<body>
<body onload='loadData()'>
<div id="display"></div>
<script>
function loadData() {
var url="https://docs.google.com/spreadsheet/pub?key=p_aHW5nOrj0VO2ZHTRRtqTQ&single=true&gid=0&range=A1&output=csv";
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status==200){
document.getElementById("display").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
</script>
</body>
</html>
Can you help please?
Thank you so much.
var url="https://docs.google.com/spreadsheet/pub?key=p_aHW5nOrj0VO2ZHTRRtqTQ&single=true&gid=0&range=A1:F20&output=csv";
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status==200){
const result = xmlhttp.responseText;
const values = result.split('\n').map(row => row.split(','));
console.log(values[0][0]); // A1
console.log(values[2][0]); // A3
console.log(values[4][2]); // C5
console.log(values[8][5]); // F9
}
};
xmlhttp.open("GET",url,true);
xmlhttp.send(null);