datawindow 技巧

阅读更多

1、如何复制graph风格的datawindow中的图形到剪切板?

答:dw_1.clipbord("gr_1")

2、如何使用datawindow的查询模式?

答:dw_1.Object.DataWindow.QueryMode='yes'将datawindow改变为查询模式后,接收用户的输入,再使用一下代码获取结果:

dw_1.accepttext()

dw_1.retrieve()

3、如何控制打印横向:

dw_control. O B J E C T.datawindow.print.orientation= 1

29、如何进行预览:

dw_control. O B J E C T.datawindow.print.preview = "yes"

4、如何将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" )

5、保存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

// 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

6、怎样将数据窗口(free格式)中的内容转成word文档

答:给你两个函数:

(1)、辅助函数

integer f_cncharnum (string aString);

//函数名: 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

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

Return li_num

end function

---------------------------------------------------------------

(2)、转到WORD

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

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

long ll_colnum,ll_rownum

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

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

//得到数据窗口数据的列数与行数(行数应该是数据行数 + 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)

string ls_colname

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

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)

constant long wdFormatDocument = 0

SetPointer(oldpointer)

//保存新建的文档

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

end if

//断开OLE连接

Ole_Object.DisConnectObject()

Destroy Ole_Object

return 1

end function

7、字段如何自动换行的同时且自动高度?

答:将数据窗口中相应列的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

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

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

openwithparm(w_waiting,this)

ib_cancel = false

iw_frame.enabled = false

ll_totalstep = ll_rowcount * li_upperbound

w_waiting.uf_register(ll_totalstep)

for li_column = 1 to li_upperbound

ls_width = adw_content.describe(ls_column[li_column]+".width")

li_width = integer(ls_width)

if ls_width='!' or ls_width='?' or li_width=0 then

continue

end if

//ls_temp = adw_content.describe(ls_column[li_column]+".Font.property { = 'width' }")

//messagebox(ls_column[li_column]+".Font.property { = 'width' }",ls_temp)

//return 1

li_fontwidth = 27

li_counter = li_width / li_fontWidth

for ll_row=1 to ll_rowcount

if ib_cancel then

iw_frame.enabled = true

return 0 //pressed cancel button

end if

as_source = adw_content.getitemstring(ll_row,ls_column[li_column])

as_replaced = uf_insertstring(as_source,li_counter,' ',false)

if as_replaced<>as_source then

adw_content.setitem(ll_row,ls_column[li_column],as_replaced)

end if

w_waiting.uf_stepit()

next

next

close(w_waiting)

iw_frame.enabled = true

return 1

8、如何动态外部创建数据窗口?

答:首先制作一个自己想动态得到的数据窗口,然后将该数据窗口导出,看看语法,这样你就了解了这种数据窗口的生成语法了!

---------------------------------------------------------------

dw_1.create()

可以参考帮助以及srd文件(数据窗口导出文件)

---------------------------------------------------------------

动态数据窗创建原理及实现

在实际应用中,经常需要根据用户需求来动态创建数据窗,一般方法是这样的。

在一个window中加入一个数据窗控件,如dw_new,但是该数据窗没有data O B J E C T,(空白的)

就可以用以下语法来创建:

dw_new.create(ls_syntax,ls_error) // 创建语法,错误信息

ls_syntax可以用以下三种方法来形成:

一、动态由sql语法创建:

// 连接到pb的example数据库

string ls_sql,ls_syntax,ls_error

ls_syntax = 'select * from department'

ls_syntax = sqlca.SyntaxFromSQL(ls_sql,'style(type=grid)',ls_error)

if len(ls_error) >0 then

messagebox('Error','SyntaxFromSQL Error:~r'+ls_error)

else

dw_new.create(ls_syntax,ls_error)

if len(ls_error) >0 then

MessageBox("Error", "Create have these errors: ~r" + ls_error)

else

dw_new.settransOBJECT(sqlca)

dw_new.retrieve()

end if

end if

二、由另一个数据窗的syntax来创建

string ls_syntax,ls_error

ls_syntax = dw_test.describe('datawindow.syntax')

dw_new.create(ls_syntax,ls_error)

if ls_error <> '' then

messagebox('Create Error',ls_error)

else

dw_new.settrans O B J E C T(sqlca)

dw_new.retrieve()

end if

三、读取psr文件来创建

样例

string ls_syntax,ls_error,ls_ret

ls_ret = char(13)+char(10) //回车键

