xlsfunc
by Mohammad Gouse
HTML
<input type="file" id="excelFile" />
<button onclick="readExcel()">Read Excel</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script>
function readExcel() {
const fileInput = document.getElementById('excelFile');
// Check if a file was selected
if (fileInput.files.length === 0) {
alert("Please select an Excel file.");
return;
}
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(event) {
const data = new Uint8Array(event.target.result);
const workbook = XLSX.read(data, { type: 'array' });
// Check if VBA project information is available
if (workbook.vbaProject) {
// Access the VBA project
const vbaProject = workbook.vbaProject;
debugger
// Iterate through the modules (macros) and their content
for (const moduleName in vbaProject) {
const module = vbaProject[moduleName];
console.log(`Macro Name: ${moduleName}`);
console.log(`Macro Content:`);
console.log(module);
console.log("---------------------");
}
} else {
console.log("No VBA project (macros) found in the Excel file.");
}
};
reader.readAsArrayBuffer(file);
}
</script>