| 发表于:2007-12-28 09:26:33 楼主 |
vb中读取一个文本中的指定位置的数据到excel中 公司有个取报表的程序....我说下大概流程,从服务器取下数据到本地的一个文本:原始报表.txt 然后点另个按钮执行导入到excel 现在的问题是,如果只是这同一张报表,我只有修改具体的 列数就能取这张报表的任何一个位置的数据,但是,现在需要的是从另张报表里取数,我们称之为b报表:原始报表2.txt ,原始报表2.txt的抬头部分与原始报表.txt的抬头部分有点区别,所以导致原来的程序导入不了~我试着修改...但是还是解决不了~先附上这段点击按钮就 导入excel的程序: private sub command3_click() dim file, linesfromfile, nextline, jm as string dim i, j, k, m, l dim tmp(21) as double dim nyear, nmonth, ndate as integer dim oleexcel as object set oleexcel = createobject("excel.application") oleexcel.visible = false oleexcel.workbooks.open filename:="c:\documents and settings\administrator\桌面\统版报表\定期余额.xls " i = 0 file = "c:\documents and settings\administrator\桌面\统版报表\原始报表.txt" close open file for input as #1 do until eof(1) line input #1, nextline if mid(nextline, 12, 2) = "局名" then '1 (应该是出在这部分,请教下各位这里该怎么改~) n = instr(1, nextline, "年") y = instr(1, nextline, "月") r = instr(1, nextline, "日") ndate = val(mid(nextline, y + 1, r - y - 1)) nyear = val(mid(nextline, n - 4, 4)) nmonth = val(mid(nextline, n + 1, y - n - 1)) 下面还有几部分,主要是循环取n张报表,结尾部分有这样一段,是在上面定位好某张报表后取想要的数据: ... if (trim(mid(nextline, 8, 8)) = "定期合计") and j <> 0 then '3 linesfromfile = trim(mid(nextline, 46, 16)) '4 k = instr(1, linesfromfile, ",") if k > 0 then linesfromfile1 = mid(linesfromfile, 1, k - 1) + mid(linesfromfile, k + 1, len(linesfromfile) - k) end if k = instr(1, linesfromfile1, ",") if k > 0 then linesfromfile = mid(linesfromfile1, 1, k - 1) + mid(linesfromfile1, k + 1, len(linesfromfile1) - k) end if i = i + 1 tmp(j) = val(linesfromfile) / 10000 if tmp(j) > = int(tmp(j)) + 0.5 then tmp(j) = int(tmp(j)) + 1 else tmp(j) = int(tmp(j)) end if ... 另附上2张报表的台头: 原始报表.txt: 局名:临海赤城路储蓄所 2007年12月27日 "局"的列数:12 原始报表2.txt: 局号: 331082901 局名: 临海市邮政局 日期: 2007/12/28 "局号"的列数:11;"局名"的列数:34;"日期"的列数:100 |
|
|
|
|