⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 实现两个数据窗口的合并打印.txt

📁 PB常用技巧 PB常用技巧 PB常用技巧
💻 TXT
字号:
实现两个数据窗口的合并打印
问:我有两个数据窗口,一个主,一个从数据窗口,那我如何才能实现两个数据窗口中的数据在一张纸上打印呢? 

答:数据窗口一般都是打印一个就走一张纸,很难实现同一张纸上打印两个数据窗口,当然也并非完全不可以,但有限制。原理:
第一个DW最好为FREEFORM的风格,第二个DW不能为GRID风格,例如将第一个数据窗口的DETAIL区的一条记录加入到第二个数据窗的HEADER区中,再打印第二个数据窗口,以实现两个数据窗口的合并打印。 

代码: 

//这里用到两个函数f_print_dw()与f_print_dw_describe() 

1、打印按纽代码: 

//将dw_1中数据与dw_2中数据合并打印
f_print_dw(dw_1,dw_2) 

2、f_print_dw(fp_dw_key[datawindow],fp_dw[datawindow])函数说明 

///////////////////////////////
//参数一定要为传址形式       //
//fp_dw_key → reference   //
//fp_dw → reference       //
/////////////////////////////

//fp_dw_key必须为一自由格式的DATAWINDOW
//本函数实现在同一页纸上打印两个DATAWINDOW
//实现方法
//先把一个数据窗口作为文本对象加入到另一个数据窗口中,然后打印,打印完后再恢复数据窗口
string l_attr_list //数据窗口对象的语法 
string l_error
string l_o b j e c t_list // DWO对象列表,以TAB键分开
string l_o b j e c t
int l_new_field
int l_pos, l_start
int l_dw_height // 数据窗口fp_dw中header区的高度
int l_dw_key_height // 数据窗口fp_dw_key中detail区的高度 

l_dw_key_height = integer(fp_dw_key.describe("datawindow.detail.height"))
l_dw_height = integer((fp_dw.describe("datawindow.header.height")))
//增加DW中HEADER区的尺寸,为DW_key上的东西设置空间
//modify()成功返回空字符串
l_error = fp_dw.modify("datawindow.header.height=" + &
string(l_dw_key_height + l_dw_height))
if l_error <> "" then
    l_o b j e c t = "header"
    //发生错误时程序转移
    goto Error_City
end if
//将对象移到DW中的开阔区域
// 取得以TAB字符分离的数据窗口fp_dw中DWO对象的列表
l_o b j e c t_list = fp_dw.describe("datawindow.o b j e c ts")
l_pos = 0
do // 假定列表不为空
    l_start = l_pos
    l_pos = pos(l_o b j e c t_list, "~t", l_start + 1)
    if l_pos = 0 then l_pos = 9999
    l_o b j e c t = mid(l_o b j e c t_list, l_start + 1, l_pos - l_start - 1)
    //将header区的所有对象都向下移
    if fp_dw.describe(l_o b j e c t + ".band") = "header" then
        //行控件比较特殊,它是X1,X2,Y1,Y2
        if fp_dw.describe(l_o b j e c t+".type")="line" then
            fp_dw.modify(l_o b j e c t + ".y1 ='" + &
            string(integer(fp_dw.describe(l_o b j e c t+".y1")) + &
            l_dw_key_height) + "'")
            fp_dw.modify(l_o b j e c t+".y2='" + fp_dw.describe(l_o b j e c t+".y1") +"'") 
        else
            fp_dw.modify(l_o b j e c t + ".y ='" + &
            string(integer(fp_dw.describe(l_o b j e c t+".y")) + &
            l_dw_key_height) + "'")
        end if 
    end if
loop until l_pos = 9999
//把数据窗口fp_dw_key中的对象以TEXT的形式 COPY 到数据窗口fp_dw中的header区
//取得以TAB字符分离的数据窗口fp_dw_key中DWO对象的列表
l_o b j e c t_list = fp_dw_key.describe("datawindow.o b j e c ts")
l_pos = 0 
l_new_field = 0
do // 假定列表不为空
    l_start = l_pos
    l_pos = pos(l_o b j e c t_list, "~t", l_start + 1)
    if l_pos = 0 then l_pos = 9999
    l_o b j e c t = mid(l_o b j e c t_list, l_start + 1, l_pos - l_start - 1)
    l_attr_list = f_print_dw_describe(fp_dw_key, l_o b j e c t)
    if l_attr_list = "" then return false
    l_new_field = l_new_field + 1
    l_error = fp_dw.modify("create text (" + &
    l_attr_list + " name = hdr" + string(l_new_field) + ")") 
    if l_error <> "" then goto Error_City
