最近一个项目中需要水晶报表打印Invoice,在汇总金额的同时要把金额转换为英文表示,最开始的时候客户需求是只在Invoice最后一页总汇总的时候才需要显示英文,所以当被直接在.net中转好英文,然后再在数据源xsd设置多一个英文字段传到报表中。使用一段时间后客户要求每一页Invoice需要汇总英文,麻烦来了,如果要传参数法,将不能确定水晶报表分几页也没法传不固定参数,于是直接在水晶报表中写了转换方法,需要这样要求的朋友可以自己改改
1.在水晶报表中建立一个转换方法 DecimalToWords
Function (numbervar decimals)
local stringVar array _smallNumbers := ["ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT",
"NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN",
"SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN"];
local stringVar array _tens := ["", "", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"];
local stringVar array _scaleNumers := ["", "THOUSAND", "MILLION", "BILLION" ];
stringVar combined := _smallNumbers[1];
if decimals <> 0 then
(
numberVar i := 1;
numberVar array digitGroups := [0,0,0,0];
for i := 1 to 4 step 1 do
(
digitGroups[i] := decimals mod 1000;
decimals := Int(decimals / 1000);
);
stringVar array groupText := ["","","",""];
for i:=1 to 4 step 1 do
(
numberVar hundreds := Int(digitGroups[i] / 100);
numberVar tensUnits := digitGroups[i] mod 100;
if hundreds <> 0 then
(
groupText[i] := groupText[i] + _smallNumbers[hundreds+1] + " HUNDRED";
if tensUnits <> 0 then
groupText[i] := groupText[i] + " ";
);
numberVar tens := Int(tensUnits / 10);
numberVar units := tensUnits mod 10;
if tens >= 2 then
(
groupText[i] := groupText[i] + _tens[tens+1];
if units <> 0 then
groupText[i] := groupText[i] + "-" + _smallNumbers[units+1];
)
else if tensUnits <> 0 then
groupText[i] := groupText[i] + _smallNumbers[tensUnits +1]
);
combined := groupText[1];
for i:=2 to 4 step 1 do
(
if digitGroups[i] <> 0 then
(
stringVar prefix := groupText[i] + " " + _scaleNumers[i];
if Length(combined) <> 0 then
prefix := prefix+ " ";
combined := prefix + combined;
);
);
);
combined;
2.然后在水晶报表中建一个 公式字段 TotalEg
DecimalToWords ({#Total}) //其中Total是个汇总字段
3.把上一步建的公式字段TotalEg拖到报表需要的位置