How to read a Excel file in Javascript using ActiveX

The following code will help you to read a Excel File and show it has table format in HTML <html> <body onload=”GetData();”> <div id=”ExcelContent”> </div> </body> <script type=”text/javascript”> function GetData() { var excel = new ActiveXObject(“Excel.Application”); var excel_file = excel.Workbooks.Open(“H:/sample_Codes/sample.xls”); var excel_sheet = excel.Worksheets(“Sheet1″); var totalColCount=excel_sheet.UsedRange.Columns.Count; var totalRowCount = excel_sheet.UsedRange.Rows.Count; var htmlStr=”<table>”; for(i=0;i<totalRowCount;i++) { htmlStr…

Details

How to read / write files using activex in JavaScript

1. Reading a file

function ReadFile()
{
var FileOpener = new ActiveXObject(“Scripting.FileSystemObject”);
var FilePointer = FileOpener.OpenTextFile(“C:\abcd.txt”, 1, true);
FileContents = FilePointer.ReadAll();
alert("FileContents  " + FileContents);
FilePointer.Close();
}

2. Writing a file

function WriteFile
{
var FileOpener = new ActiveXObject(“Scripting.FileSystemObject”);
var FilePointer = FileOpener.OpenTextFile(“C:\abcd.txt”, 8, true);
FilePointer.WriteLine(“Writing first line”);
FilePointer.Close();
}