使用ActiveX to javaScript中的工作表名称列表 [英] Get list of Worksheet names using ActiveX to array in javaScript
本文介绍了使用ActiveX to javaScript中的工作表名称列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用ActiveX Object获取我的excel文件的所有可用工作表名称列表?
How can i get a list of all available Sheet names for my excel file using ActiveX Object?
我知道这个代码 Excel.ActiveWorkBook .Sheets
返回工作表...但是如何在数组中获取这些工作表的名称?
I know this code Excel.ActiveWorkBook.Sheets
returns the sheets... But how could I get the NAMES of these sheets in an array?
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;
}
这是我现在的代码.....
This is my code right now.....
推荐答案
好的,经过很多的尝试和错误我得到了一个有用的答案:
ok, after a lot of trial and error i have come to an answer that works:
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;
}
这篇关于使用ActiveX to javaScript中的工作表名称列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文