JAVASCRIPT to read excel

Sample Code:

function ReadExcelFile() {
var fileUrl;
var rowIndex;
var colIndex;
var workSheetCount;
var XLSheet;
fileUrl = document.getElementById("hdnFileName").value;
//alert(fileUrl);
objExcel = new ActiveXObject("Excel.Application");
//alert("Excel Obj Created");
objWorkbook = objExcel.Workbooks.Open(fileUrl);
//alert("Excel Workbook Created");
workSheetCount = objExcel.Worksheets.Count;
//alert(workSheetCount);
XLSheet = null;
for(var Iter = 1; Iter < workSheetCount; Iter++) {
XLSheet = objExcel.Worksheets(Iter);
for(rowIndex = 1; rowIndex <= 5 ; rowIndex++) {
for(colIndex = 1; colIndex <= 5; colIndex++) {
alert(XLSheet.Cells(rowIndex, colIndex).value);
}
}
}
objExcel.Application.Quit();
}

Cheers!!!

No comments:

Post a Comment