如何使用 ActiveX 对象获取我的 Excel 文件的所有可用工作表名称的列表?
我知道这段代码 Excel.ActiveWorkBook.Sheets
返回工作表...但是我怎样才能在数组中获取这些工作表的名称?
function getTabs()
{
var w =new ActiveXObject("Excel.Application");
var book = w.Workbooks.Open(excelFile);
alert(book.name); //here I get the filename of my xls file and it displays ok
var ExcelSheet= book.Sheets;
alert(ExcelSheet); //This alerts to 'undefined'
w.Quit();
w=null;
}
这是我现在的代码......
最佳答案
好的,经过大量的反复试验,我得出了一个有效的答案:
var w =new ActiveXObject("Excel.Application");
var book = w.Workbooks.Open(excelFile);
var ExcelSheet= book.Sheets;
var sheetCount = ExcelSheet.Count;
var arrayOfSheets = new Array();;
for(var i=0;i<sheetCount;i++){
alert("Read sheets from file :"+ExcelSheet.Item(i+1).Name);
arrayOfSheets [i] =ExcelSheet.Item(i+1).Name;
}
关于javascript - 使用 ActiveX 获取工作表名称列表以在 javaScript 中排列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15635942/