JavaScript gives you power to access local resources on you machine from a webpage, using Activex Object. Here is a Sample how to do it...

function edit()
{
var myApp = new ActiveXObject("Excel.Application"); //invoking EXCEL application
if (myApp != null)
{
myApp.visible = true; //this makes the application visible to us
myApp.workbooks.open("D:\\pin report\\pin_report.xls"); //creates a new work book
myApp.ActiveSheet.Cells(1,1).Value = "Hello World!"; // writes value to a cell
}
}

Note : myApp.visible can be true or false, if we use false then we cannot see the excel application. but it runs in background. we can still access it. Be careful when you use false. use myApp.Close(); after ur work with out fail.

This concept can also be applied to read, write, create a text file. like this...

function read_line_no()
{
var fso, f1, ts;
var ForReading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.CreateTextFile("c:\line_no.txt", true); // a text file is created here
f1.WriteLine("1443");
f1.WriteBlankLines(1);
f1.Close();
ts = fso.OpenTextFile("c:\line_no.txt", ForReading); //Open a text file for reading
line_no = ts.ReadLine(); //read a line from text file
ts.Close(); //Close the text file
}


Comments (0)