[p5] I am curious about the Excel conversion source code / array declaration.
1. How to declare array like ‘java’ in ‘p5’?
example) 10x10 array make
String[][] randoms = new String[10][10];
How do I do ‘p5’ to do the above?
2. Implemented ‘excel export’ using the source code below.
2-1) html
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/addons/p5.sound.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2014-11-29/FileSaver.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.12.13/xlsx.full.min.js"></script>
</head>
<body>
<main>
</main>
<script src="sketch.js"></script>
</body>
</html>
2-2) sketch.js
var String_ARRAY = [["","","","",""],["","","","",""],["","","","",""],["","","","",""]];
function setup() {
createCanvas(400, 400);
//----------------------------------------------------//
for (var i = 0; i < 4; i++) {
String_ARRAY[0][i]="value-"+str(i+1);
String_ARRAY[1][i]=random(0,100);
String_ARRAY[2][i]=random(100,200);
String_ARRAY[3][i]=random(200,300);
}
//----------------------------------------------------//
//----------------------------------------------------//
var worksheet_data = String_ARRAY;
var workbook = XLSX.utils.book_new();
var worksheet = XLSX.utils.aoa_to_sheet(worksheet_data);
workbook.SheetNames.push("Test");
workbook.Sheets["Test"] = worksheet;
var filename=str(hour())+str(minute())+str(second());
exportExcelFile(workbook,filename);
//----------------------------------------------------//
}
function draw() {
background(220);
}
function exportExcelFile(workbook, file_name) {
return XLSX.writeFile(workbook, file_name+".xlsx");
}
The above source code works fine.
Questions) How to declare array like ‘java’ in ‘p5’?