Inspiring
October 15, 2023
Question
animate + *.xlsx
- October 15, 2023
- 4 replies
- 683 views
Hello geniuses
I have a file
I want to enter a number from first row and it will call me all the row data from a file
Can anyone help me?
I don't know why the fla file is not uploaded
var xlsxFileName = "name_id.xlsx";
var sheetName = "Sheet1"; console.log(workbook) call below
var rows = [ "1", "2" , "3", "4", "5"];
var targetTextFieldsContainers;
function main()
{
root.stop();
targetTextFieldsContainers = [ root.tf0, root.tf1, root.tf2, root.tf3, root.tf4 ];
readXLSX(xlsxFileName, onXLSXLoaded, { sheetName: sheetName, rows: rows });
}
function readXLSX(src, callback, props)
{
var req = new XMLHttpRequest();
var textFields = [];
var texts = [];
var data = [];
var i;
req.open("GET", src, true);
req.responseType = "arraybuffer";
req.onload = function(e)
{
var workbook = XLSX.read(req.response);
var worksheet = workbook.Sheets[props.sheetName];
var key;
console.log(workbook);
console.log(worksheet);
for (key in worksheet)
{
if (key.indexOf(props.rows[0]) > -1)
textFields.push(worksheet[key].h);
if (key.indexOf(props.rows[1]) > -1)
texts.push(worksheet[key].h);
}
for (i = 0; i < textFields.length; i++)
data[i] = { tf: textFields[i], text: texts[i] };
callback(data);
};
req.send();
}
function onXLSXLoaded(data)
{
console.log(data);
data.forEach(function(item)
{
if (targetTextFieldsContainers.indexOf(root[item.tf]) > -1)
root[item.tf].tf.text = item.text;
});
stackTextFields(targetTextFieldsContainers);
}
function stackTextFields(targets)
{
targets.forEach(function(tf, index, array)
{
var currentHeightOffset = tf.tf.getMeasuredHeight() * 0.5;
tf.tf.y = -currentHeightOffset;
if (index > 0)
{
var previousTF = array[index - 1];
tf.y = previousTF.y + previousTF.tf.getMeasuredHeight() * 0.5 + currentHeightOffset;
}
});
}
if (!this.looped)
{
window.root = this;
main();
root.looped = 1;
}
