29、如何进行预览:
dw_control. O B J E C T.datawindow.print.preview = "yes"
30、如何连续在同一张纸打印两个数据窗口?
答:dw_1. O B J E C T.datawindow.print.filename="temp.prn"
dw_2. O B J E C T.datawindow.print.filename="temp.prn"
dw_1.print()
dw_2.print()
31、如何将pb9.0 的datawindow转化为pb 8.0版本的datawindow?
答:edit source 将release 9;改为release 8;
并删除以下内容:
print.printername=""
print.canusedefaultprinter=yes
print.cliptext=no print.overrideprintjob=no
hidegrayline=no
encodeselflinkargs="1"
export.xml(headgroups="1" includewhitespace="0" metadatatype=0 savemetadata=0 )
import.xml()
export.pdf(method=0 distill.custompostscript="0" xslfop.print="0" )
32、如何设置datawindow分组后每个分组中的记录号?
答:建立一个计算列,expression为 getrow() - first(getrow() for group 1)+1
33、如何实现在datawindow中只有新增的行,才可以编辑?
答:在所有的column的protect属性表达式中写入以下表达式:
if(isrownew(),'0','1')
34、保存datawindow数据到excel中
// ... Init docname
// ... GetFileOpenName or any other method
dw_control. O B J E C T.datawindow.print.preview = "yes"
30、如何连续在同一张纸打印两个数据窗口?
答:dw_1. O B J E C T.datawindow.print.filename="temp.prn"
dw_2. O B J E C T.datawindow.print.filename="temp.prn"
dw_1.print()
dw_2.print()
31、如何将pb9.0 的datawindow转化为pb 8.0版本的datawindow?
答:edit source 将release 9;改为release 8;
并删除以下内容:
print.printername=""
print.canusedefaultprinter=yes
print.cliptext=no print.overrideprintjob=no
hidegrayline=no
encodeselflinkargs="1"
export.xml(headgroups="1" includewhitespace="0" metadatatype=0 savemetadata=0 )
import.xml()
export.pdf(method=0 distill.custompostscript="0" xslfop.print="0" )
32、如何设置datawindow分组后每个分组中的记录号?
答:建立一个计算列,expression为 getrow() - first(getrow() for group 1)+1
33、如何实现在datawindow中只有新增的行,才可以编辑?
答:在所有的column的protect属性表达式中写入以下表达式:
if(isrownew(),'0','1')
34、保存datawindow数据到excel中
// ... Init docname
// ... GetFileOpenName or any other method
if dw_1.SaveAs(docname, HTMLTable!, True) = -1 then
MessageBox("Warning", "Unable to export data. Error writing to file!", Exclamation!)
return
end if
MessageBox("Warning", "Unable to export data. Error writing to file!", Exclamation!)
return
end if
// Convert HTML file to Excel native format
OLEObject excel
excel = CREATE OLEObject
if excel.ConnectToObject(docname) = 0 then
excel.application.DisplayAlerts = FALSE
excel.application.workbooks(1).Parent.Windows(excel.application.workbooks(1).Name).Visible = True
excel.application.workbooks(1).saveas(docname, 39)
excel.application.workbooks(1).close()
end if
DESTROY excel
// done
// done
35、除了循环以外,有没有更好的方法统计数据窗口中处于选中状态的行数?
一般习惯于使用循环来统计数据窗口中处于选中状态的行数,有没有更好的方法?
一般习惯于使用循环来统计数据窗口中处于选中状态的行数,有没有更好的方法?
其实此问题在应用上用处不大,讨论一下,活跃一下思维还是有好处的。
方法一:
long ll_Selected
long ll_Selected
ll_Selected = long(dw_1.describe("evaluate('sum( if(IsSelected(), 1, 0) for all)',1)"))
方法二:
long ll_Selected
long ll_Selected
ll_Selected = long(dw_1.describe("evaluate('count(IsSelected() for all)',1)"))
方法三:
upperbound(dw_1.Object.Data.Selected)
36、问:怎么让PB只打印当前记录,是用Free格式制作的数据窗口!
upperbound(dw_1.Object.Data.Selected)
36、问:怎么让PB只打印当前记录,是用Free格式制作的数据窗口!
答:
DataStore ldt_temp
long ll_Row , ll_Rows
ll_Rows = dw_XX.Rowcount()
If ll_Rows = 0 Then GoTo the_end
If ll_Rows = 1 Then
dw_XX.Print()
GoTo the_end
End if
dw_XX.SetRedraw(False)
ldt_temp = Create DataStore
ldt_temp.DataObject = dw_XX.DataObject
ll_Row = dw_XX.GetRow()
dw_XX.RowsMove(1 , ll_Rows , Primary! , ldt_temp , 1 , Primary!)
ldt_temp.RowsMove(ll_Row , ll_Row , Primary! , dw_XX , 1 , Primary!)
dw_XX.Print()
dw_XX.RowsMove(1 , 1 , Primary! , ldt_temp , ll_Row , Primary!)
ldt_temp.RowsMove(1 , ll_Rows , Primary! , dw_XX , 1 , Primary!)
Destroy ldt_temp
dw_XX.SetRedraw(True)
the_end:
//只用将上述脚本拷入到打印部分即可,dw_XX为被打印的free型数据窗口,该方法可保证dw_XX中的数据在打印前后包括sort等属性均不发生任何改变,但效率较低,不宜用在数据量太大的数据窗口中,当然,考虑到打印本身速度就比较慢,所以3000行数据是可以采用这种方法并让用户接受的。若在同一窗口上存在与dw_XX共享的grid数据窗口并且与dw_XX同时显示,则需要与dw_one一起SetRedraw()
DataStore ldt_temp
long ll_Row , ll_Rows
ll_Rows = dw_XX.Rowcount()
If ll_Rows = 0 Then GoTo the_end
If ll_Rows = 1 Then
dw_XX.Print()
GoTo the_end
End if
dw_XX.SetRedraw(False)
ldt_temp = Create DataStore
ldt_temp.DataObject = dw_XX.DataObject
ll_Row = dw_XX.GetRow()
dw_XX.RowsMove(1 , ll_Rows , Primary! , ldt_temp , 1 , Primary!)
ldt_temp.RowsMove(ll_Row , ll_Row , Primary! , dw_XX , 1 , Primary!)
dw_XX.Print()
dw_XX.RowsMove(1 , 1 , Primary! , ldt_temp , ll_Row , Primary!)
ldt_temp.RowsMove(1 , ll_Rows , Primary! , dw_XX , 1 , Primary!)
Destroy ldt_temp
dw_XX.SetRedraw(True)
the_end:
//只用将上述脚本拷入到打印部分即可,dw_XX为被打印的free型数据窗口,该方法可保证dw_XX中的数据在打印前后包括sort等属性均不发生任何改变,但效率较低,不宜用在数据量太大的数据窗口中,当然,考虑到打印本身速度就比较慢,所以3000行数据是可以采用这种方法并让用户接受的。若在同一窗口上存在与dw_XX共享的grid数据窗口并且与dw_XX同时显示,则需要与dw_one一起SetRedraw()
37、怎样将数据窗口(free格式)中的内容转成word文档
答:给你两个函数:
(1)、辅助函数
$PBExportHeader$f_cncharnum.srf
$PBExportComments$得到字符串中汉字或者双字节的个数
global type f_cncharnum from function_ O B J E C T
end type
forward prototypes
global function integer f_cncharnum (string aString)
end prototypes
global function integer f_cncharnum (string aString)
end prototypes
global function integer f_cncharnum (string aString);
//函数名: f_cncharnum
//用途: 返回一个字符串中汉字的个数
//输入: aString - string, 给定的字符串
//返回值: li_num - Integer, 给定的字符串中汉字的个数
//注意: 1. 此方法基于汉字的国标汉字库区位编码的有效性,不符合此编码的系统此函数无效!
// 2. 若汉字串含有非汉字字符,如图形符号或ASCII码,则这些非汉字字符将保持不变.
//例如: li_ret = f_cncharnum("摆渡人ferryman") li_ret = 3
//函数名: f_cncharnum
//用途: 返回一个字符串中汉字的个数
//输入: aString - string, 给定的字符串
//返回值: li_num - Integer, 给定的字符串中汉字的个数
//注意: 1. 此方法基于汉字的国标汉字库区位编码的有效性,不符合此编码的系统此函数无效!
// 2. 若汉字串含有非汉字字符,如图形符号或ASCII码,则这些非汉字字符将保持不变.
//例如: li_ret = f_cncharnum("摆渡人ferryman") li_ret = 3
string ls_ch //临时单元
string ls_SecondSecTable //存放所有国标二级汉字读音
integer li_num = 0 //返回值
integer i,j
string ls_SecondSecTable //存放所有国标二级汉字读音
integer li_num = 0 //返回值
integer i,j
For i = 1 to Len(aString)
ls_ch = Mid(aString,i,1)
If Asc(ls_ch) >= 128 then //是汉字
li_num++
i = i+1
End if
Next
ls_ch = Mid(aString,i,1)
If Asc(ls_ch) >= 128 then //是汉字
li_num++
i = i+1
End if
Next
Return li_num
end function
---------------------------------------------------------------
(2)、转到WORD
$PBExportHeader$f_outputtoword_new.srf
global type f_outputtoword_new from function_ O B J E C T
end type
$PBExportHeader$f_outputtoword_new.srf
global type f_outputtoword_new from function_ O B J E C T
end type
forward prototypes
global function integer f_outputtoword_new (datawindow adw)
end prototypes
global function integer f_outputtoword_new (datawindow adw)
end prototypes
global function integer f_outputtoword_new (datawindow adw);
//函数名:f_outputtoword_new
//输入: adw - datawindow,指定的数据窗口
//返回值: Integer
constant integer ppLayoutBlank = 12
OLEObject ole_ O B J E C T
ole_ O B J E C T = CREATE OLEObject
//函数名:f_outputtoword_new
//输入: adw - datawindow,指定的数据窗口
//返回值: Integer
constant integer ppLayoutBlank = 12
OLEObject ole_ O B J E C T
ole_ O B J E C T = CREATE OLEObject
integer li_ret
li_ret = ole_ O B J E C T.ConnectToObject("","word.application")
IF li_ret <> 0 THEN
//如果Word还没有打开,则新建。
li_ret = ole_ O B J E C T.ConnectToNewObject("word.application")
if li_ret <> 0 then
MessageBox('OLE错误','OLE无法连接!错误号:' + string(li_ret))
return 0
end if
ole_ O B J E C T.Visible = True
END IF
IF li_ret <> 0 THEN
//如果Word还没有打开,则新建。
li_ret = ole_ O B J E C T.ConnectToNewObject("word.application")
if li_ret <> 0 then
MessageBox('OLE错误','OLE无法连接!错误号:' + string(li_ret))
return 0
end if
ole_ O B J E C T.Visible = True
END IF
long ll_colnum,ll_rownum
constant long wdWord9TableBehavior = 1
constant long wdAutoFitFixed = 0
constant long wdCell = 12
string ls_value
pointer oldpointer
constant long wdWord9TableBehavior = 1
constant long wdAutoFitFixed = 0
constant long wdCell = 12
string ls_value
pointer oldpointer
oldpointer = SetPointer(HourGlass!)
string ls_ O B J E C Ts,ls_obj,ls_objs[],ls_objtag[]
long ll_pos,ll_len,ll_num = 0
long ll_pos,ll_len,ll_num = 0
ls_ O B J E C Ts = trim(adw.Describe('datawindow.Objects'))
do while (pos(ls_ O B J E C Ts,"~t") > 0)
ll_pos = pos(ls_ O B J E C Ts,"~t")
ll_len = ll_pos - 1
ls_obj = left(ls_ O B J E C Ts,ll_len)
if (adw.Describe(ls_obj + '.type') = 'column' or &
adw.Describe(ls_obj + '.type') = 'compute') and &
(adw.Describe(ls_obj + '.band') = 'detail') and (ls_obj <> "asd") then
ll_num += 1
ls_objs[ll_num] = ls_obj
ls_objtag[ll_num] = adw.Describe(ls_obj + '.tag')
end if
ls_ O B J E C Ts = right(ls_ O B J E C Ts,len(ls_ O B J E C Ts) - ll_pos)
loop
ll_pos = pos(ls_ O B J E C Ts,"~t")
ll_len = ll_pos - 1
ls_obj = left(ls_ O B J E C Ts,ll_len)
if (adw.Describe(ls_obj + '.type') = 'column' or &
adw.Describe(ls_obj + '.type') = 'compute') and &
(adw.Describe(ls_obj + '.band') = 'detail') and (ls_obj <> "asd") then
ll_num += 1
ls_objs[ll_num] = ls_obj
ls_objtag[ll_num] = adw.Describe(ls_obj + '.tag')
end if
ls_ O B J E C Ts = right(ls_ O B J E C Ts,len(ls_ O B J E C Ts) - ll_pos)
loop
//得到数据窗口数据的列数与行数(行数应该是数据行数 + 1)
ll_colnum = ll_num
ll_rownum = adw.rowcount() + 1
ll_colnum = ll_num
ll_rownum = adw.rowcount() + 1
ole_ O B J E C T.Documents.Add()
ole_ O B J E C T.ActiveDocument.Tables.Add(ole_ O B J E C T.Selection.Range, ll_rownum, ll_colnum)
ole_ O B J E C T.ActiveDocument.Tables.Add(ole_ O B J E C T.Selection.Range, ll_rownum, ll_colnum)
string ls_colname
integer i,j,k
integer i,j,k
for i = 1 to ll_colnum
//得到标题头的名字
ls_value = ls_objtag
ole_ O B J E C T.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_ O B J E C T.Selection.TypeBackspace()
next
ole_ O B J E C T.Selection.MoveRight(wdCell)
next
//得到标题头的名字
ls_value = ls_objtag
ole_ O B J E C T.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_ O B J E C T.Selection.TypeBackspace()
next
ole_ O B J E C T.Selection.MoveRight(wdCell)
next
adw.setredraw(false)
ole_ O B J E C T.Selection.MoveLeft(wdCell)
string column_name
for i = 2 to ll_rownum
for j = 1 to ll_colnum
column_name = ls_objs[j]
if adw.Describe(column_name + '.type') = 'column' then
ls_value = adw.Describe("Evaluate('LookupDisplay("+column_name+")',"+string(i - 1)+")")
end if
if adw.Describe(column_name + '.type') = 'compute' then
ls_value = adw.Describe("Evaluate('" + adw.Describe(column_name + '.expression') + "',"+string(i - 1)+")")
end if
ole_ O B J E C T.Selection.MoveRight(wdCell)
ole_ O B J E C T.Selection.TypeText(ls_value)
//for k = 1 to f_cncharnum(ls_value)
//ole_ O B J E C T.Selection.TypeBackspace()
//next
next
next
adw.setredraw(true)
ole_ O B J E C T.Selection.MoveLeft(wdCell)
string column_name
for i = 2 to ll_rownum
for j = 1 to ll_colnum
column_name = ls_objs[j]
if adw.Describe(column_name + '.type') = 'column' then
ls_value = adw.Describe("Evaluate('LookupDisplay("+column_name+")',"+string(i - 1)+")")
end if
if adw.Describe(column_name + '.type') = 'compute' then
ls_value = adw.Describe("Evaluate('" + adw.Describe(column_name + '.expression') + "',"+string(i - 1)+")")
end if
ole_ O B J E C T.Selection.MoveRight(wdCell)
ole_ O B J E C T.Selection.TypeText(ls_value)
//for k = 1 to f_cncharnum(ls_value)
//ole_ O B J E C T.Selection.TypeBackspace()
//next
next
next
adw.setredraw(true)
constant long wdFormatDocument = 0
SetPointer(oldpointer)
//保存新建的文档
if messagebox("保存","文档已经成功完成,是否保存?",Question!,YesNo!) = 1 then
string docname, named
integer value
//保存新建的文档
if messagebox("保存","文档已经成功完成,是否保存?",Question!,YesNo!) = 1 then
string docname, named
integer value
value = GetFileSaveName("选择文件",docname, named, "DOC","Doc Files (*.DOC), *.DOC")
IF value = 1 THEN
ole_ O B J E C T.ActiveDocument.SaveAs(docname, 0,False,"",True,"",False,False,False, False,False)
end if
ole_ O B J E C T.ActiveDocument.SaveAs(docname, 0,False,"",True,"",False,False,False, False,False)
end if
end if
//断开OLE连接
Ole_Object.DisConnectObject()
Destroy Ole_Object
//断开OLE连接
Ole_Object.DisConnectObject()
Destroy Ole_Object
return 1
end function
end function
38、字段如何自动换行的同时且自动高度?
答:将数据窗口中相应列的auto horz scroll 为不选中,选中autosize height
将detail的autosize height选中。在数据窗口retrieve 后调用下面函数即可
答:将数据窗口中相应列的auto horz scroll 为不选中,选中autosize height
将detail的autosize height选中。在数据窗口retrieve 后调用下面函数即可
uf_set_text(datawindow adw_content,string
as_columns,boolean,ab_ignoreblank)
/*************************************************************
describe: 在数据窗口adw_content中,在as_columns中包含的列中插入空格
args:
as_columns 要操作的多个列,列间用逗号隔开
*************************************************************/
if (not isvalid(adw_content)) or isnull(as_columns) or len(as_columns)<1 or isnull(ab_ignoreblank) then return -1
as_columns,boolean,ab_ignoreblank)
/*************************************************************
describe: 在数据窗口adw_content中,在as_columns中包含的列中插入空格
args:
as_columns 要操作的多个列,列间用逗号隔开
*************************************************************/
if (not isvalid(adw_content)) or isnull(as_columns) or len(as_columns)<1 or isnull(ab_ignoreblank) then return -1
n_cst_string lnv_string
string ls_column[] , ls_width ,as_source,as_replaced ,ls_temp
int li_upperbound , li_width , li_column , li_fontWidth, li_counter
long ll_rowcount , ll_row , ll_totalstep
int li_yield
string ls_column[] , ls_width ,as_source,as_replaced ,ls_temp
int li_upperbound , li_width , li_column , li_fontWidth, li_counter
long ll_rowcount , ll_row , ll_totalstep
int li_yield
lnv_string.of_parsetoarray(as_columns,',',ls_column)
li_upperbound = upperbound(ls_column)
ll_rowcount = adw_content.rowcount()
if li_upperbound<1 or ll_rowcount<1 then return -1
li_upperbound = upperbound(ls_column)
ll_rowcount = adw_content.rowcount()
if li_upperbound<1 or ll_rowcount<1 then return -1
openwithparm(w_waiting,this)
ib_cancel = false
iw_frame.enabled = false
ll_totalstep = ll_r
ib_cancel = false
iw_frame.enabled = false
ll_totalstep = ll_r