Online Wizard for Converting HTML Table to Delimited Text File

By ServerWatch Staff (Send Email)
Posted Aug 3, 1999


by Jessie Cui
jc@espidotcom.com

This application serves as online wizard to convert HTML table to text file with user specified delimiter. This wizard (T2T wizard) is designed with ASP and DHTML. You may use this wizard to convert html table generated from SQL Server in an internet or an intranet system to text file with a user specified delimiter. A link between SQL Server and an internet/intranet creates real_time and user_defined information from SQL Server. Additionally, webmaster or administrator can save this text file as plain text file for unix system database, since user already specified the delimiter for this file. You can further extend the functionality of this wizard to build a query from database as recordset, (refer to my previous article: Access database on Remote SQL Server ). That enables you to work with multiple tables and views to create your own text report.

  • An architectural overview of T2T wizard:
    table to text file
    This application serves as online wizard to convert HTML table to text file with user specified delimiter. This wizard (T2T wizard) is designed with ASP and DHTML.

  • List of files:


    File Name: File Type: Description:
    1)   default.htm html file (2k) login page to SQL server database
    2)  list.asp asp file  (3k) table list on SQL server database
    3)  tbl_text.asp asp file  (4k) show table data
    4)  sel_delimiter.asp asp file  (4k) DHTML pop window guide you to select delimiter
    5)  funToText.inc server include file  (3k) function to show table and save as text file...
    6) table2text.zip zip file  (6k) first five files in this zip file
     

  • Demo

  • Download    table2text.zip


    list.asp lists all files available to be viewed through browser after successfully login.  Using the server name and databse name submitted by the user, we create  the connection  'on the fly'.

    tbl_text.asp is the main page to get recordset, then retieves data from the recordset and save the data as text file. Firstly we use GetRow() method to put all recordsets into array for quick access. Secondly, this array converted to delimited text file. Finally we Create "Scripting.FileSystemObject" to save this file.

    <!--#INCLUDE FILE="funToText.inc"-->

    <%
    '*************************************************************************
    '* if user click "send" button on sel_delimiter.asp pop window,
    '* then append delimiter as querystring, redirect to tbl_text.txt
    '*************************************************************************
    If Request("send") = "Yes" then
        Set rs = Server.CreateObject("ADODB.Recordset")
        rs.Open session("sql"), session("dsn"),1, , adCmdTable

        dim i, j
        dim arrtext1
        dim arrtext()
        dim fieldcount, recordcount

    arrtext1=rs.getrows() 'arrtext1(fieldcount,recordcount)
    rs.movelast
    fieldcount=rs.Fields.Count
    recordcount=rs.recordcount
        redim preserve arrtext(fieldcount,recordcount+2)
    rs.MoveFirst

        for i= 0 to rs.Fields.Count-1
            arrtext(i,0)=rs.Fields(i).Name
        next

        for i=0 to rs.Fields.Count-1
            for j=1 to recordcount
                arrtext(i,j)=arrtext1(i,j-1) '''note j-1 to get first row
            next
        next
    rs.Close
    Set rs = Nothing
    if request("other")<>"" then
        delimiter=request("other")
    else
        delimiter=request("delimiter")
    end if
    '********************************************************************************************
    '* function totext(ByVal arrtbl, ByVal col, ByVal row, Byval delimiter)
    '* return string
    '* function WriteToTextFile(ByVal strText) accepts the string to write in a file on disk
    '* return true on success
    '********************************************************************************************
        WriteToTextFile(totext(arrtext,fieldcount,recordcount+1, delimiter))
    response.redirect mytext & "?delimiter=" & delimiter
    %>

    <%else%>...

    sel_delimiter.asp is DHTML page that divided page to three layers and navigate user to select delimiter or specify his/her own delimiters for selected table. After users click "send" button, it is closed and the delimiter sent to tbl_text.asp.

  • Page 1 of 1


    Comment and Contribute

    Your name/nickname

    Your email

    (Maximum characters: 1200). You have characters left.