www.webdeveloper.com
Results 1 to 2 of 2

Thread: Table Rows and Columns

  1. #1
    Join Date
    Nov 2009
    Posts
    3

    Table Rows and Columns

    Hi,
    I am trying to read a text file and place in a table, found some script on google, but this is limited to five columns, my text file may have more than 5 columns and many rows and this can change from time to time.

    results.txt
    ABC, 123, 234, xyz, ttt, 1000, 2000
    C, 123, 234, xyz, ttt, 1000, 2000
    BC, 123, 234, xyz, ttt, 1000, 2000
    d, 123, 234, xyz, ttt, 1000, 2000


    also sometime the columns are separted by " and sometimes just a blank space.

    Please can someone help.



    Code:
    <div id="foo"><--INCLUDE FILE HERE--></div>
    <script type="text/JavaScript">
    onload= function(){
    var d=document.getElementById("foo").innerHTML.split(/\s+/)
    document.getElementById("foo").innerHTML=table_mak er(5,d);
    }
    function table_maker(columns,array){
    var txt="<TABLE cellpadding=1 cellspacing=1 border=1>"
    var rows=Math.ceil(array.length/columns);
    for(var r=0,t=0;r<rows;r++){
    txt+="<TR>"
    for(var c=0;c<columns;c++){
    txt+="<TD>"+array[t++]+"</TD>"
    }
    txt+="</TR>"
    }
    txt+="</TR></TABLE>"
    return txt;
    }
    </script>

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,252
    Are you trying to parse a CSV type file?

    In a particular line, how will you know to create a column of a table using the (space) or the (comma) or the (quote) column separator? Is there a rule you can follow or is it that you don't care in the table creation?

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