...

View Full Version : Resolved Accessing Local Data using JS



klarosa
07-18-2011, 11:22 PM
Hello,

I am working on a project using HTML and javascript to allow the user to choose a vehicle from a drop down menu, then load a new page showing some information about this vehicle. The information is stored in an Excel file. I posted regarding this issue a while back and got an excellent response from Old Pedant (thanks again!) about using ActiveX - which has thus far worked perfectly. My initial condition was that I would only be using IE7+. However, my next idea was to be able to use it on an IPad (which I unfortunately do not own yet, making any kind of testing difficult) which I am fairly certain ActiveX won't work on. So, I was looking for any other method which would be similar.

Important note: this will not use the internet at all, all of these files will be available locally. There is a lot of material on running queries to servers, but I didn't think that would really apply here. It seems pretty clear that JS has difficulty accessing files client side (which I understand why completely), but I was hoping to find something that worked for the gray zone I'm currently working in since I'm not using servers at all.

I know that this is not really the intended use of HTML/JS, but I was hoping that by writing it as an HTML file, it'd be accessible to anyone with a browser. Some of my target computers have odd limitations (such as not being to download .exe files).

The code I based my original off of is shown below:


<script type="text/javascript">

var conn = new ActiveXObject("ADODB.Connection")
conn.Open ( 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\full\path\to\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";)';

var sql = "SELECT * FROM [nameOfSheet$]";
var rs = conn.execute( sql )
while ( ! rs.eof )
{
// just an example of dumping everything from the sheet out to the browser:
for ( var f = 0; f < rs.fields.count; ++f )
{
document.write( rs.fields(f).value + "," );
}
document.write("<br>\n");
rs.moveNext();
}

rs.close();
conn.close();
</script><script type="text/javascript">

var conn = new ActiveXObject("ADODB.Connection")
conn.Open ( 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\full\path\to\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";)';

var sql = "SELECT * FROM [nameOfSheet$]";
var rs = conn.execute( sql )
while ( ! rs.eof )
{
// just an example of dumping everything from the sheet out to the browser:
for ( var f = 0; f < rs.fields.count; ++f )
{
document.write( rs.fields(f).value + "," );
}
document.write("<br>\n");
rs.moveNext();
}

rs.close();
conn.close();
</script>

Thank you,
klarosa

rnd me
07-18-2011, 11:30 PM
since the ipad has no file system and no file upload input, you'll have to use a server.
you can get a close idea of what the ipad will display by running safari full-screen at 1024X768



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum