Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open and read from Excel with Javascript or ASP

Status
Not open for further replies.

lillu

Technical User
Jun 25, 2003
29
HU
sorry - forgot to write subject.

Hi,

I must accomplish this using client-side javascript or if it's not feasible, ASP.
The scenario: There is an Excel file that resides on a server. The worksheet contains two columns: Date and Name.
Eg.
Date Name
11 Nov John Doe
12 Nov Fred Leigh

They can swap dates with another person in the list. There is a hyperlink on a HTML page through which they can open up the file, edit then save it.

The script (Javascript/ASP) I need:
The same HTML page should display the person's name who appears next to today's date.

All I've got so far is opening the Excel Appliation. No workbook is opened either using javascript or ASP. What am I doing wrong?

ASP:

<% @ language=&quot;VBscript&quot; %>
<%
Dim objXlApp, objXlSheet

' create the Excel object
Set objXlApp = Server.CreateObject(&quot;Excel.Application&quot;)

' open the spreadsheet file
objXlApp.Workbooks.Open &quot;SheriffOnDuty.xls&quot;

' get the worksheet
Set objXlSheet = objXlApp.Worksheets(&quot;SheriffOnDuty4&quot;)

' read from the worksheet
Response.Write(objXlSheet.Range(&quot;B1&quot;).Text)

' clean up
Set objXlSheet = Nothing
objXlApp.Workbooks.Close
Set objXlApp = Nothing

%>

With this one I get this error:
Error Type:
Microsoft Excel (0x800A03EC)
'SheriffOnDuty.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.
If you are trying to open the file from your list of most recently used files on the File menu, make sure that the file
has not been renamed, moved, or deleted.
/lillu/working/openExcel.asp, line 9

Javascript:

<script language=&quot;javascript&quot;>
function LaunchExcel()
{
var excelApp = new ActiveXObject(&quot;Excel.Application&quot;);

excelApp.Workbooks.Open = &quot;SheriffOnDuty.xls&quot;;

excelSheet = excelApp.Worksheets(&quot;SheriffOnDuty4&quot;);

document.write(excelSheet.Range(&quot;B1&quot;).Text);

excelApp.Quit();
excelApp = null;
setTimeout(&quot;CollectGarbage()&quot;,1);
}
</script>

It launches Excel but the specified file doesn't show up.

Thank you for any help on this.

Lillu

If you want to get a job done, ask a busy person. (Sherry Conway Appel - American writer)
 
I don't even know if you can access files using JavaScipt - because their is a security issue there.

Try to to specify the full path of the Excel file.

Who exactly will be running this JavaScript? Because since JavaScript runs on the client side - it will attempt to open the file on the computer of the user who is accessing the page.
 
Thanks, I already worked it out.

The file resides on a server which is accessible to certain users (those I gave permissions to edit this file)
I just had to give a full path in ASP and it worked all fine. Using javascript will raise a security issue so that's why I opted for ASP.

Thanks.

Lillu

If you want to get a job done, ask a busy person. (Sherry Conway Appel - American writer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top