int li_fileNum

long li_length

li_FileNum = FileOpen("efef.psr",Streammode!, read!, shared!, Replace!)

// 以下是pb5的代码

if li_filenum >0 then

FileSeek(li_FileNum, 158, FromBeginning!)

li_length = fileRead(li_filenum,ls_syntax)

end if

fileclose(li_filenum)

if li_length = 0 then return

ls_syntax = "release 5;"+ls_ret+ls_syntax

//截掉ls_syntax中的数据部分,5.0以"sparse(names="dept_name?) "作为参考位置

//6.0以html(作为参考位置

long pos1,pos2

pos1 = pos(ls_syntax,'sparse(names="',1)

pos2 = pos(ls_syntax,'"',pos1 +16)

ls_syntax = left(ls_syntax,pos1) + mid(ls_syntax,pos1 +1,pos2 - pos1 +1)

dw_New.create(ls_syntax,ls_error)

if ls_error <> '' then

messagebox('Create Error',ls_error)

else

dw_new.settrans O B J E C T(sqlca)

dw_new.retrieve()

end if

global type f_createextenddw from function_ O B J E C T

end type

forward prototypes

global function string f_createextenddw (ref datawindow dw, string cols[])

end prototypes

global function string f_createextenddw (ref datawindow dw, string cols[]);string sql_dw_general, sql_dw_columns_type, sql_dw_headers_conf, sql_dw_columns_conf, ls_errors

int i

long ll_colcount

string ls_colnametype

string ls_colname,ls_coltype

long ll_pos

ll_colcount = upperbound(cols)

//generals

sql_dw_general = "release 8;" &

+ "datawindow(units=0 timer_interval=0 color=16777215 processing=0 print.documentname=" + char(34) + "" + char(34) + " print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.prompt=no print.buttons=no print.preview.buttons=no )" &

+ "header(height=72 color=" + char(34) + "536870912" + char(34) + " )" &

+ "summary(height=0 color=" + char(34) + "536870912" + char(34) + " )" &

+ "footer(height=0 color=" + char(34) + "536870912" + char(34) + " )" &

+ "detail(height=84 color=" + char(34) + "536870912" + char(34) + " )"

//列及类型

sql_dw_columns_type = "table("

FOR I=1 to ll_colcount

ls_colnametype = trim(cols)

ls_colname = right(ls_colnametype,len(ls_colnametype) - 1)

ls_coltype = left(ls_colnametype,1)

choose case upper(ls_coltype)

case 'C'

ls_coltype = 'char(100)'

case 'D'

ls_coltype = 'date'

case 'N'

ls_coltype = 'decimal(6)'

case else

ls_coltype = 'char(100)'

end choose

//ls_coltype = 'char(100)'

//列及类型

sql_dw_columns_type= sql_dw_columns_type + "column=(type=" +ls_coltype+" updatewhereclause=no name=" + ls_colname + " dbname=" + char(34) + ls_colname + char(34) + " ) "

//列标题

sql_dw_headers_conf = sql_dw_headers_conf + "text(band=header alignment=" + char(34) + "2" + char(34) + " text=" + char(34) + ls_colname + char(34) + " border=" + char(34) + "6" + char(34) + " color=" + char(34) + "16711680" + char(34) + " x=" + char(34) + string( ((i - 1) * 588) + 5) + char(34) + " y=" + char(34) + "4" + char(34) + " height=" + char(34) + "64" + char(34) + " width=" + char(34) + "574" + char(34) + " name=" + ls_colname + "_t font.face=" + char(34) + "Arial" + char(34) + " font.height=" + char(34) + "-10" + char(34) + " font.weight=" + char(34) + "400" + char(34) + " font.family=" + char(34) + "2" + char(34) + " font.pitch=" + char(34) + "2" + char(34) + " font.charset=" + char(34) + "0" + char(34) + " background.mode=" + char(34) + "2" + char(34) + " background.color=" + char(34) + "12632256" + char(34) + " )"

//列属性

