Posted 31 March 2025, 6:42 am EST
- Updated 31 March 2025, 6:47 am EST
Hi Priya,
As per my understanding, you want to validate the sheet name while importing a file—for example, allowing the import if Sheet1 is named “test” and canceling it if the name is “hello.”
You can achieve this by using a dummy Spread instance. First, import the file into the dummy Spread, retrieve the sheet name, and validate it. If the name matches “test,” proceed with importing it into the original Spread instance and display the required message. If the name is “hello,” prevent the file from being imported into the original Spread instance.
Refer to the code snippet, attached GIF, and sample: https://jscodemine.mescius.io/share/9DVBT88S60SJF4-C5Kxmcw/?defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fsrc%2Fapp.jsx"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.jsx"}
document.getElementById("import").addEventListener("click", (e) => {
let file = document.getElementById("file").files[0];
if (!file) {
console.log("File not selected!");
return;
}
let validateSpread = new GC.Spread.Sheets.Workbook();
validateSpread.import(file, () => {
console.log("File imported!!");
let sheet1Name = validateSpread.getSheet(1).name();
if (sheet1Name) {
if (sheet1Name === "test") {
alert("Ready to upload!");
spread.import(file, () => {
alert("Imported Successfully!!");
}, (err) => {
console.log(err);
});
} else if (sheet1Name === "hello") {
alert("Importing cancelled!");
}
}
}, (err) => {
console.log(err);
});
});
GIF: 
Regards,
Priyam