'convert a text file into a HTML table, supply filename and cell delimiter (e.g. CSV files use ",") 'Assumes that rows end in MSDOS type endline and headings have no internal endlines (but are allowed in other cells) Function txt2htmltab(iflnm As String, delim As String) As Boolean Dim str As String, buf As String, x As Long, ostr As String, endl As String, delims As Long Dim str2 As String, cls As Long, ok As Integer, dl As Long txt2htmltab = False endl = "" + Chr(13) + Chr(10) + "" dl = Len(delim) - 1 Open iflnm For Binary Access Read As #1 buf = String(FileLen(iflnm), " ") Get #1, , buf Close 1 'create output file with .htm extension x = InStr(iflnm, ".") str = Left(iflnm, x) + "htm" Open str For Binary Access Write As #2 str = "" + Chr(13) + Chr(10) + "" Put #2, , str 'set out headings of table - no endlines in headings x = InStr(buf, endl) str = Left(buf, x - 1) buf = Right(buf, Len(buf) - x - 1) cls = 0 Do While 1 x = InStr(str, delim) If x = 0 Then ostr = "" Put #2, , ostr 'chop string into chunks using delimiter ok = 1 Do While ok x = InStr(str, delim) If x = 0 Then ostr = str ok = 0 Else ostr = Left(str, x - 1) str = Right(str, Len(str) - (x + dl)) End If If Len(ostr) = 0 Then ostr = "-" End If ostr = "
" + iflnm + "
" + str Put #2, , ostr Exit Do End If cls = cls + 1 ostr = Left(str, x - 1) str = Right(str, Len(str) - x) ostr = "" + ostr Put #2, , ostr Loop Put #2, , endl Do While 1 'get string that holds cls categories worth (uses delimit character) delims = 0 Do While delims < cls x = InStr(x + 1, buf, delim) delims = delims + 1 Loop If x <> 0 Then x = InStr(x, buf, endl) 'find end of row Else x = InStr(buf, endl) End If If x <> 0 Then str = Left(buf, x - 1) buf = Right(buf, Len(buf) - x - 1) Else 'EOF Exit Do End If ostr = "
" + ostr Put #2, , ostr Loop Put #2, , endl Loop ostr = "
" Put #2, , ostr Close txt2htmltab = True End Function