我有一个制表符分隔的文本文件,它使用经典ASP页面来读取它并从上到下显示它。这是文本文件:
Email Division Course TotalIncorrect Score DATE_TIME
1steve.perry@gov.gc.ca National BI Course 5 40% 2014-01-23 16:38:55
2sylvie.smith@gov.gc.ca B - H - J - L BI Course 5 100% 2014-01-31 14:56:34
3Jen.peter@gov.gc.ca D - F - K BI Course 5 100% 2014-02-07 18:11:22
4BigJimMcBob@gov.gc.ca National BI Course 5 40% 2014-01-23 16:38:55
5Tony.Montana@gov.gc.ca B - H - J - L BI Course 5 100% 2014-01-31 14:56:34
这是读取txt文件的ASP代码:
<%
Response.CharSet = "UTF-8"
dim import_file,counter,line,fso,objFile
import_file="QuizScores.txt"
counter=0
set fso = createobject("scripting.filesystemobject")
If (fso.FileExists("D:\Vignette\QuizScores.txt"))=true Then
set objFile = fso.opentextfile(server.mappath(import_file))
str_imported_data="<table style='text-align: left; width: 98%; margin-left: 0px; margin-right: auto; font-family: Arial Narrow;' cellpadding='3' cellspacing='2' border='0'>"
Do Until objFile.AtEndOfStream
line = split(objFile.ReadLine, vbTab)
if (counter Mod 2 = 0) And (counter = 0) then
str_imported_data=str_imported_data&"<tr bgcolor='#3C3C3C' style='font-weight: bold; color:white;'>"
Elseif (counter Mod 2 = 0) Then
str_imported_data=str_imported_data&"<tr bgcolor='#EEEEEE'>"
Else
str_imported_data=str_imported_data&"<tr bgcolor='#FFFFE5'>"
end if
counter=counter+1
total_records=ubound(line)
for i=0 to total_records
if ((i=0) or (i=6)) then
str_imported_data=str_imported_data&"<td style='font-weight: bold;'><font size='-1'>"&line(i)&"</td>"
else
str_imported_data=str_imported_data&"<td><font size='-1'>"&line(i)&"</td>"
end if
next
str_imported_data=str_imported_data&"</tr>" & chr(13)
Loop
str_imported_data=str_imported_data&"<caption><b>Project Systems Solution Real Property Course Test Scores</b></caption></table>"
objFile.Close
response.Write str_imported_data
set fso=nothing
Else
Response.Write("Test Scores File does NOT exist.")
End If
%>
我想让asp页面读取txt文件但反转顺序,以便最新的记录显示在表格的顶部,最旧的记录显示在底部。
任何帮助将不胜感激。我是ASP的新手!
由于
这是我的修订版2014年4月1日:
<%
Response.CharSet = "UTF-8"
dim import_file,counter,line,fso,objFile
Dim array_line(), array_column()
import_file="QuizScores.txt"
set fso = createobject("scripting.filesystemobject")
If (fso.FileExists("D:\Vignette\QuizScores.txt")) Then
set objFile = fso.opentextfile(server.mappath(import_file))
counter=0
Do Until objFile.AtEndOfStream
array_line(counter) = objFile.ReadLine
counter=counter+1
Redim Preserve array_line(counter)
Loop
objFile.Close
set fso=nothing
str_imported_data="<table style='text-align: left; width: 98%; margin-left: 0px; margin-right: auto; font-family: Arial Narrow;' cellpadding='3' cellspacing='2' border='0'>"
total_records=ubound(array_line)
for i_row=total_records to 0 step -1
array_column = split(array_line(i_row), vbTab)
if (i_row Mod 2 = 0) And (i_row = 0) then
s_bgcolor = "bgcolor='#3C3C3C' style='font-weight: bold; color:white;'"
Elseif (i_row Mod 2 = 0) Then
s_bgcolor = "bgcolor='#EEEEEE'"
Else
s_bgcolor = "bgcolor='#FFFFE5'"
end if
str_imported_data=str_imported_data & "<tr>" & vbCrLf
for i_col = 0 to 6
if ((i=0) or (i=6)) then
str_imported_data = str_imported_data & "<td " & s_bgcolor & "><font size='-1' style='font-weight: bold;'>" & array_column(i_col) & "</td>" & vbCrLf
else
str_imported_data = str_imported_data & "<td " & s_bgcolor & "><font size='-1'>" & array_column(i_col) & "</td>" & vbCrLf
end if
next 'i_col
str_imported_data = str_imported_data & "</tr>" & vbCrLf & vbCrLf
next 'i_row
str_imported_data = "<caption><b>Project Systems Solution Real Property Course Test Scores</b></caption></table>" & vbCrLf & str_imported_data
response.Write (str_imported_data)
Else
Response.Write("Test Scores File does NOT exist.")
End If
%>
答案 0 :(得分:1)
未经测试但不会有很多错误。 仅供参考:我建议你注意我把事情分开的方式;更可读的代码。 哦,如果内存服务,将“bgcolor”属性放入TR在大多数浏览器中都不起作用,这就是我将它移动到TD的原因。
<%
Response.CharSet = "UTF-8"
dim import_file,counter,line,fso,objFile
import_file="QuizScores.txt"
counter=0
set fso = createobject("scripting.filesystemobject")
If (fso.FileExists("D:\Vignette\QuizScores.txt")) Then
set objFile = fso.opentextfile(server.mappath(import_file))
counter=0
Do Until objFile.AtEndOfStream
array_line(counter) = objFile.ReadLine
counter=counter+1
Loop
objFile.Close
set fso=nothing
str_imported_data="<table style='text-align: left; width: 98%; margin-left: 0px; margin-right: auto; font-family: Arial Narrow;' cellpadding='3' cellspacing='2' border='0'>"
total_records=ubound(array_line)
for i_row=total_records to 0 step -1
array_column = split(array_line(i_row), vbTab)
if (i_row Mod 2 = 0) And (i_row = 0) then
s_bgcolor = "bgcolor='#3C3C3C' style='font-weight: bold; color:white;'"
Elseif (i_row Mod 2 = 0) Then
s_bgcolor = "bgcolor='#EEEEEE'"
Else
s_bgcolor = "bgcolor='#FFFFE5'"
end if
str_imported_data=str_imported_data & "<tr>" & vbCrLf
for i_col = 0 to 6
if ((i=0) or (i=6)) then
str_imported_data = str_imported_data & "<td " & s_bgcolor & "><font size='-1' style='font-weight: bold;'>" & array_column(i_col) & "</td>" & vbCrLf
else
str_imported_data = str_imported_data & "<td " & s_bgcolor & "><font size='-1'>" & array_column(i_col) & "</td>" & vbCrLf
end if
next 'i_col
str_imported_data = str_imported_data & "</tr>" & vbCrLf & vbCrLf
next 'i_row
str_imported_data = "<caption><b>Project Systems Solution Real Property Course Test Scores</b></caption></table>" & vbCrLf & str_imported_data
response.Write (str_imported_data)
Else
Response.Write("Test Scores File does NOT exist.")
End If
%>