In the next deployment it will be possible to use the EmbedControl API to load the data directly from script.
The URL of the embedded application should be changed to include #wait
instead of #load
- this instructs that the application waits for the EmbedControl API call and does not ask the user to provide the data.
Next the API is used to import the data:
var ec = new SpreadsheetAnalytics.EmbedControl(document.getElementById("iframe"), "*");
function importData() {
var data = {
meta: {
Category: { value: false },
Value: { value:true }
},
data: [
{ Category: "A", Value: Math.random() * 10 },
{ Category: "B", Value: Math.random() * 10 },
{ Category: "C", Value: Math.random() * 10 },
{ Category: "A", Value: Math.random() * 10 },
{ Category: "B", Value: Math.random() * 10 },
{ Category: "C", Value: Math.random() * 10 },
{ Category: "A", Value: Math.random() * 10 },
{ Category: "B", Value: Math.random() * 10 },
{ Category: "C", Value: Math.random() * 10 },
{ Category: "A", Value: Math.random() * 10 },
{ Category: "B", Value: Math.random() * 10 },
{ Category: "C", Value: Math.random() * 10 },
]
};
ec.importData("sample.json", data, function (e) {
console.log("API data import success", e);
}, function (e) {
console.log("API data import failed", e);
});
}
The method can also be used to import Excel or other supported file formats.