loop until l_pos = 9999
// 打印
print(fp_dw)
//如果没有打印机,可以将以下部份RETURN TRUE之前的代码屏蔽起来,就可以看到变化后的后果了
// 恢复数据窗口
// 去除新增加的FIELD
//for l_pos = 1 to l_new_field
//    fp_dw.modify("destroy hdr" + string(l_pos))
//next
//// 移动列
//l_o b j e c t_list = fp_dw.describe("datawindow.o b j e c ts")
//l_pos = 0
//do 
//    l_start = l_pos
//    l_pos = pos(l_o b j e c t_list, "~t", l_start + 1)
//    if l_pos = 0 then l_pos = 9999
//    l_o b j e c t = mid(l_o b j e c t_list, l_start + 1, l_pos - l_start - 1)
//    if fp_dw.describe(l_o b j e c t + ".band") = "header" then
//        fp_dw.modify(l_o b j e c t + ".y ='" + &
//        string(integer(fp_dw.describe(l_o b j e c t+".y")) - &
//        l_dw_key_height) + "'")
//    end if
//loop until l_pos = 9999 
//
//// 收宿数据窗口header区
//fp_dw.modify("datawindow.header.height=" + string(l_dw_key_height))
//
return true
////////////////////
Error_City:
    messagebox("Error in col " + l_o b j e c t, l_error)
    return false 

3、f_print_dw_describe(fp_dw[datawindow],fp_col[string]) 

//////////////////////////////////////////////
//fp_dw → reference 传值 //
//fp_col → value 传直 //
// 目的: 描述各列的属性,返回给f_print_dw //
//////////////////////////////////////////////

string l_error
string l_bg_color, l_color, l_fontface, l_height, l_text, l_x, l_y, l_width
string l_fontheight

l_bg_color = fp_dw.describe(fp_col + ".background.color")
if l_bg_color = "!" then
    l_error = "bg_color"
    goto Error_City
end if
l_color = fp_dw.describe(fp_col + ".color")
if l_color = "!" then
    l_error = "color"
    goto Error_City
end if
l_fontface = fp_dw.describe(fp_col + ".font.face")
if l_fontface = "!" then
    l_error = "fontface"
    goto Error_City
end if
l_fontheight = fp_dw.describe(fp_col + ".font.height")
if l_fontface = "!" then
    l_error = "fontheight"
    goto Error_City
end if
l_height = fp_dw.describe(fp_col + ".height")
if l_height = "!" then
    l_error = "height"
    goto Error_City
end if
l_width = fp_dw.describe(fp_col + ".width")
if l_width = "!" then
    l_error = "width"
    goto Error_City
end if
l_x = fp_dw.describe(fp_col + ".x")
if l_x = "!" then
    l_error = "x"
    goto Error_City
end if
l_y = fp_dw.describe(fp_col + ".y")
if l_y = "!" then
    l_error = "y"
    goto Error_City
end if
choose case left(fp_dw.describe(fp_col + ".coltype"), 5)
    case "char("
        l_text = fp_dw.getitemstring(1, fp_col)
    case "datet"
        l_text = string(fp_dw.getitemdatetime(1, fp_col))
    case "numbe"
        l_text = string(fp_dw.getitemnumber(1,(fp_col)))
    case "!" // 假定为text
        l_text = fp_dw.describe(fp_col + ".text")
end choose
l_color = "33554432"
l_bg_color = "1086374080"
return " band = header " + &
" color = '" + l_color + "'" + &
" background.color = '" + l_bg_color + "'" + &
" font.face = '" + l_fontface + "'" + &
" font.height = '" + l_fontheight + "'" + &
" height = '" + l_height + "'" + &
" text = '" + l_text + "'" + &
" width = '" + l_width + "'" + &
" x = '" + l_x + "'" + &
" y = '" + l_y + "'" 

Error_City:
    messagebox("Error in col " + fp_col, l_error)
    return ""



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -