2007年6月21日 星期四

如何將繁體Crystal Report(*.RPT)檔轉成簡體?

如何將繁體Crystal Report(*.RPT)檔轉成簡體?

請先準備:
1. Hokoy.WordKit.dll
(http://reg.softking.com.tw/freeware/index.asp?fid1=3&fid2=260&fid3=22195)
2. Crystal Report 正式版 (或安裝Crystal Translator Demo 版)
(http://www.softlang.com/download.htm)
3. Unicode 補完計畫 2.50
(http://uao.cpatch.org/index.php?%E4%B8%8B%E8%BC%89)

參考文件:
Integrating Crystal Reports with Visual FoxPro
(http://www.craigberntson.com/Articles/kb014.htm)

作法:
1. 先用 "RegSvr32" 註冊Hokoy.WordKit.dll.
2. 如果有用到Unicode請安裝 Unicode補完計畫.

VFP8.0 程式範例:
(http://roxsu.tw.googlepages.com/rpt_tran.zip)

*** 用TCtoSC將 D:\RPT\*.RPT(Unicode繁體字)
*** 轉到D:\RPTS\*.RPT(Unicode簡體字)


Set Safety Off
Set Exact On
If Rpl_unicode("D:\RPT\", "D:\RPTS\")
Messagebox("Transfer OK!!")
Endif
Set Safety On

Function Rpl_unicode
Para wic, wicnew

olebig=Createobject('Hokoy.WordKit')

*!* 函式名稱 參數形式 傳回值形式
*!* GBtoBig5 GB Big5
*!* BIG5toGB Big5 GB
*!* GBtoUnicode GB Unicode
*!* Big5toUnicode Big5 Unicode
*!* UnicodetoGB Unicode GB
*!* UnicodetoBig5 Unicode Big5
*!* SCtoTC Unicode簡體字 Unicode繁體字
*!* TCtoSC Unicode繁體字 Unicode簡體字

Local LLC,MTXT,CTMP, MRPL
Local oCR As CRAXDRT.Application
Local oRpt As CRAXDRT.Report

If Para()<>2
=Messagebox('error',48,'error of path!!')
Return .F.
Endif

getfilenum=Adir(getfiles,wic+'*.rpt')
For ii=1 To getfilenum
Wait Wind 'process Prog: '+getfiles[ii,1] At 8,35 Nowait
*-------------------
oCR = Createobject("CrystalRuntime.Application")
oRpt = oCR.OpenReport(wic+ getfiles[ii,1])
For jj=1 To oRpt.Areas.Count
For kk=1 To oRpt.Areas.Item(jj).Sections.Count
For ll=1 To oRpt.Areas.Item(jj).Sections.Item(kk).ReportObjects.Count
yy = oRpt.Areas.Item(jj).Sections.Item(kk).ReportObjects.Item(ll)
If yy.Kind=2 && text obj
v_objn =0
v_hasobj=.F. && has obj in text?
*---------------save text - obj to array --------------------
If yy.FieldElements.Count>0
v_objn=yy.FieldElements.Count
v_hasobj=.T.
Dimension txtobj(v_objn,3)
For pp=1 To v_objn
txtobj(pp,1)=yy.FieldElements.Item(pp).FieldDefinition
txtobj(pp,3)=yy.FieldElements.Item(pp).Font.bold && 儲存BOLD狀態
Endfor
Endif
*---------------save text - obj to array -------------------
m.MTXT=Alltrim(yy.Text)
m.MRPL=m.MTXT && for replace
If Len(m.MRPL) > 0 && 一次轉換繁體->簡體UNICODE
v_uncode = olebig.TCtoSC(m.MRPL)
m.MRPL = v_uncode
Endif
If v_hasobj
*---------------save text - obj to text --------------------
For pp=1 To v_objn
txtobj(pp,2)=Atcc('[]',m.MRPL,pp) && 因為ADD用中文算字數所以用ATCC
Endfor
m.MRPL=Strtran(m.MRPL, '[]', '')
oRpt.Areas.Item(jj).Sections.Item(kk).ReportObjects.Item(ll).settext(m.MRPL)
For pp=1 To v_objn
yy.FieldElements.Add(txtobj(pp,2),txtobj(pp,1))
yy.FieldElements.Item(pp).Font.bold = txtobj(pp,3)
Endfor
*---------------save text - obj to text -------------------
Else
oRpt.Areas.Item(jj).Sections.Item(kk).ReportObjects.Item(ll).settext(m.MRPL)
Endif
oRpt.Areas.Item(jj).Sections.Item(kk).ReportObjects.Item(ll).Font.Name="SimSun"
If v_hasobj && bold 字型設定後才有效
For pp=1 To v_objn
yy.FieldElements.Item(pp).Font.bold = txtobj(pp,3)
Endfor
Endif
Endif
If yy.Kind=1
oRpt.Areas.Item(jj).Sections.Item(kk).ReportObjects.Item(ll).Font.Name="SimSun"
Endif
Endfor
Endfor
Endfor
oRpt.Save(Trim(wicnew)+ Alltrim(getfiles[ii,1]))
Endfor
Return .T.
Endfunc