Getting data from a text file

  • Thread starter Jean-Marie Delapierre
  • Start date
J

Jean-Marie Delapierre

Hi,

I have two files in a directory.
one called toto.txt with the following content :
1
2
3
4
5

one called toto.html in which I want to get the data of toto.txt with a
javascript script.

May you suggest me an example of a script doing this ?

Regards.

Jean-Marie
 
A

alu

if the data file does not necessarily need to have a .txt extension, it
would be better to rename it toto.js (you can still open it in notepad)

within toto.js you'll need to assign variables for the data,
for example in the simplest way:

mydata1 = 1
mydata2 = 2
mydata3 = 3
mydata4 = 4
mydata5 = 5


then it's just a matter of including & using the variables within toto.html,
for example:

<script src="toto.js" type="text/javascript"></script>

<script Language='JavaScript'>
document.write(mydata1)
</script>


if you must have the data in a .txt extension file, it may still work:

<script src="toto.txt" type="text/javascript"></script>

<script Language='JavaScript'>
document.write(mydata1)
</script>
 
J

Jean-Marie Delapierre

Le Fri, 10 Oct 2003 18:37:38 -0400, alu a écrit :
if the data file does not necessarily need to have a .txt extension, it
would be better to rename it toto.js (you can still open it in notepad)

within toto.js you'll need to assign variables for the data,
for example in the simplest way:

mydata1 = 1
mydata2 = 2
mydata3 = 3
mydata4 = 4
mydata5 = 5


then it's just a matter of including & using the variables within toto.html,
for example:

<script src="toto.js" type="text/javascript"></script>

<script Language='JavaScript'>
document.write(mydata1)
</script>


if you must have the data in a .txt extension file, it may still work:

<script src="toto.txt" type="text/javascript"></script>

<script Language='JavaScript'>
document.write(mydata1)
</script>

Hi,

Thank you very mutch for your answer.
But, your solution can't work for me. The text file (here is only a basic
exemple) will be generated by an Excel extract.
Therefore, I have no possibility to transform it into a javascript script
assigning data to variables.

Regards.

Jean-Marie
 
L

Laurent Bugnion, GalaSoft

Hi,

Jean-Marie Delapierre said:
Hi,

Thank you very mutch for your answer.
But, your solution can't work for me. The text file (here is only a basic
exemple) will be generated by an Excel extract.
Therefore, I have no possibility to transform it into a javascript script
assigning data to variables.

Regards.

Jean-Marie

I assume that you have access to the Excel file. If so, why not simply
make a VB macro saving the text file in any format you decide?

If you really don't have this possibility, one possible way is to have a
Java applet read the text file, and pass the content to JS for
processing. See examples and a free download at
http://www.galasoft-LB.ch/myjava/WebLoadFile/Demo/Demo.html

Other ways include (if the application runs locally only) using the
FileSystemObject (IE only) or directly accessing the java File object
(Netscape only). All these solutions need lower security settings, and
not very easy to put in place.

I would try the macro solution first.

HTH,

Laurent
 
A

alu

Laurent Bugnion said:
Hi,



I assume that you have access to the Excel file. If so, why not simply
make a VB macro saving the text file in any format you decide?

If you really don't have this possibility, one possible way is to have a
Java applet read the text file, and pass the content to JS for
processing. See examples and a free download at
http://www.galasoft-LB.ch/myjava/WebLoadFile/Demo/Demo.html

Other ways include (if the application runs locally only) using the
FileSystemObject (IE only) or directly accessing the java File object
(Netscape only). All these solutions need lower security settings, and
not very easy to put in place.

I would try the macro solution first.

HTH,

Laurent
--


I agree, the Excel solution should be easy.
I'm not very familiar with Excel, but i would think that just adding 2
columns
to the left of the required data and then extracting all three columns
would do the trick.
e.g.,

="mydata"&ROW() = [data to extract]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top