sql_dw_columns_conf = sql_dw_columns_conf + "column(band=detail id=" + string(i) + " alignment=" + char(34) + "1" + char(34) + " tabsequence=" + string(i) + "0 border=" + char(34) + "2" + char(34) + " color=" + char(34) + "0" + char(34) + " x=" + char(34) + string( ((i - 1) * 588) + 5) + char(34) + " y=" + char(34) + "4" + char(34) + " height=" + char(34) + "76" + char(34) + " width=" + char(34) + "579" + char(34) + " format=" + char(34) + "[general]" + char(34) + " name=" + ls_colname + " edit.limit=0 edit.case=any edit.autoselect=yes edit.autohscroll=yes font.face=" + char(34) + "Arial" + char(34) + " font.height=" + char(34) + "-10" + char(34) + " font.weight=" + char(34) + "400" + char(34) + " font.family=" + char(34) + "2" + char(34) + " font.pitch=" + char(34) + "2" + char(34) + " font.charset=" + char(34) + "0" + char(34) + " background.mode=" + char(34) + "1" + char(34) + " background.color=" + char(34) + "536870912" + char(34) + " )"

NEXT

sql_dw_columns_type= sql_dw_columns_type + " )"

sql_dw_columns_conf = sql_dw_columns_conf + "htmltable(border=" + char(34) + "1" + char(34) + " cellpadding=" + char(34) + "0" + char(34) + " cellspacing=" + char(34) + "0" + char(34) + " generatecss=" + char(34) + "no" + char(34) + " nowrap=" + char(34) + "yes" + char(34) + ")"

//MESSAGEBOX('',sql_dw_general + sql_dw_columns_type + sql_dw_headers_conf + sql_dw_columns_conf)

dw.Create(sql_dw_general + sql_dw_columns_type + sql_dw_headers_conf + sql_dw_columns_conf , ls_errors)

return(ls_errors)

end function

9、如何让datawindow的heade带区r的内容只打印一次?

答:a、制作两个数据窗口,第一个有表头,第二个没有。

b、用第一个有表头的数据读取数据库中的数据

c、打印有表头的数据窗口中的第一页,记住结束行号

d、将从结束行号开始的所有数据复制到第二个数据窗口中

e、打印第二个数据窗口

10、交叉报表在retrieve后,其datawindow的宽度怎么获得?

答:[PUBLIC] Function wf_settitle_length 在 w_search_report inherited from window

//----------------------------

// 说明:设置表头长度

//----------------------------

// 参数1:[reference] datawindow adw_1

// 说明:报表DW

//--------------------------------------

// 返回: (INTEGER) 成功返回1,不成功返回0

Long Row

String List

string token[]

String tag_1

Integer StartPos = 1, EndPos, Top, i = 1 , index = 0

//取出DW中所有的对象存入token[]中

list = adw_1.Describe("datawindow. O B J E C Ts")

EndPos = pos(list, '~t', StartPos)

Do while ( EndPos > 0 )

token = Mid(list, StartPos, EndPos - StartPos)

i ++

StartPos = EndPos + 1

EndPos = pos(list, '~t', StartPos)

LOOP

token = Mid(list, StartPos)

Top = UpperBound(token[])

//找出最后一列

string ls_lastcol

int li_lastpos=0,li_thispos

For i = 1 to Top

CHOOSE CASE UPPER(adw_1.Describe(token + '.type'))

CASE 'COLUMN','COMPUTE'

li_thispos = integer(adw_1.Describe(token + '.X'))

if li_thispos>=li_lastpos then //这是目前最后一列

li_lastpos=li_thispos

ls_lastcol=token

end if

end choose

NEXT

//设置表头长度

string ls_change

ls_change="800~tlong(describe('"+ls_lastcol+".x')) + long(describe('"+ls_lastcol +".width')) + 10"

//messagebox('',ls_change)

adw_1.modify('title.width="'+ls_change+'"')

return 1

11 如何使光标指向每页第一行?  

long ll_firstrowonpage=long(dw_1.describe("datawindow.firstrowonpage"))

dw_1.scrolltorow(ll_firstrowonpage)

dw_1.setrow(ll_firstrowonpage)

12. 怎样取子数据窗口的总列数 工工 工工工工工工工工工工工工工工工工工工工式 l_column_count=integer(dwc.describe("datawindow.column.count")) //dwc为子窗口

13.在数据窗口过滤以后,计算列值如何才能一起改变?

dw_1.setfilter(filter_condition)

dw_1.filter()

dw_1.groupcalc()

14.怎么改变某一列的背景颜色?

dw_1.Modify("sno.background.mode=2" )

dw_1.Modify ( "sno.background.Color='255'" )

15.在数据窗口中如何delete选中的多行?

Long ll_rows , ll_row

ll_rows=DW_1.RowCount()

for ll_row = ll_rows to 1 step -1

