Carbon News

Embed Test

Carbon Credits Live Prices

// API Key
var apiKey = ‘AIzaSyCxclgd-mBmrkczMqXOLGD-dSUUmCkTfrg’;

// Get the data range
var range = ‘A1:D12’; // Adjusted the range to A1:D12

// Construct the URL
var url = `https://sheets.googleapis.com/v4/spreadsheets/${documentId}/values/${range}?key=${apiKey}`;

// Fetch the data from the Google Sheets API
fetch(url)
.then(response => response.json())
.then(data => {
// Get the values
var values = data.values;

// Check if there are any values
if (values.length > 0) {
// Get the table
var table = document.getElementById(‘priceData’);

// Clear the table
table.innerHTML = ”;

// Iterate over each row
for (let i = 0; i < values.length; i++) {
// Create a new table row
var tr = document.createElement(‘tr’);

// Iterate over each cell in the row
for (let j = 0; j < values[i].length; j++) {
// Create a new table cell
var td = document.createElement(‘td’);

// Set the cell text
td.innerText = values[i][j];

// Add the cell to the row
tr.appendChild(td);
}

// Add the row to the table
table.appendChild(tr);
}
} else {
console.log(‘No data found.’);
}
})
.catch(error => console.error(‘Error:’, error));

The post Embed Test appeared first on Carbon Credits.