VFP 愛用者社區 首頁 VFP 愛用者社區
本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
 
 常見問題常見問題   搜尋搜尋   會員列表會員列表   會員群組會員群組   會員註冊會員註冊 
 個人資料個人資料   登入檢查您的私人訊息登入檢查您的私人訊息   登入登入

report 中如何動態改變Field中的字體列印大小?

 
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區
上一篇主題 :: 下一篇主題  
發表人 內容
小柯



註冊時間: 2003-11-27
文章: 78


第 1 樓

發表發表於: 星期六 八月 24, 2024 9:15 pm    文章主題: report 中如何動態改變Field中的字體列印大小? 引言回覆

請問如標題,當欄位內有六個中文字時,要以16的字體列印,當欄位內有八個中文字時,要以14的字體列印,當欄位內有十個中文字以上時,要以14的字體,並自動換行列印,請問是否有先進指點賜教,謝謝。
因欄位內的中文字串長度不一,當列印時需要將該欄的中文字串限縮在固定的表格框內。
回頂端
檢視會員個人資料 發送私人訊息
syntech



註冊時間: 2003-05-16
文章: 4249
來自: Taipei,Taiwan

第 2 樓

發表發表於: 星期日 八月 25, 2024 12:14 am    文章主題: 引言回覆

以前我們工程師這樣做

用三個text 報表物件疊在一起
一個 fontsize 16,一個 fontsize 14,一個 fontsize 16,且可換行,
然後就是你想辦法找出有多少中文字,
第一個的列印條件就是有六個中文字,
第二個的列印條件就是有八個中文字,
第三個的列印條件就是有大於8個中文字,

也就是同一時間只有一個物件被印出

_________________
如果公司有下列困擾:
1. 找不到便宜,快速,簡易的 生產排程軟體
2. 不知道如何快速排定 採購計劃
3. 成本抓不準,自己算比軟體算有用
4. 想學習系統規劃,想找系統架構的顧問

請聯絡我們,也許我們幫得上忙
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件 AIM Address
小柯



註冊時間: 2003-11-27
文章: 78


第 3 樓

發表發表於: 星期四 八月 29, 2024 9:31 am    文章主題: 引言回覆

感謝 syntech 賜教。
回頂端
檢視會員個人資料 發送私人訊息
foxy



註冊時間: 2007-08-16
文章: 258
來自: 泰國

第 4 樓

發表發表於: 星期四 八月 29, 2024 9:48 am    文章主題: 引言回覆

syntech兄作法很好. 小弟做法如下
按照字串長度把 field SELECT 為3個 field, 在報表上作三個 text 重疊一起, 字體大小不同
SELECT *, cusName as cusName6, cusName as cusName8, cusName as cusName10 from cusinfo into cursor myc nofilter readwrite
replace cusName6 with '' for lenc(allt(cusName6))>6
replace cusName8 with '' for lenc(allt(cusName8))>8 or lenc(allt(cusName8))<=6
replace cusName12 with '' for lenc(allt(cusName8))<=8
report form myReport to preview

_________________
進銷存+生產製造+會計+員工薪資+CRM+POS零售+餐廳手機app+電商手機app+電商網站,物流系統. 正/簡體中文,英,日,泰,緬甸文. MS SQL Server + 前台 VFP + PHP 網站 + Flutter 手機 App, 都共享 MS SQL Server的資料. www.foxacc.com LINE: mike-lm
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件 參觀發表人的個人網站 MSN Messenger
小柯



註冊時間: 2003-11-27
文章: 78


第 5 樓

發表發表於: 星期五 八月 30, 2024 4:49 pm    文章主題: 引言回覆

感謝 foxy 賜教。
回頂端
檢視會員個人資料 發送私人訊息
foxy



註冊時間: 2007-08-16
文章: 258
來自: 泰國

第 6 樓

發表發表於: 星期三 十月 30, 2024 5:11 pm    文章主題: 引言回覆