if dw_1.isSelected(ll_row) then

dw_1.DeleteRow(ll_row)

end if

next

16.如何改变列的字体颜色,提醒用户此列已做修改

  在列的Color属性中,输入如下表达式

IF (column_name < >column_name.Original, RGB(255, 0, 0), RGB(0, 0, 0))

17.数据窗口中限定某列不可编辑 用DataWindow的clicked事件中的方法也可以实现列的保护。若

某列不可更改,则可置rotect=0。即:

dw_1.modify("columnname.protect=0")

或dw_1.modify("#"+string(number)+".protect=0")

若要将该列改为可更改,则置protect=1,即:

dw_1.modify(:columnname.protect=1")

或dw_1.modify("#"+string(number)+".protect=1")

此方法不影响Tab键的移动,用户可以随意拉动列,还可在应用过

程中自己决定哪一列可编辑,哪一列不可编辑。

18.怎样去掉上图中数据窗口中的黑影?

this.Modify ("DataWindow.selected.mouse=no")

this.Modify ("DataWindow.Grid.ColumnMove = false")

19 实现逐行增加求和

使用计算列:CumulativeSum(field for all),即可达到逐渐递增求和的功能

20 快速删除多行

方法是把要删除的行从主缓冲区中移到删除缓冲区中。例如,删除缓冲区中所有的行: dw_1.RowsMove(dw_1, 1, dw_1.RowCount, Primary!, dw_1, 1, Delete!)

21、在分组的header上加序号

答:建立计算域,expression:cumulativeSum( If (jlxm = jlxm[-1],0,1) for all)

22、为什么varchar字段类型的列只能保存255个字符?

答:设置事务处理对象的dbparm属性即可

示例:

SQLCA.dbParm = "DBTextLimit = '9999'"

23、点击grid类型数据窗口的header,自动排序。(图片自己做)

/*

*args: i_str_oldcol

*note:实例变量,纪录上次点击的列

*/

string i_str_oldcol

string str_ O B J E C Tname, str_curcol, str_addpic

integer int_pic_x

str_OBJECTname =string (dwo.name) //对象名称

if row = 0 and this.describe(str_OBJEC Tname+".band") = "header" and this.describe(str_OBJEC Tname+".text") <> "!" then //是否点击列对象

str_curcol = left(str_ O B J E C Tname,len(str_ O B J E C Tname) - 2) //当前列对象名称

if str_curcol <> i_str_oldcol then //点击的是不同列对象

this.modify("destroy p_sort") //不管有没有位图对象都删除

i_str_oldcol = str_curcol //保存上次点击的列对象

//画图

int_pic_x = integer(this.describe(str_ O B J E C Tname+".x")) + (integer(this.describe(str_ O B J E C Tname+".width")) - 70)

str_addpic = 'create bitmap(band = foreground filename= "..\pic\up.bmp" x= "'+string(int_pic_x)+'" y= "24" height= "48" width= "48" border= "0" name= p_sort visible= "1")'

this.modify(str_addpic) //动态画个图

this.setsort(str_curcol + " A") //头一次点击当然是升序了

this.sort()

else //当前列已经点过了

if this.describe("p_sort.filename") = "..\pic\up.bmp" then //上次是升序

this.modify("p_sort.filename = '..\pic\down.bmp'")

this.setsort(str_curcol + " D") //这次是降序

else

this.modify("p_sort.filename = '..\pic\up.bmp'")

this.setsort(str_curcol + " A")

end if

this.sort()

end if

end if

24、如何让存储文件目录的列,显示图片?

答:选择对应的column的display as picture属性为true

25、如何复制grid类型的所选择的行的数据到系统剪切板?

答:string ls_selected

ls_selected=dw_1.Object.DataWindow.Selected.Data

clipbord(ls_selected)

26、如何设置的DW底色?

在DW的editsource中改变color的值

27、如何将Grid风格改成自由格式?

在DW的editsource中将processing=1的1改为0

28、要新建一个表A但风格和现有表格B风格一样,怎么将A表快速设置成表B风格?

复制B表C,在C表的DW中的editsource中将表名和字段名改成A表的,即可

29、如何实现gird风格的datawindow的多栏表头?

答:添加 text到header带区,并设置band属性为foreground保存,edit source 修改text的x和width属性表达式如下:

x="100~t integer(describe('firstcol.x')" width="100~tinteger(describe('lastcol.x')) - integer(describe('firstcol.x')) +integer(describe('lastcol.width'))

30、如何过滤dddw编辑风格的显示值为指定值的记录?

答:dw_1.setfilter("lookupdisplay('column_name')='"+ls_display_value_your+"'")

dw_1.filter()

31、如何设置datawindow的某一列为空?

答:string ls_temp[]

setnull(ls_temp)

dw_1.object.columnname.primary.current=ls_temp

32、如何设置datawindow的单双行不同颜色间隔?

答:在detail带区的color属性表达式中写上if(mod (getrow(),2)=1 ,rgb(255,0,0),rgb(0,255,0)),如果是当前行以第三种颜色表示,表达式如下:if(getrow()=current(), rgb(255,0,0),if(mod(getrow(),2)=1 ,rgb(0,0,255),rgb(0,255,0)))

33、如何获取指定名称的datawindowobject?

答:DWObject ldwo_use,ldwo_abc

ldwo_use = dw_1.Object

ldwo_abc = ldwo_use.__get_attribute("t_1",FALSE)//t_1为datawindow中text对象的名称

34、如何缩放datawindow的打印大小?

答:dw_1.object.datawindow.zoom=150 or dw_1.object.datawindow.zoom=75

35、如何在已过滤后的数据基础上对datawindow进行过滤?

答:dw_1.setfilter(dw_1.describe("datawindow.table.filter")+your_join+your_new_filter)

dw_1.filter()

36、如何在datawindow中显示动态时间?

答:建立一个计算域,表达式为string(datetime(today(),now()),'yyyy年mm月dd日 hh点mm分ss秒'),同时设置datawindow的属性dw_1.Object.DataWindow.Timer_Interval=500

37、如何让带用title bar的datawindow控件的标题栏诚活动窗口的颜色?

答:外部函数定义:

funcation logn SetActiveWindow(long hwnd ) Library "user32.dll"

datawindow控件的clicked事件代码:

setactivewindow(handle(this))

38、如何设置datawindow的当前行指示图标?

答:在datawindow中建立一个计算列,expression为'',并将该计算列移动为datawindow的第一个列,在datawindow控件的

rowfocuschanged事件中写入代码:

SetRowFocusIndicator(hand!)或setrowfucsindicator(p_1)//p_1为窗口上的picture控件名

39、如何通过代码打开dddw?

答:定义外部函数引用声明

SUBROUTINE keybd_event( int bVk, int bScan, int dwFlags, int dwExtraInfo) LIBRARY "user32.dll"

代码如下: [constant integer VK_F4 = 115

dw_1.SetFocus()

dw_1.SetColumn( "dept_head_id" ) //设置当前dddw

keybd_event( VK_F4,0,0,0 ) // 按下F4键

keybd_event( VK_F4,0,2,0 ) // 释放F4键

40、如何打印datawindow的内容到文件中?

答: dw_1.object.datawindow.print.fileName ="c:\temp.prn"

dw_1.print()

41、如何设置dddw的初始值?

答:dw_1.object.columnname.Initial="your_initial_value"

42、如何只显示不同的数据?

答:dw_1.filter("isnull(columnname[-1]) and columnname<>columnname[-1]")

dw_1.filter()

43、如何让带有title bar的datawindow不可以移动?

答:在datawindow的自定义事件ue_nchittest(pbm_nchittest)中写入如下代码:

return 1

44、如何在N-UP显示风格中建立基于第N栏中的列的计算列?

答:如column有两列,number和price ,并显示为两栏,则第一栏的cost计算列的expression为number*price,第二栏的cost_1计算列的expression为number[1]*price[1]

45、如何清空ddlb或edit.codetable中项目?

答:dw_1.Object.columnname.Values=""

46、如何实现指定的column的字体旋转90度?

答:dw_1.object.columnname.font.Escapement ="900"

47、如何获取datawindow的sql代码?

答: 可以通过以下四种方法获取sql代码:

string szselect

szselect=dw_1.describe("datawindow.table.select")

szselect=dw_1.describe("datawindow.table.sqlselect")

szselect=dw_1.describe("datawindow.table.select.attribute")

szselect=dw_1.getsqlselect()

48、如何获取datawindow对象占有的虚拟存储的容量?

答:使用datawindow.storage属性

举例:在datawindow控件的retrieverow事件中,写如如下代码:

long lstorage

lstorage=long(dw_1.object.datawindow.storage)

if lstorage>50000 then dbcancel()

49、如何连续在同一张纸打印两个数据窗口?

答:dw_1.object.datawindow.print.filename="temp.prn"

dw_2.object.datawindow.print.filename="temp.prn"

dw_1.print()

dw_2.print()

50、如何设置datawindow分组后每个分组中的记录号?

答:建立一个计算列,expression为 getrow() - first(getrow() for group 1)+1

51、如何实现在datawindow中只有新增的行,才可以编辑?

答:在所有的column的protect属性表达式中写入以下表达式:

if(isrownew(),'0','1')

52、问:怎么让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()

53、如何使dw的列不可移动,不可调整列宽?

答:在datawindow的cilcked事件写 if row=0 then return 1 end if

54.光标跳转到数据窗口的某一行某一列

dw_1.scrolltorow(ll_row) dw_1.setcolumn(ll_column)

55. Grid的窗口如何使第一列固定不动?

①选上data OBJECT的HSplitScroll属性 ②在constructor事件中: dw_1.Object.DataWindow.HorizontalScrollSplit=integer(dw_1.describe("#1.width")) //第一列的宽度 ③在scrollhorizontal事件中: int i

if pane = 1 then

i = integer(this.OBJECT.datawindow.horizontalscrollposition2)

if i < 1 or isnull(i) then return

if scrollpos > 0 then

this.OBJECT.datawindow.horizontalScrollPosition = 0

end if

else

i = integer(this.Object.DataWindow.HorizontalScrollSplit)

if i < 1 or isnull(i) then return

if i > scrollpos then

this.OBJECT.datawindow.horizontalScrollPosition2 = i

end if

end if

把如下代码放在某列的text color里,可实现修改某行某列后,该列变为红色,否则为白色(前景)

If(IsRowModified(), 255, 0)

56、弹出式菜单

//m_module是菜单名

m_module m_newmenu

m_newmenu=create m_module

m_newmenu.popmenu(pointerX(),pointerY())

57、这段代码不用API就可以取IP

Integer lifilenum

String lsbat , lsdat

String lstext,lsip[]

Long i , llfilename

llfilename = 0

Do While True

llfilename ++

lsbat = 'C:\' + String(llfilename) + '.BAT'

If FileExists(lsbat) Then Continue

// If DirectoryExists(lsbat) Then Continue

Exit

Loop

llfilename = 0

Do While True

llfilename ++

lsdat = 'C:\' + String(llfilename) + '.DAT'

If FileExists(lsdat) Then Continue

// If DirectoryExists(lsdat) Then Continue

Exit

Loop

lifilenum = FileOpen(lsbat,linemode!, Write!, lockwrite!, Replace!)

FileWrite(lifilenum,'ipconfig > ' + lsdat)

FileClose(lifilenum)

Run(lsbat,minimized!)

Do While True

Yield()

If FileExists(lsdat) Then Exit

Loop

Do While True

Yield()

lifilenum = FileOpen(lsdat,linemode!)

If lifilenum > 0 Then Exit

Loop

Do While True

Yield()

If FileRead(lifilenum, lstext) = -100 Then

Exit

Else

If Pos(lstext,'IP Address') > 0 Then

lsip[UpperBound(lsip) + 1] = Mid(lstext,Pos(lstext,':') + 1)

End If

End If

Loop

FileClose(lifilenum)

FileDelete(lsbat)

FileDelete(lsdat)

If UpperBound(lsip) = 0 Then

MessageBox('','没有网卡或网络连接未启用!')

Else

For i = 1 To UpperBound(lsip)

MessageBox('IP:'+String(i),lsip)

Next

End If

(

声明win32 API函数:

function int WSAStartup( uint UIVersionRequested, ref s_WSAData lpWSAData ) library "wsock32.dll"

function int WSACleanup() library "wsock32.dll"

function int WSAGetLastError ( ) library "wsock32.dll"

function int gethostname ( ref string name, int namelen ) library "wsock32.dll"

function string GetHost(string lpszhost, ref blob lpszaddress ) library "pbws32.dll"

使用方法:

s_wsadata l_WSAData

string ls_HostName = space(128)

string ls_IpAddress

int li_version = 257

blob{4} lb_hostaddress

IF wsastartup ( li_version, l_WSAData ) = 0 THEN

IF gethostname ( ls_HostName, len(ls_HostName) ) < 0 THEN

messagebox("GetHostName",WSAGetLastError())

ELSE

GetHost(ls_HostName, lb_HostAddress)

ls_IpAddress = string(asc(string(blobmid(lb_HostAddress,1,1))),"000") + "."

ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,2,1))),"000") + "."

ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,3,1))),"000") + "."

