文本文件(文件名为data.20020102)的内容如下:
676 1220 11324991 20714272 0 34138 63550 0 623 1319 14635 24532 0 168 10696 2258 0
0 0 232603 634856 0 503 979 0 0 0 -37 25 0 0 0 0 0
26 80 210381 362909 0 912 1134 0 14 43 355 704 0 4 155 35 0
0 0 1718 16563 0 5 43 0 0 0 0 59 0 0 0 0 0
9 10 238391 285649 0 1852 1899 0 34 43 262 381 0 1 9 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
24 38 3249019 4883903 0 2392 3658 0 0 2 0 153 0 1 20 301 0
现在我需要将他们放在表格中显示出来,那我该怎么做呢?
要求:1、每个数字占用一个单元格;
2、数字0表示不填写该单元格;
3、每行有7个单元格。
万望各位能给予我一点提示,如果能帮我列写出部分代码,我更感激不尽!!!
我的邮箱是: myusa@263.sina.com
谢谢!!!!!!! :)
7 个解决方案
#1
Set fs = CreateObject("Scripting.FileSystemObject")
if fs.fileExists(filepath) then
set tx=fs.openTextFile(filepath)
while not tx.AtEndOfStream
content=content&tx.readline
wend
tx.close
set tx=nothing
end if
result=replace(content," 0 ","</td><td>")
把O当做分界即可
if fs.fileExists(filepath) then
set tx=fs.openTextFile(filepath)
while not tx.AtEndOfStream
content=content&tx.readline
wend
tx.close
set tx=nothing
end if
result=replace(content," 0 ","</td><td>")
把O当做分界即可
#2
很方便的办法,不是么!!我刚做了一个搜索引擎也是采用这种道理!!!
#3
我认为 你可以将数据项用逗号分隔,我看你的文本文件里,共七行数据,每行包括17个数据项!
我现在正在做一个*的统计,我用的方法和你一样,将统计的结果存入文本文件,
统计表中的每行在文本文件中存为一行,每行数据中每个数据项用,隔开!
我做的是按月统计,我看你的好像是按日期,不过差不多!
我这样做的,代码如下:
dim counts(8) '共7行 从counts(1)到counts(7)
dim counttype(8,18) '具体的数据项
for i=0 to 8
for j=0 to 18
counttype(i,j)=0
next
next
set fs=server.CreateObject("Scripting.FileSystemobject")
session("countmonth")=session("counttimeyear") & session("counttimemonth")
set fs=server.CreateObject("Scripting.FileSystemobject")
path="c:\inetpub\wwwroot\lscount\xscountmonth\"
filename=session("countmonth") & ".txt"
counterfilename=path & filename
if not fs.FileExists(counterfilename) then '如果文件不存在
set txtf=fs.CreateTextFile(counterfilename)
... '这里为从库中读取信息,进行统计的代码,我略去了!,只举出第一行,最后的结果如下,用逗号
分隔数据,
counts(1)=cstr(cstr(counttype(1,1)) & "," & cstr(counttype(1,2)) & "," & cstr(counttype(1,3)) &
"," & cstr(counttype(1,4)) & "," & cstr(counttype(1,5)) & "," & cstr(counttype(1,6)) & "," &
cstr(counttype(1,7)) & "," & cstr(counttype(1,8)) & "," & cstr(counttype(1,9)) & "," &
cstr(counttype(1,10)) & "," & cstr(counttype(1,11)) & "," & cstr(counttype(1,12)) & "," &
cstr(counttype(1,13)) & "," & cstr(counttype(1,14)) & "," & cstr(counttype(1,15)) & "," &
cstr(counttype(1,16)) & "," & cstr(counttype(1,17)))
' 最后将统计的结果存入文本文件.
txtf.writeline counts(1)
..........
txtf.writeline counts(7)
txtf.close
else'如果存在,直接从文件中读取值
set txtf=fs.OpenTextFile(counterfilename,1)
'行1
counts(1)=txtf.readline
str1=1
str2=0
for i=1 to 16
str1=instr(str1,counts(1),",")
aa=str1-str2-1
counttype(1,i)=right(left(counts(1),str1-1),aa)
laststr=str1
str2=str1
str1=str1+1
'Response.Write "str1=" & str1
next
counttype(1,17)=right(counts(1),len(counts(1))-laststr)
.....'其他的行同第一行
txtf.close
set txtf=nothing
end if
%>
<%
'然后通过循环打印结果
reponse.wrtie "<table border=1>"
for i=1 to 7
response.write "<tr>"
for j=1 to 17
response.write "<td>" & count(i,j) & "</td>"
next
response.write "</tr>"
next
reponse.wrtie "</table>"
response.write
%>
我现在正在做一个*的统计,我用的方法和你一样,将统计的结果存入文本文件,
统计表中的每行在文本文件中存为一行,每行数据中每个数据项用,隔开!
我做的是按月统计,我看你的好像是按日期,不过差不多!
我这样做的,代码如下:
dim counts(8) '共7行 从counts(1)到counts(7)
dim counttype(8,18) '具体的数据项
for i=0 to 8
for j=0 to 18
counttype(i,j)=0
next
next
set fs=server.CreateObject("Scripting.FileSystemobject")
session("countmonth")=session("counttimeyear") & session("counttimemonth")
set fs=server.CreateObject("Scripting.FileSystemobject")
path="c:\inetpub\wwwroot\lscount\xscountmonth\"
filename=session("countmonth") & ".txt"
counterfilename=path & filename
if not fs.FileExists(counterfilename) then '如果文件不存在
set txtf=fs.CreateTextFile(counterfilename)
... '这里为从库中读取信息,进行统计的代码,我略去了!,只举出第一行,最后的结果如下,用逗号
分隔数据,
counts(1)=cstr(cstr(counttype(1,1)) & "," & cstr(counttype(1,2)) & "," & cstr(counttype(1,3)) &
"," & cstr(counttype(1,4)) & "," & cstr(counttype(1,5)) & "," & cstr(counttype(1,6)) & "," &
cstr(counttype(1,7)) & "," & cstr(counttype(1,8)) & "," & cstr(counttype(1,9)) & "," &
cstr(counttype(1,10)) & "," & cstr(counttype(1,11)) & "," & cstr(counttype(1,12)) & "," &
cstr(counttype(1,13)) & "," & cstr(counttype(1,14)) & "," & cstr(counttype(1,15)) & "," &
cstr(counttype(1,16)) & "," & cstr(counttype(1,17)))
' 最后将统计的结果存入文本文件.
txtf.writeline counts(1)
..........
txtf.writeline counts(7)
txtf.close
else'如果存在,直接从文件中读取值
set txtf=fs.OpenTextFile(counterfilename,1)
'行1
counts(1)=txtf.readline
str1=1
str2=0
for i=1 to 16
str1=instr(str1,counts(1),",")
aa=str1-str2-1
counttype(1,i)=right(left(counts(1),str1-1),aa)
laststr=str1
str2=str1
str1=str1+1
'Response.Write "str1=" & str1
next
counttype(1,17)=right(counts(1),len(counts(1))-laststr)
.....'其他的行同第一行
txtf.close
set txtf=nothing
end if
%>
<%
'然后通过循环打印结果
reponse.wrtie "<table border=1>"
for i=1 to 7
response.write "<tr>"
for j=1 to 17
response.write "<td>" & count(i,j) & "</td>"
next
response.write "</tr>"
next
reponse.wrtie "</table>"
response.write
%>
#4
再有,你可以依照你的意思,用空格分隔数据,只要将代码中的逗号换成空格就可以了!
将最后的循环代码换成下面的,就可过滤掉0
<%
'然后通过循环打印结果
reponse.wrtie "<table border=1>"
for i=1 to 7
response.write "<tr>"
for j=1 to 17
if counttype(i,j)=0 then
response.write "<td>" & "</td>"
else
response.write "<td>" & count(i,j) & "</td>"
next
response.write "</tr>"
next
reponse.wrtie "</table>"
%>
将最后的循环代码换成下面的,就可过滤掉0
<%
'然后通过循环打印结果
reponse.wrtie "<table border=1>"
for i=1 to 7
response.write "<tr>"
for j=1 to 17
if counttype(i,j)=0 then
response.write "<td>" & "</td>"
else
response.write "<td>" & count(i,j) & "</td>"
next
response.write "</tr>"
next
reponse.wrtie "</table>"
%>
#5
用readline读数据,split取得数据
#6
使用ASP读出文本文件并显示
使用ASP读出文本文件并显示
读取一个文本文件并写出 Sun Aug 2 06:34:07 1998
(注:textStream有关写的METHOD
Write(STRING)
WriteLine(STRING)
WriteBlankLines(LINES)
)
这是一个完整的程序
〈 html 〉
〈 head 〉
〈 http-equiv="Content-Type" content="text/html; charset=gb2312" 〉
〈 title 〉〈 /title 〉
〈 /head 〉
〈 body 〉
< % LANGUAGE = VBScript % >
< %
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim filename
filename = "test.txt" ’缺省相对路径是c:winnt
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filename)
Set readf = f.OpenAsTextStream(ForReading,TristateFalse)
’第一个参数可选。输入/输出模式,是下列三个常数之一:
’ ForReading=1只读、ForWriting=2 可读写或 ForAppending=3追加
’第二个参数也为可选。三个 Tristate 值之一,
’ 指出以何种格式打开文件。忽略此参数,则文件以 ASCII
’格式打开。 TristateUseDefault=-2 以系统默认格式打开文件、
’TristateTrue=-1 以 Unicode 格式打开文件或TristateFalse=0
’以 ASCII 格式打开文件。
’也可用OpenTextFile方法打开文件
s = readf.ReadLine
Do While readf.AtEndOfLine <> True
s = readf.ReadLine
Response.write s & "" ’逐行读文件并写出
Loop
readf.close
% >
< /body>
< /html>
这样就可以将文本文件读出并显示了。
使用ASP读出文本文件并显示
读取一个文本文件并写出 Sun Aug 2 06:34:07 1998
(注:textStream有关写的METHOD
Write(STRING)
WriteLine(STRING)
WriteBlankLines(LINES)
)
这是一个完整的程序
〈 html 〉
〈 head 〉
〈 http-equiv="Content-Type" content="text/html; charset=gb2312" 〉
〈 title 〉〈 /title 〉
〈 /head 〉
〈 body 〉
< % LANGUAGE = VBScript % >
< %
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim filename
filename = "test.txt" ’缺省相对路径是c:winnt
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filename)
Set readf = f.OpenAsTextStream(ForReading,TristateFalse)
’第一个参数可选。输入/输出模式,是下列三个常数之一:
’ ForReading=1只读、ForWriting=2 可读写或 ForAppending=3追加
’第二个参数也为可选。三个 Tristate 值之一,
’ 指出以何种格式打开文件。忽略此参数,则文件以 ASCII
’格式打开。 TristateUseDefault=-2 以系统默认格式打开文件、
’TristateTrue=-1 以 Unicode 格式打开文件或TristateFalse=0
’以 ASCII 格式打开文件。
’也可用OpenTextFile方法打开文件
s = readf.ReadLine
Do While readf.AtEndOfLine <> True
s = readf.ReadLine
Response.write s & "" ’逐行读文件并写出
Loop
readf.close
% >
< /body>
< /html>
这样就可以将文本文件读出并显示了。
#7
谢谢大家!!!
呜呜呜。。。大伙这么热情,让我真是太感动了,谢谢!!!!!!
呜呜呜。。。大伙这么热情,让我真是太感动了,谢谢!!!!!!
#1
Set fs = CreateObject("Scripting.FileSystemObject")
if fs.fileExists(filepath) then
set tx=fs.openTextFile(filepath)
while not tx.AtEndOfStream
content=content&tx.readline
wend
tx.close
set tx=nothing
end if
result=replace(content," 0 ","</td><td>")
把O当做分界即可
if fs.fileExists(filepath) then
set tx=fs.openTextFile(filepath)
while not tx.AtEndOfStream
content=content&tx.readline
wend
tx.close
set tx=nothing
end if
result=replace(content," 0 ","</td><td>")
把O当做分界即可
#2
很方便的办法,不是么!!我刚做了一个搜索引擎也是采用这种道理!!!
#3
我认为 你可以将数据项用逗号分隔,我看你的文本文件里,共七行数据,每行包括17个数据项!
我现在正在做一个*的统计,我用的方法和你一样,将统计的结果存入文本文件,
统计表中的每行在文本文件中存为一行,每行数据中每个数据项用,隔开!
我做的是按月统计,我看你的好像是按日期,不过差不多!
我这样做的,代码如下:
dim counts(8) '共7行 从counts(1)到counts(7)
dim counttype(8,18) '具体的数据项
for i=0 to 8
for j=0 to 18
counttype(i,j)=0
next
next
set fs=server.CreateObject("Scripting.FileSystemobject")
session("countmonth")=session("counttimeyear") & session("counttimemonth")
set fs=server.CreateObject("Scripting.FileSystemobject")
path="c:\inetpub\wwwroot\lscount\xscountmonth\"
filename=session("countmonth") & ".txt"
counterfilename=path & filename
if not fs.FileExists(counterfilename) then '如果文件不存在
set txtf=fs.CreateTextFile(counterfilename)
... '这里为从库中读取信息,进行统计的代码,我略去了!,只举出第一行,最后的结果如下,用逗号
分隔数据,
counts(1)=cstr(cstr(counttype(1,1)) & "," & cstr(counttype(1,2)) & "," & cstr(counttype(1,3)) &
"," & cstr(counttype(1,4)) & "," & cstr(counttype(1,5)) & "," & cstr(counttype(1,6)) & "," &
cstr(counttype(1,7)) & "," & cstr(counttype(1,8)) & "," & cstr(counttype(1,9)) & "," &
cstr(counttype(1,10)) & "," & cstr(counttype(1,11)) & "," & cstr(counttype(1,12)) & "," &
cstr(counttype(1,13)) & "," & cstr(counttype(1,14)) & "," & cstr(counttype(1,15)) & "," &
cstr(counttype(1,16)) & "," & cstr(counttype(1,17)))
' 最后将统计的结果存入文本文件.
txtf.writeline counts(1)
..........
txtf.writeline counts(7)
txtf.close
else'如果存在,直接从文件中读取值
set txtf=fs.OpenTextFile(counterfilename,1)
'行1
counts(1)=txtf.readline
str1=1
str2=0
for i=1 to 16
str1=instr(str1,counts(1),",")
aa=str1-str2-1
counttype(1,i)=right(left(counts(1),str1-1),aa)
laststr=str1
str2=str1
str1=str1+1
'Response.Write "str1=" & str1
next
counttype(1,17)=right(counts(1),len(counts(1))-laststr)
.....'其他的行同第一行
txtf.close
set txtf=nothing
end if
%>
<%
'然后通过循环打印结果
reponse.wrtie "<table border=1>"
for i=1 to 7
response.write "<tr>"
for j=1 to 17
response.write "<td>" & count(i,j) & "</td>"
next
response.write "</tr>"
next
reponse.wrtie "</table>"
response.write
%>
我现在正在做一个*的统计,我用的方法和你一样,将统计的结果存入文本文件,
统计表中的每行在文本文件中存为一行,每行数据中每个数据项用,隔开!
我做的是按月统计,我看你的好像是按日期,不过差不多!
我这样做的,代码如下:
dim counts(8) '共7行 从counts(1)到counts(7)
dim counttype(8,18) '具体的数据项
for i=0 to 8
for j=0 to 18
counttype(i,j)=0
next
next
set fs=server.CreateObject("Scripting.FileSystemobject")
session("countmonth")=session("counttimeyear") & session("counttimemonth")
set fs=server.CreateObject("Scripting.FileSystemobject")
path="c:\inetpub\wwwroot\lscount\xscountmonth\"
filename=session("countmonth") & ".txt"
counterfilename=path & filename
if not fs.FileExists(counterfilename) then '如果文件不存在
set txtf=fs.CreateTextFile(counterfilename)
... '这里为从库中读取信息,进行统计的代码,我略去了!,只举出第一行,最后的结果如下,用逗号
分隔数据,
counts(1)=cstr(cstr(counttype(1,1)) & "," & cstr(counttype(1,2)) & "," & cstr(counttype(1,3)) &
"," & cstr(counttype(1,4)) & "," & cstr(counttype(1,5)) & "," & cstr(counttype(1,6)) & "," &
cstr(counttype(1,7)) & "," & cstr(counttype(1,8)) & "," & cstr(counttype(1,9)) & "," &
cstr(counttype(1,10)) & "," & cstr(counttype(1,11)) & "," & cstr(counttype(1,12)) & "," &
cstr(counttype(1,13)) & "," & cstr(counttype(1,14)) & "," & cstr(counttype(1,15)) & "," &
cstr(counttype(1,16)) & "," & cstr(counttype(1,17)))
' 最后将统计的结果存入文本文件.
txtf.writeline counts(1)
..........
txtf.writeline counts(7)
txtf.close
else'如果存在,直接从文件中读取值
set txtf=fs.OpenTextFile(counterfilename,1)
'行1
counts(1)=txtf.readline
str1=1
str2=0
for i=1 to 16
str1=instr(str1,counts(1),",")
aa=str1-str2-1
counttype(1,i)=right(left(counts(1),str1-1),aa)
laststr=str1
str2=str1
str1=str1+1
'Response.Write "str1=" & str1
next
counttype(1,17)=right(counts(1),len(counts(1))-laststr)
.....'其他的行同第一行
txtf.close
set txtf=nothing
end if
%>
<%
'然后通过循环打印结果
reponse.wrtie "<table border=1>"
for i=1 to 7
response.write "<tr>"
for j=1 to 17
response.write "<td>" & count(i,j) & "</td>"
next
response.write "</tr>"
next
reponse.wrtie "</table>"
response.write
%>
#4
再有,你可以依照你的意思,用空格分隔数据,只要将代码中的逗号换成空格就可以了!
将最后的循环代码换成下面的,就可过滤掉0
<%
'然后通过循环打印结果
reponse.wrtie "<table border=1>"
for i=1 to 7
response.write "<tr>"
for j=1 to 17
if counttype(i,j)=0 then
response.write "<td>" & "</td>"
else
response.write "<td>" & count(i,j) & "</td>"
next
response.write "</tr>"
next
reponse.wrtie "</table>"
%>
将最后的循环代码换成下面的,就可过滤掉0
<%
'然后通过循环打印结果
reponse.wrtie "<table border=1>"
for i=1 to 7
response.write "<tr>"
for j=1 to 17
if counttype(i,j)=0 then
response.write "<td>" & "</td>"
else
response.write "<td>" & count(i,j) & "</td>"
next
response.write "</tr>"
next
reponse.wrtie "</table>"
%>
#5
用readline读数据,split取得数据
#6
使用ASP读出文本文件并显示
使用ASP读出文本文件并显示
读取一个文本文件并写出 Sun Aug 2 06:34:07 1998
(注:textStream有关写的METHOD
Write(STRING)
WriteLine(STRING)
WriteBlankLines(LINES)
)
这是一个完整的程序
〈 html 〉
〈 head 〉
〈 http-equiv="Content-Type" content="text/html; charset=gb2312" 〉
〈 title 〉〈 /title 〉
〈 /head 〉
〈 body 〉
< % LANGUAGE = VBScript % >
< %
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim filename
filename = "test.txt" ’缺省相对路径是c:winnt
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filename)
Set readf = f.OpenAsTextStream(ForReading,TristateFalse)
’第一个参数可选。输入/输出模式,是下列三个常数之一:
’ ForReading=1只读、ForWriting=2 可读写或 ForAppending=3追加
’第二个参数也为可选。三个 Tristate 值之一,
’ 指出以何种格式打开文件。忽略此参数,则文件以 ASCII
’格式打开。 TristateUseDefault=-2 以系统默认格式打开文件、
’TristateTrue=-1 以 Unicode 格式打开文件或TristateFalse=0
’以 ASCII 格式打开文件。
’也可用OpenTextFile方法打开文件
s = readf.ReadLine
Do While readf.AtEndOfLine <> True
s = readf.ReadLine
Response.write s & "" ’逐行读文件并写出
Loop
readf.close
% >
< /body>
< /html>
这样就可以将文本文件读出并显示了。
使用ASP读出文本文件并显示
读取一个文本文件并写出 Sun Aug 2 06:34:07 1998
(注:textStream有关写的METHOD
Write(STRING)
WriteLine(STRING)
WriteBlankLines(LINES)
)
这是一个完整的程序
〈 html 〉
〈 head 〉
〈 http-equiv="Content-Type" content="text/html; charset=gb2312" 〉
〈 title 〉〈 /title 〉
〈 /head 〉
〈 body 〉
< % LANGUAGE = VBScript % >
< %
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim filename
filename = "test.txt" ’缺省相对路径是c:winnt
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filename)
Set readf = f.OpenAsTextStream(ForReading,TristateFalse)
’第一个参数可选。输入/输出模式,是下列三个常数之一:
’ ForReading=1只读、ForWriting=2 可读写或 ForAppending=3追加
’第二个参数也为可选。三个 Tristate 值之一,
’ 指出以何种格式打开文件。忽略此参数,则文件以 ASCII
’格式打开。 TristateUseDefault=-2 以系统默认格式打开文件、
’TristateTrue=-1 以 Unicode 格式打开文件或TristateFalse=0
’以 ASCII 格式打开文件。
’也可用OpenTextFile方法打开文件
s = readf.ReadLine
Do While readf.AtEndOfLine <> True
s = readf.ReadLine
Response.write s & "" ’逐行读文件并写出
Loop
readf.close
% >
< /body>
< /html>
这样就可以将文本文件读出并显示了。
#7
谢谢大家!!!
呜呜呜。。。大伙这么热情,让我真是太感动了,谢谢!!!!!!
呜呜呜。。。大伙这么热情,让我真是太感动了,谢谢!!!!!!