顯示具有 Crystal Report 標籤的文章。 顯示所有文章
顯示具有 Crystal Report 標籤的文章。 顯示所有文章

2017年2月11日 星期六

於 .Net 4.5 使用 Crystal Report 的注意事項

最近接了一個定時抓資料產生報表的案子,想說應該很容易,沒想到卻因為 Crystal Report 的問題卡關了一整天

症狀是這樣的:服務一啟動就發生 1067 錯誤

2017-02-11_164847

看事件檢視器中的錯誤訊息是 System.IO.FileNotFoundException,但是卻不知道是哪個檔案找不到

2017-02-11_165040

卡了好幾個小時之後,轉個方向,改成用 Console 程式來產生報表,結果一跑就看到問題發生的原因了,是找不到這個檔案 "C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll"

可是根本就沒有這個目錄,怎麼可能找得到檔案呢?

2017-02-11_165541

把這個路徑拿去 google,一搜馬上就有結果了,原來要在 App.config 的 startup 節加上 useLegacyV2RuntimeActivationPolicy="true" 這個屬性。

也就是把
<startup>
改成
<startup useLegacyV2RuntimeActivationPolicy="true">

改好之後,重新建置,執行,果然正常了。
為免遺忘,特記述於此。

2011年12月15日 星期四

Crystal Report 9 以後適用的“拆解長字串成多行”函數

//
// 將長字串拆解成數行,中間用 CR+LF 分開
// Crystal Report 9 以後適用
//
StringVar s := {要拆解的欄位};                // 要拆解的字串
StringVar output := '';                     // 輸出字串
NumberVar CharsInALine := 20;               // 一行幾個字
NumberVar currLength := 0;
while Length(s) > 0 do
(
  // 這只是很粗略的判斷,假定使用者只會輸入半形英數字跟中文字,
  //
不會使用半形的特殊符號,如半形日文假名
  if AscW(s) > 256 then
  (   
    currLength := currLength + 2;           // 中文字,長度 + 2
  )
  else
  (
    currLength := currLength + 1;           // 文數字,長度 + 1
  );
  output := output + s[1];
  if currLength >= CharsInALine then
  (
    output := output + Chr(13) + Chr(10);
    currLength := 0;
  );
  s := Mid(s, 2);
);
output;

2009年3月10日 星期二

Crystal Report 的民國100年問題

Crystal Report (8、9、11) 的日期物件,若選用「中華民國曆」格式的話,「年」只會出現兩位
使得民國 100 年變成了「00」
可以使用以下的公式來處理 (Crystal 語法)
Trim(CStr(Year(日期) - 1911, '#00')) + '/' + CStr(Month(日期), '00') + '/' + CStr(Day(日期), '00')

2012/03/06 更新:原先的版本沒有考慮到 null 的問題,改成以下這樣
if (aDate >= CDate('1899/12/31')) then
  Trim(CStr(Year(aDate) - 1911, '#00')) + '/' + CStr(Month(aDate), '00') + '/' +  CStr(Day(aDate), '00')
else
  ''

2008年9月8日 星期一

數字轉中式大寫的 Crystal Report 公式

//=========================================
// 數字轉中文大寫
//=========================================

// 要轉換的數字
NumberVar VNT := (你要轉換的數字欄位); 
StringVar VSU := '零壹貳參肆伍陸柒捌玖'; 
StringVar VST := '仟佰拾兆仟佰拾億仟佰拾萬仟佰拾元'; 
StringVar VNS := ToText(VNT, '0000000000000000'); 
NumberVar VSL := 17 - Length(TrimLeft(ToText(VNT, '################'))); 
StringVar VSS := ''; 
BooleanVar VSF; 
BooleanVar VS0; 
BooleanVar VS1; 
BooleanVar VS2; 
NumberVar VNI; 

VSF := False; 
for VNI := VSL to 16 do 
( 
  VS1 := Mid(VNS, VNI, 1) <> '0'; 
  VS2 := VS1 or (((VNI mod 4) = 0) and ((Mid(VNS, VNI - 3, 4) <> '0000') or (VNI = 16))); 
  VS0 := VSF and VS1; 
  VSF := not (VS0 or VS1 or VS2); 
  if VS0 then 
    VSS := VSS + '零'; 
  if VS1 then 
    VSS := VSS + Mid(VSU, ToNumber(Mid(VNS, VNI, 1)) + 1, 1); 
  if VS2 then 
    VSS := VSS + Mid(VST, VNI, 1); 
); 
// 這是回傳值
VSS;