數(shù)據(jù)庫報表程序是經(jīng)常使用的,現(xiàn)在很多用戶都使用報表設(shè)計器設(shè)計報表,且簡單方便;但筆者在工作中遇到要對成百個數(shù)據(jù)庫打印的情況,這些數(shù)據(jù)庫除了字段名不相同外,其他結(jié)構(gòu)信息基本相同,因此筆者就編制了如下的一個通用程序,供同行參考。
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() &&獲取打開的庫中的字段數(shù)
dimension a(n1) &&定義一個存放字段名的數(shù)組
dimension b(n1) &&定義一個存放字段寬度的數(shù)組
k=1
do while k<=n1
a(k)=field(k)
k=k+1
enddo &&將字段名賦給數(shù)組
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
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() &&獲取打開的庫中的字段數(shù)
dimension a(n1) &&定義一個存放字段名的數(shù)組
dimension b(n1) &&定義一個存放字段寬度的數(shù)組
k=1
do while k<=n1
a(k)=field(k)
k=k+1
enddo &&將字段名賦給數(shù)組
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