set talk off hh1=printstatus() set print on do while .not.hh1 "打印机未准备好,请准备好打印机" hh1=printstatus() enddo set talk off set device to print clear a1=getfile("dbf") &&打开打开文件对话框 use "&a1" &&打开指定的文件 n1=fcount() &&获取打开的库中的字段数 dimension a(n1) &&定义一个存放字段名的数组 dimension b(n1) &&定义一个存放字段宽度的数组 k=1 do while k<=n1 a(k)=field(k) k=k+1 enddo &&将字段名赋给数组 w=1 do while w<=n1 b(w)=fsize(a(w)) &&获取字段的长度 if b(w)<6 b(w)=8 else b(w)=b(w)+2 endif w=w+1 enddo do while not eof() r1=1 &&显示表头的第一行 m=1 col1=1 do while m<=n1 if m=1 @r1,col1 say "┌"+replicate("-",b(m)) else if m=n1 @r1,col1 say "┬"+replicate("-",b(m))+"┐" else @r1,col1 say "┬"+replicate("-",b(m)) endif endif col1=col1+b(m) m=m+1 enddo
m=1 &&显示字段名行 col1=1 do while m<=n1 if m=1 @r1+1,col1 say "∣"+substr(a(m),1,6)+replicate(" ",(b(m)-len(a(m)))) else if m=n1 @r1+1,col1 say "∣"+substr(a(m),1,6)+replicate(" ",(b(m)-len(substr(a(m),1,6))))+"∣" else @r1+1,col1 say "∣"+substr(a(m),1,6)+replicate(" ",(b(m)-len(substr(a(m),1,6)))) endif endif col1=col1+b(m) m=m+1 enddo m=1 &&由于字段多,一行不能完全显示整个行,因此分为两行显示字段名行 col1=1 do while m<=n1 if m=1 @r1+2,col1 say "∣"+substr(a(m),7) else if m=n1 @r1+2,col1 say "∣"+substr(a(m),7)+replicate(" ",(b(m)-len(substr(a(m),7))))+"∣" else @r1+2,col1 say "∣"+substr(a(m),7) endif endif col1=col1+b(m) m=m+1 enddo m=1 &&显示字段名下面的一行表格线 col1=1 do while m<=n1 if m=1 @r1+3,col1 say "├"+replicate("-",b(m)) else if m=n1 @r1+3,col1 say "┼"+replicate("-",b(m))+"┤" else @r1+3,col1 say "┼"+replicate("-",b(m)) endif endif col1=col1+b(m) m=m+1 enddo
row1=r1+4 do while .not.eof() &&每页显示20个记录 m=1 &&显示各记录的值 col1=1 do while m<=n1 if type(a(m))="C" if m=1 @row1,col1 say "∣"+&a(m) else if m=n1 @row1,col1 say "∣"+alltrim(&a(m))+replicate(" ",(b(m)-len(alltrim(&a(m)))))+"∣" else @row1,col1 say "∣"+&a(m) endif endif else if m=1 @row1,col1 say "∣"+str(&a(m)) else if m=n1 @row1,col1 say "∣"+alltrim(str(&a(m)))+replicate(" ",(b(m)-len(alltrim(str(&a(m))))))+"∣" else @row1,col1 say "∣"+alltrim(str(&a(m))) endif endif endif col1=col1+b(m) m=m+1 enddo SKIP if eof() &&显示数据库结束的最后一行 m=1 col1=1 do while m<=n1 if m=1 @row1+1,col1 say "└"+replicate("-",b(m)) else if m=n1 @row1+1,col1 say "┴"+replicate("-",b(m))+"┘" else @row1+1,col1 say "┴"+replicate("-",b(m)) endif endif col1=col1+b(m) m=m+1 enddo h=".f." exit else if r1=20 &&显示每一页的最后一行 m=1 col1=1 do while m<=n1 if m=1 @row1+1,col1 say "└"+replicate("-",b(m)) else if m=n1 @row1+1,col1 say "┴"+replicate("-",b(m))+"┘" else @row1+1,col1 say "┴"+replicate("-",b(m)) endif endif col1=col1+b(m) m=m+1 enddo r1=1 eject exit else m=1 &&显示每个记录下面的一行表格线 col1=1 do while m<=n1 if m=1 @row1+1,col1 say "├"+replicate("-",b(m)) else if m=n1 @row1+1,col1 say "┼"+replicate("-",b(m))+"┤" else @row1+1,col1 say "┼"+replicate("-",b(m)) endif endif col1=col1+b(m) m=m+1 enddo endif ENDIF row1=row1+2 r1=r1+1 enddo && 每页显示20个记录到此 enddo set print off set device to screen set talk on return |