ls_IpAddress += string(asc(string(blobmid(lb_HostAddress,4,1))),"000")

END IF

WSACleanup()

ELSE

messagebox("GetHostName",WSAGetLastError())

END IF

sle_1.text=ls_hostname

sle_2.text=ls_ipaddress

)

58、嵌入桌面

Function Ulong FindWindowA(string classname, String windowname) Library "user32.dll"

Function Long SetParent(Long childwin, Long parentwin) Library "user32.dll"

long ll_handle

ll_handle=findwindowa(“Progman”, “Program Manager”)

setparent(handle("我的窗口"),ll_handle)

59、非复合报表中的嵌套报表不可使用getchild取得,也不可使用describe取得属性和使用modify更改属性,你可以调用PB未载入文档的函数来获取/更改属性,请看示例,注意多层嵌套时使用循环获取最终对象.

例:数据窗口控件dw_test包含嵌套报表dw_1,dw_1有栏位dept_name.

dwobject ldwo_parent,ldwo_obj

string ls_color

ldwo_parent = dw_1.object

ldwo_obj = ldwo_parent.__get_attribute("dw_1",false)

ldwo_obj = ldwo_obj.object

ldwo_obj = ldwo_obj.__get_attribute("dept_name",false)

ls_color = ldwo_obj.color//取颜色

