www.webdeveloper.com
Results 1 to 9 of 9

Thread: A script that will download csv file and show it on a web page

  1. #1
    Join Date
    Apr 2013
    Posts
    5

    A script that will download csv file and show it on a web page

    Hello everyone.

    I am new here. Just curious if you can help me with this....

    Currently I am working on a automation project and one of the tasks I need to do is to show a data log on a web page.
    Basically, a PLC (device that is used in industry automation) will save a data log .csv file on a web server. I need to
    access that file and show it on a web page in a table. So far I have searched across the web for solution but a lot of
    those solutions use jquery or PHP which I can't use (PHP because server can't use it, and jquery because it's too large, PLC has a limited memory space). Can you help me?

    Thanks.

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    funny, i wrote a great tool last month to do that: danml.com/bind/
    it doesn't need jQuery or phpm and has a lot of examples and documentation online.

    let me know if you need a hand getting it to work for your specific needs/server/site...

  3. #3
    Join Date
    Apr 2013
    Posts
    5
    Quote Originally Posted by rnd me View Post
    funny, i wrote a great tool last month to do that: danml.com/bind/
    it doesn't need jQuery or phpm and has a lot of examples and documentation online.

    let me know if you need a hand getting it to work for your specific needs/server/site...
    Hey, thanks for your help. Your tool seems to be exactly what I need, however, I have a hard time making it work...

    This is what I wrote in my HTML file:

    Code:
    <OBJECT id="tdcLog" CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
    	<PARAM NAME="DataURL" VALUE="/log.csv">								  
    	<PARAM NAME="UseHeader" VALUE="True">
    	<param name="RowDelim" value="\n" />
    	<param name="FieldDelim" value="," />
    	<PARAM NAME="TextQualifier" VALUE=",">
    </OBJECT>
    						
    			<TABLE datasrc=#tdcLog border=1>
    <THEAD><TR>
       <TD>Datum</TD><TD>Ime</TD><TD>Prezime</TD><TD>Email</TD>
       </TR></THEAD>
    <TBODY>
    <TR>
       <TD><DIV datafld="datum"></DIV></TD>
       <TD><DIV datafld="ime"></DIV></TD>
       <TD><DIV datafld="prezime"></DIV></TD>
       <TD><DIV datafld="email"></DIV></TD>
    </TR>
    </TBODY>
    </TABLE>
    and this is log.csv

    Code:
    datum	ime	prezime	email	
    datum1, ime1, prezime1, email
    datum2, ime2, prezime2, email
    datum1, ime1, prezime1, email
    datum2, ime2, prezime2, email
    I know there is something that I am doing wrong, but I can't find out. Thanks for you help and your tool.

  4. #4
    Join Date
    Apr 2013
    Posts
    5
    Oh yeah, the only thing that gets printed to my page is table header, and the next row is generated but it is empty.

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    it looks like your csv file has no commas in in the header row, which would prevent it from working.

    also, this should not be the same as the delimeter:

    <PARAM NAME="TextQualifier" VALUE=",">

    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    you can just delete the param to use the default (quote ).
    Last edited by rnd me; 04-14-2013 at 10:24 PM.

  6. #6
    Join Date
    Apr 2013
    Posts
    5
    I copied this:

    Code:
    	<OBJECT id="tdcComposers" CLASSID="clsid:lxw5wyjv-46wm-6lxr-bl9h-yp9avjwcdizk">
    	<PARAM NAME="DataURL" VALUE="https://docs.google.com/spreadsheet/pub?key=0Aptc98y5K95RdGdOaGdubFk2YWh5ZEkxVGNpeFF4clE&output=csv">								  
    	<PARAM NAME="UseHeader" VALUE="True">
    	<PARAM NAME="TextQualifier" VALUE="'">
    </OBJECT>
    
    
    			
    			
    			<TABLE datasrc=#tdcComposers>
    <THEAD><TR>
       <TD>Long Term</TD><TD>Right Now</TD><TD>Date</TD><TD>Comments</TD>
       </TR></THEAD>
    <TBODY>
    <TR>
       <TD><DIV datafld="Long Term"></DIV></TD>
       <TD><DIV datafld="Right Now"></DIV></TD>
       <TD><DIV datafld="Timestamp"></DIV></TD>
       <TD><DIV datafld="What do you think?"></DIV></TD>
    </TR>
    </TBODY>
    </TABLE>
    from your example and the only thing that is displayed on my web page is

    Code:
    Long Term	Right Now	Date	Comments
    So I think something is not right?? I did put <script type='text/javascript' src='http://danml.com/bind/'></script> in head of my HTML file? Do you know why is it not working?

    Thanks

  7. #7
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    i just tested this ok:

    make sure the <script> tag is at the bottom, after the <table> and <object>
    Code:
    
    <html>
    <head></head><body>
    
    <OBJECT id="tdcComposers" CLASSID="clsid:lxw5wyjv-46wm-6lxr-bl9h-yp9avjwcdizk">
    	<PARAM NAME="DataURL" VALUE="https://docs.google.com/spreadsheet/pub?key=0Aptc98y5K95RdGdOaGdubFk2YWh5ZEkxVGNpeFF4clE&output=csv">								  
    	<PARAM NAME="UseHeader" VALUE="True">
    	<param name="Sort" value="-Timestamp" />
    	<PARAM NAME="TextQualifier" VALUE="'">
    </OBJECT>
    
    
    			
    			
    			<TABLE datasrc=#tdcComposers>
    <THEAD><TR>
       <TD>Long Term</TD><TD>Right Now</TD><TD>Date</TD><TD>Comments</TD>
       </TR></THEAD>
    <TBODY>
    <TR>
       <TD><DIV datafld="Long Term"></DIV></TD>
       <TD><DIV datafld="Right Now"></DIV></TD>
       <TD><DIV datafld="Timestamp"></DIV></TD>
       <TD><DIV datafld="What do you think?"></DIV></TD>
    </TR>
    </TBODY>
    </TABLE>
    
    
    <script src="http://danml.com/bind"></script>
    </body></html>
    Last edited by rnd me; 04-14-2013 at 10:34 PM.

  8. #8
    Join Date
    Apr 2013
    Posts
    5
    just put this in my HTML and now your example is working

    Code:
    <script type='text/javascript' src='/bind/jquery.js'></script>	
    <script type='text/javascript' src='/bind/jquery.dataTables.js'></script>	
    <script>
    
    tdcComposers.ready=function(elm) {
        $(elm).dataTable({
            "bPaginate": true,
            "bLengthChange": false,
            "bFilter": true,
            "bSort": true,
            "bInfo": false,
            "bAutoWidth": true
        });
      elm.style.width='100%';
    
    };
    Know why is it necessary? Also, is there a way to display diffrent formatted csv files (with tab or space delimiter... or different delimiters in header and body)?

    Thanks

  9. #9
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by krisbi View Post
    Know why is it necessary? Also, is there a way to display diffrent formatted csv files (with tab or space delimiter... or different delimiters in header and body)?
    i'm not sure exactly what your first question is. datatables like to have the tables filled-in before it runs.

    you could use the events of the TDC to reneder the datatables, but i don't see the exect event you need (on that fires when the table is drawn by TDC).
    the closet one i can see is "datasetcomplete", but that's after the data is fetched and before the table is drawn.
    this is exactly why i like people trying it out and reporting back. I'll add a new ondraw() event tonight, and let you know.
    if you have it working meanwhile, awesome.


    your 2nd question is easier to answer.

    you can use many formats, you just need to define, at most, three things about the data source:

    Code:
    FieldDelim    	<param name="FieldDelim" value="," />Specifies the character used to mark the end of data fields.
    RowDelim    	<param name="RowDelim" value="\n" />Specifies the character used to mark the end of each row.
    TextQualifier	<param name="TextQualifier" value="'" />Specifies the optional character that surrounds a field.
    for a TDF as opposed to CSV, FieldDelim would be "\t", and the others can stay as defaults, not even needing to be included in the <object>.

    thanks for trying it out, i really appreiciete you bearing with me and kicking the tires as i make it better

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles