Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 2nd, 2004, 06:35 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reading from Excel Files

Hi Guys,

Can Javascript read data from an excel file and then outpuyt the data to a web page?

cheers

__________________
\'sync\' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
Reply With Quote
  #2 (permalink)  
Old October 2nd, 2004, 06:42 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Yes easily, do you want to run the code server-side or client-side?
If server-side then Excel will need to be installed on the server and all users will need a licence. If on the client the users will need Excel installed and your site will need to be in the "Local intranet" or "Trusted sites" zone.

--

Joe
Reply With Quote
  #3 (permalink)  
Old October 2nd, 2004, 06:54 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Joe,

The code will be run client side, we are covered by a site license so no worries there and my site is in the trusted zone.

Thanks
interrupt

Reply With Quote
  #4 (permalink)  
Old October 2nd, 2004, 07:37 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Where is the Excel file, on the server or the client?

--

Joe
Reply With Quote
  #5 (permalink)  
Old October 2nd, 2004, 08:47 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excel file will be on the server.

cheers

Reply With Quote
  #6 (permalink)  
Old October 2nd, 2004, 09:24 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That's the most awkward combination because as far as I know even the latest version cannot open a file by URL, you would need to copy the file to the client first then manipulate it.
First a function to copy files from server to client:
Code:
function saveRemoteFile(From, To)
{
  var oXmlHttp = new ActiveXObject("Msxml2.XmlHttp.4.0");  //Change to version 3 if necessary
  oXmlHttp.open("GET", From, false);
  oXmlHttp.send();
  if (oXmlHttp.status == 200)
  {
    var oStream = new ActiveXObject("Adodb.Stream");
    oStream.type = 1; //Binary
    oStream.open();
    oStream.write(oXmlHttp.responseBody);
    oStream.saveToFile(To, 1 && 2); //Create if needed and overwrite if necessary
    oStream.close();
  }
  else
  {
    throw new Error(oXmlHttp.statusText);  //Needs improving
  }
}
Now when web page needs Excel file you need to call
Code:
saveRemoteFile("http://myserver/myfolder/myfile.xls", "C:\\myfile.xls");
.
Now to work with file, let's display the value in cell A1 on first sheet in a div with the id of divOutput.
Code:
var oExcel = new ActiveXObject("Excel.Application");
var oWB = oExcel.workbooks.open("C:\\myfile.xls");
//oExcel.visible = true;
var oWS = oWB.worksheets(1);
document.getElementById("divOutput").innerText = oWS.Range("A1").value;
oExcel.quit();
--

Joe
Reply With Quote
  #7 (permalink)  
Old October 2nd, 2004, 10:03 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How the hell do you do that???? lol! Thats just the ticket! Thanks Joe.

interrupt

Reply With Quote
  #8 (permalink)  
Old September 28th, 2006, 09:31 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am having a problem when reading xls file. I dont want to upload the file on the server. I just want to read the file which the user is going to post.
Note: This file in not on the server and i want the file format as .xls (not .csv)
Using Request.BinaryRead(whatever may be the size of file) it gives me junk characters.

Please Help
Raghav

Reply With Quote
  #9 (permalink)  
Old September 28th, 2006, 09:31 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

More details about the problem
I have a web site in which any user(client) can upload the excel file.
The user is going to select file from his machine.
When the user clicks on upload the page(asp page) is posted back.
By using request.binaryread i will get all the contents of the page(asp) including the excel file data contents.
But i am not able to convert it in to readable format.

My main purpose is that i want the Excel data in the recordset.
I have the code to create the recordset when the file resides on the server.
And to do that i will have to upload that file on the server and then read it.
And after reading the file delete the file from the server. But that is not the solution.

By using request.binaryread i am able to read the file by converting it to string. But the same is not working for excel file.

Raghav

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading excel files dotnetprogrammer VS.NET 2002/2003 1 June 29th, 2005 07:01 AM
Reading excel and text files using VB6... CJ35 VB How-To 5 October 8th, 2004 03:56 AM
Reading from Binary Files jschmi J2EE 0 October 5th, 2004 01:09 AM
Reading/Creating/Writing Excel FIles p_nut33 C# 1 September 2nd, 2003 12:17 PM
reading files nightsurfer JSP Basics 0 August 10th, 2003 04:34 PM



All times are GMT -4. The time now is 03:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.