ldwo_obj.__set_attribute("color",rgb(192,192,192))//更改颜色

60、EXCEL的内容导入数据窗口

string str_savename,named,s_grxh

int excelok,li_net

long li_count,i

oleobject excelserver

excelserver=create oleobject

excelok=excelserver.connecttonewobject("excel.application")

if excelok<>0 then

messagebox("信息提示","连接excel失败,请检查计算机中是否安装了excel!")

return -1

end if

li_net=getfileopenname("选择文件",str_savename,named,"xls","excel文件(*.xls),*xls")

if li_net>0 then

if str_savename="" then

messagebox("信息提示","没有指定导入文件!")

return -1

else

dw_1.settransobject(sqlca)

dw_1.reset()

excelserver.workbooks.open(str_savename)

excelserver.activesheet.cells.copy

li_count=dw_1.importclipboard(2)

clipboard("")

excelserver.quit()

excelserver.disconnectobject()

cb_2.enabled=true

this.enabled=false

destroy excelserver

return 1

end if

end if

61、PB数据转到EXCEL里面不能求和 pb转过去的都是字符型的 怎么解决!!

ole_object.Worksheets(1).Columns(1).NumberFormat = "@"这个是把一个列,变成字符,"#"是数字

62、让DW中的行单、双行显示不同颜色