小弟恰好看到了另外一種作法.
只用一個 TEXT 報表物件, 需要使用 reportListener class 動態改寫顯示該TEXT報表物件, 可以根據條件設定字體大小, 文字顏色和背景顏色, 需要在TEXT報表物件的 Other 頁面的 User Data 裡面輸入相關條件, 例如:
*:EFFECTS FORECOLOR = iif(left(accno,5)='10013', rgb(255, 0, 0), rgb(0, 0, 0))
設定字體顏色
*:EFFECTS FONTSIZE = iif(LEN(ALLT(ACCNO))<=4, 20, iif(LEN(ALLT(ACCNO))>6, 10,14))
根據資料多少設定字體大小

Set REPORTBEHAVIOR 90
m.loListener=createobject('EffectsListener') && 使用下面的 class (define class EffectsListener as _ReportListener of )
m.loListener.outputtype=1
m.loListener.quietmode=1

Report Form myReport To Printer Prompt PREVIEW OBJECT m.loListener

&&&

define class EffectsListener as _ReportListener of ;
home() + 'ffc\_ReportListener.vcx'

oEffectHandlers = .NULL.
&& a collection of effect handlers
dimension aRecords[1]
&&an array of information for each record in the FRX

* Create a collection of effect handler objects and fill it with
* the handlers we know about. A subclass or instance could be
* filled with additional ones.

function Init
dodefault()
_ReportPreview=Alltrim(_Screen.reportpreview_app_name)
with This
.oEffectHandlers = createobject('Collection')
.oEffectHandlers.Add(createobject('DynamicForeColorEffect')) && 設定字體顏色
.oEffectHandlers.Add(createobject('DynamicStyleEffect')) && 設定背景顏色
.oEffectHandlers.Add(createobject('DynamicFontsizeEffect')) && 設定字體大小
endwith
endfunc

* Dimension aRecords to as many records as there are in the FRX so
* we don't have to redimension it as the report runs. The first
* column indicates if we've processed that record in the FRX yet
* and the second column contains a collection of effect handlers
* used to process the record.

function BeforeReport
dodefault()
with This
.SetFRXDataSession()
dimension .aRecords[reccount(), 2]
.ResetDataSession()
endwith
endfunc

* Apply any effects that were requested to the field about to be
* rendered.

function EvaluateContents(tnFRXRecno, toObjProperties)
local loEffectObject, ;
loEffectHandler, ;
lcExpression
with This

* If we haven't already checked if this field needs any effects, do
* so and flag that we have checked it so we don't do it again.

if not .aRecords[tnFRXRecno, 1]
.aRecords[tnFRXRecno, 1] = .T.
.aRecords[tnFRXRecno, 2] = ;
.SetupEffectsForObject(tnFRXRecno)
endif not .aRecords[tnFRXRecno, 1]

