1.如何讓存儲文件目錄的列,顯示圖片? 答:選擇對應的column的display as picture屬性爲true
2、如何複製grid類型的所選擇的行的數據到系統剪切板?
答:string ls_selected
ls_selected=dw_1.Object.DataWindow.Selected.Data
clipboard(ls_selected)
3、如何複製graph風格的datawindow中的圖形到剪切板?
答:dw_1.clipbord("gr_1")
4、如何設置的DW底色?
在DW的editsource中改變color的值
5、如何將Grid風格改成自由格式?
在DW的editsource中將processing=1的1改爲0
6、要新建一個表A但風格和現有表格B風格一樣,怎麼將A錶快速設置成表B風格?
複製B表C,在C表的DW中的editsource中將表名和字段名改成A表的,即可
7、如何實現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'))
8、如何過濾dddw編輯風格的顯示值爲指定值的記錄?
答:dw_1.setfilter("lookupdisplay('column_name')='"+ls_display_value_your+"'")
dw_1.filter()
9、如何設置datawindow的某一列爲空?
答:string ls_temp[]
setnull(ls_temp)
dw_1. O B J E C T.columnname.primary.current=ls_temp
10、如何設置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)))
11、如何獲取指定名稱的datawindow O B J E C T?
答:DWObject ldwo_use,ldwo_abc
ldwo_use = dw_1.Object
ldwo_abc = ldwo_use.__get_attribute("t_1",FALSE)//t_1爲datawindow中text對象的名稱
12、如何使用datawindow的查詢模式?
答:dw_1.Object.DataWindow.QueryMode='yes'將datawindow改變爲查詢模式後,接收用戶的輸入,再使用一下代碼獲取結果:
dw_1.accepttext()
dw_1.retrieve()
13、如何縮放datawindow的打印大小?
答:dw_1. O B J E C T.datawindow.zoom=150 or dw_1. O B J E C T.datawindow.zoom=75
14、如何在已過濾後的數據基礎上對datawindow進行過濾?
答:dw_1.setfilter(dw_1.describe("datawindow.table.filter")+your_join+your_new_filter)
dw_1.filter()
15、如何在datawindow中顯示動態時間?
答:建立一個計算域,表達式爲string(datetime(today(),now()),'yyyy年mm月dd日 hh點mm分ss秒'),同時設置datawindow的屬性dw_1.Object.DataWindow.Timer_Interval=500
16、如何讓帶用title bar的datawindow控件的標題欄誠活動窗口的顏色?
答:外部函數定義:
funcation logn SetActiveWindow(long hwnd ) Library "user32.dll"
datawindow控件的clicked事件代碼:
setactivewindow(handle(this))
17、如何設置datawindow的當前行指示圖標?
答:在datawindow中建立一個計算列,expression爲'',並將該計算列移動爲datawindow的第一個列,在datawindow控件的
rowfocuschanged事件中寫入代碼:
SetRowFocusIndicator(hand!)或setrowfucsindicator(p_1)//p_1爲窗口上的picture控件名
18、如何通過代碼打開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鍵
19、如何打印datawindow的內容到文件中?
答: dw_1. O B J E C T.datawindow.print.fileName ="c:/temp.prn"
dw_1.print()
20、如何設置dddw的初始值?
答:dw_1. O B J E C T.columnname.Initial="your_initial_value"
21、如何只顯示不同的數據?
答:dw_1.filter("isnull(columnname[-1]) and columnname<>columnname[-1]")
dw_1.filter()
22、如何讓帶有title bar的datawindow不可以移動?
答:在datawindow的自定義事件ue_nchittest(pbm_nchittest)中寫入如下代碼:
return 1
23、如何在N-UP顯示風格中建立基於第N欄中的列的計算列?
答:如column有兩列,number和price ,並顯示爲兩欄,則第一欄的cost計算列的expression爲number*price,第二欄的cost_1計算列的expression爲number[1]*price[1]
24、如何清空ddlb或edit.codetable中項目?
答:dw_1.Object.columnname.Values=""
25、如何實現指定的column的字體旋轉90度?
答:dw_1. O B J E C T.columnname.font.Escapement ="900"
26、如何獲取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()
27、如何獲取datawindow對象佔有的虛擬存儲的容量?
答:使用datawindow.storage屬性
舉例:在datawindow控件的retrieverow事件中,寫如如下代碼:
long lstorage
lstorage=long(dw_1. O B J E C T.datawindow.storage)
if lstorage>50000 then dbcancel()
28、如何控制打印橫向:
dw_control. O B J E C T.datawindow.print.orientation= 1
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
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
// done
一般習慣於使用循環來統計數據窗口中處於選中狀態的行數,有沒有更好的方法?
long ll_Selected
long ll_Selected
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()
37、怎樣將數據窗口(free格式)中的內容轉成word文檔
答:給你兩個函數:
(1)、輔助函數
$PBExportHeader$f_cncharnum.srf
$PBExportComments$得到字符串中漢字或者雙字節的個數
global type f_cncharnum from function_ O B J E C T
end type
global function integer f_cncharnum (string aString)
end prototypes
//函數名: f_cncharnum
//用途: 返回一個字符串中漢字的個數
//輸入: aString - string, 給定的字符串
//返回值: li_num - Integer, 給定的字符串中漢字的個數
//注意: 1. 此方法基於漢字的國標漢字庫區位編碼的有效性,不符合此編碼的系統此函數無效!
// 2. 若漢字串含有非漢字字符,如圖形符號或ASCII碼,則這些非漢字字符將保持不變.
//例如: li_ret = f_cncharnum("擺渡人ferryman") li_ret = 3
string ls_SecondSecTable //存放所有國標二級漢字讀音
integer li_num = 0 //返回值
integer i,j
ls_ch = Mid(aString,i,1)
If Asc(ls_ch) >= 128 then //是漢字
li_num++
i = i+1
End if
Next
$PBExportHeader$f_outputtoword_new.srf
global type f_outputtoword_new from function_ O B J E C T
end type
global function integer f_outputtoword_new (datawindow adw)
end prototypes
//函數名: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
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
constant long wdWord9TableBehavior = 1
constant long wdAutoFitFixed = 0
constant long wdCell = 12
string ls_value
pointer oldpointer
long ll_pos,ll_len,ll_num = 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_colnum = ll_num
ll_rownum = adw.rowcount() + 1
ole_ O B J E C T.ActiveDocument.Tables.Add(ole_ O B J E C T.Selection.Range, ll_rownum, ll_colnum)
integer i,j,k
//得到標題頭的名字
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
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)
//保存新建的文檔
if messagebox("保存","文檔已經成功完成,是否保存?",Question!,YesNo!) = 1 then
string docname, named
integer value
ole_ O B J E C T.ActiveDocument.SaveAs(docname, 0,False,"",True,"",False,False,False, False,False)
end if
//斷開OLE連接
Ole_Object.DisConnectObject()
Destroy Ole_Object
end function
答:將數據窗口中相應列的auto horz scroll 爲不選中,選中autosize height
將detail的autosize height選中。在數據窗口retrieve 後調用下面函數即可
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
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
li_upperbound = upperbound(ls_column)
ll_rowcount = adw_content.rowcount()
if li_upperbound<1 or ll_rowcount<1 then return -1
ib_cancel = false
iw_frame.enabled = false
ll_totalstep = ll_r