if(currentrow()=getrow(),rgb(185,200,255),if(mod(getrow(),2)=1, rgb(255,255,255) , rgb(240,243,255)))

63、满足条件时该列字体显示为红色。

tab_1.tabpage_1.dw_1.Object.czr.Color = "0~tIf(string(zlzq,'yyyy-mm')<=string(today(),'yyyy-mm'),rgb(241,0,51),rgb(0,0,0))"

满足条件时该列背景色为红色

tab_1.tabpage_1.dw_1.modify("djh.background.mode=0")//

tab_1.tabpage_1.dw_1.object.djh.background.color = "0~tif ( string(zlzq,'yyyy-mm')<=string(today(),'yyyy-mm'), rgb(255,0,0), rgb(255,255,255))"

64、按下Insert键时插入一行

//自定义一个PBM_DWNKEY的事件在事件里写(可能有别的简单的方法)

if keydown(keycontrol!) then

if keydown(KeyInsert!) then

//插入一行

dwname.insertrow(0)

end if

end if

65、当某列获得焦点时,光标移动到最后

方法一:

//获得焦点时,按下END键

public Subroutine keybd_event(int bVk,int bScan,ulong dwFlags,ulong dwExtraInfo) LIBRARY "user32.dll"

if dwo.name = "sqr_gzdw" then

keybd_event(35,0,0,0)

end if

方法二:

this.setcolumn("po_gzdw") //让这列先获得焦点

this.selecttext( len(data) + 1,0 ) //再从最后选种0个字符

你可能感兴趣的:(Excel,SQL,C#,C,C++)