* Go through the collection of effect handlers for the field (the
* collection may be empty if the field doesn't need any effects),
* letting each one do its thing.

for each loEffectObject in .aRecords[tnFRXRecno, 2]
loEffectHandler = loEffectObject.oEffectHandler
lcExpression = loEffectObject.cExpression
loEffectHandler.Execute(toObjProperties, lcExpression)
next loEffect
endwith

* Do the normal behavior.

dodefault(tnFRXRecno, toObjProperties)
endfunc

* Go through each effect handler to see if it'll handle the current
* report object. If so, add it to a collection of handlers for the
* object, and return that collection.

function SetupEffectsForObject(tnFRXRecno)
local loFRX, ;
loHandlers, ;
loObject
with This
.SetFRXDataSession()
go tnFRXRecno
scatter memo name loFRX
.ResetDataSession()
loHandlers = createobject('Collection')
for each loEffectHandler in .oEffectHandlers
loObject = loEffectHandler.GetEffect(loFRX)
if vartype(loObject) = 'O'
loHandlers.Add(loObject)
endif vartype(loObject) = 'O'
next loEffectHandler
endwith
return loHandlers
endfunc
enddefine

* Create a class that holds a reference to an effect handler and
* the expression the effect handler is supposed to act on for a
* particular record in the FRX.

define class EffectObject as Custom
oEffectHandler = .NULL.
cExpression = ''
enddefine

* Define an abstract class for effect handler objects.

define class EffectHandler as Custom

* Execute is called by the EvaluateContents method of
* EffectsListener to perform an effect.

function Execute(toObjProperties, toFRX)
endfunc

* GetEffects is called to return an object containing a reference
* to the handler and the expression it's supposed to work on if the
* specified report object needs this effect, or return null if not.

function GetEffect(toFRX)
local loObject
loObject = .NULL.
return loObject
endfunc

* EvaluateExprssion may be called by Execute to evaluate the
* specified expression.

function EvaluateExpression(tcExpression)
return evaluate(tcExpression)
endfunc
enddefine

* Define an abstract class for effect handlers that look for
* "*:EFFECTS <effectname> = <effectexpression>" in the USER memo.

define class UserEffectHandler as EffectHandler
cEffectsDirective = '*:EFFECTS'
&& the directive that indicates an effect is needed
cEffectName = ''
&&; the effect name to look for (filled in in a subclass)

function GetEffect(toFRX)
local lcEffect, ;
laLines[1], ;
lnRow, ;
lcLine, ;
lnPos, ;
loObject
lcEffect = This.cEffectsDirective + ' ' + This.cEffectName
if atc(lcEffect, toFRX.User) > 0
alines(laLines, toFRX.User)
lnRow = ascan(laLines, lcEffect, -1, -1, 1, 13)
lcLine = laLines[lnRow]
lnPos = at('=', lcLine)
loObject = createobject('EffectObject')
loObject.oEffectHandler = This
loObject.cExpression = alltrim(substr(lcLine, lnPos + 1))
else
loObject = .NULL.
endif atc(lcEffect, toFRX.User) > 0
return loObject
ENDFUNC

enddefine

* Define a class to provide dynamic forecolor effects.

define class DynamicForeColorEffect as UserEffectHandler
cEffectName = 'FORECOLOR'

* Evaluate the expression. If the result is a numeric value and
* doesn't match the existing color of the object, change the
* object's color and set the Reload flag to .T.

function Execute(toObjProperties, tcExpression, toFRX)
local lnColor, ;
lnPenRed, ;
lnPenGreen, ;
lnPenBlue
lnColor = This.EvaluateExpression(tcExpression)
if vartype(lnColor) = 'N'
lnPenRed = bitand(lnColor, 0x0000FF)
lnPenGreen = bitrshift(bitand(lnColor, 0x00FF00), Cool
lnPenBlue = bitrshift(bitand(lnColor, 0xFF0000), 16)
if toObjProperties.PenRed <> lnPenRed or ;
toObjProperties.PenGreen <> lnPenGreen or ;
toObjProperties.PenBlue <> lnPenBlue
with toObjProperties
.PenRed = lnPenRed
.PenGreen = lnPenGreen
.PenBlue = lnPenBlue
.Reload = .T.
endwith
endif toObjProperties.PenRed <> lnPenRed ...
endif vartype(lnColor) = 'N'
endfunc
enddefine

define class DynamicBkColorEffect as UserEffectHandler
cEffectName = 'BKCOLOR'

* Evaluate the expression. If the result is a numeric value and
* doesn't match the existing color of the object, change the
* object's color and set the Reload flag to .T.

function Execute(toObjProperties, tcExpression, toFRX)
local lnColor, ;
lnPenRed, ;
lnPenGreen, ;
lnPenBlue
lnColor = This.EvaluateExpression(tcExpression)
if vartype(lnColor) = 'N'
lnPenRed = bitand(lnColor, 0x0000FF)
lnPenGreen = bitrshift(bitand(lnColor, 0x00FF00), Cool
lnPenBlue = bitrshift(bitand(lnColor, 0xFF0000), 16)
if toObjProperties.FillRed <> lnPenRed or ;
toObjProperties.FillGreen <> lnPenGreen or ;
toObjProperties.FillBlue <> lnPenBlue
with toObjProperties
.FillRed = lnPenRed
.FillGreen = lnPenGreen
.FillBlue = lnPenBlue
.Reload = .T.
endwith
endif toObjProperties.PenRed <> lnPenRed ...
endif vartype(lnColor) = 'N'
endfunc
ENDDEFINE

define class DynamicFontSizeEffect as UserEffectHandler
cEffectName = 'FONTSIZE'

* Evaluate the expression. If the result is a numeric value and
* doesn't match the existing color of the object, change the
* object's color and set the Reload flag to .T.

function Execute(toObjProperties, tcExpression, toFRX)
local lnFontSize
m.lnFontSize = This.EvaluateExpression(tcExpression)
if vartype(m.lnFontSize) = 'N'
if toObjProperties.Fontsize <> m.lnFontSize
with toObjProperties
.fontsize = m.lnFontSize
.Reload = .T.
endwith
endif
endif
endfunc
ENDDEFINE
* Define a class to provide dynamic style effects.

define class DynamicStyleEffect as UserEffectHandler
cEffectName = 'STYLE'

* Evaluate the expression. If the result is a numeric value and
* doesn't match the existing style of the object, change the
* object's style and set the Reload flag to .T.

function Execute(toObjProperties, tcExpression, toFRX)
local lnStyle
lnStyle = This.EvaluateExpression(tcExpression)
if vartype(lnStyle) = 'N' and ;
toObjProperties.FontStyle <> lnStyle
toObjProperties.FontStyle = lnStyle
toObjProperties.Reload = .T.
endif vartype(lnStyle) = 'N' ...
endfunc
enddefine

_________________
進銷存+生產製造+會計+員工薪資+CRM+POS零售+餐廳手機app+電商手機app+電商網站,物流系統. 正/簡體中文,英,日,泰,緬甸文. MS SQL Server + 前台 VFP + PHP 網站 + Flutter 手機 App, 都共享 MS SQL Server的資料. www.foxacc.com LINE: mike-lm
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件 參觀發表人的個人網站 MSN Messenger
小賴



註冊時間: 2004-12-27
文章: 476


第 7 樓

發表發表於: 星期五 十一月 01, 2024 10:48 am    文章主題: 引言回覆

如果使用 vfp9.0 應該沒有那麼複雜

借用樓上插圖一用:
圖中(欄位屬性那一張 fiels properties) 頁籤第3頁
不是有一個Dynamics可設定動能列印嗎?
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
foxy



註冊時間: 2007-08-16
文章: 258
來自: 泰國

第 8 樓

發表發表於: 星期一 十一月 04, 2024 5:36 pm    文章主題: 引言回覆

感謝小賴兄指點, 小弟沒有用過這個 Dynamic 的功能, 的確好用
_________________
進銷存+生產製造+會計+員工薪資+CRM+POS零售+餐廳手機app+電商手機app+電商網站,物流系統. 正/簡體中文,英,日,泰,緬甸文. MS SQL Server + 前台 VFP + PHP 網站 + Flutter 手機 App, 都共享 MS SQL Server的資料. www.foxacc.com LINE: mike-lm
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件 參觀發表人的個人網站 MSN Messenger
從之前的文章開始顯示:   
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區 所有的時間均為 台北時間 (GMT + 8 小時)
1頁(共1頁)

 
前往:  
無法 在這個版面發表文章
無法 在這個版面回覆文章
無法 在這個版面編輯文章
無法 在這個版面刪除文章
無法 在這個版面進行投票
無法 在這個版面附加檔案
無法 在這個版面下載檔案


Powered by phpBB © 2001, 2005 phpBB Group
正體中文語系由 phpbb-tw 維護製作