水晶報表在VC++6.0中的簡單使用方法

來源:互聯網
上載者:User

水晶報表是一個報表設計開發的強大工具,功能強大,設計靈活,在水晶報表光碟片中只提供了一個完全動態產生報表的例子,使用繁瑣。現介紹其在VC++6.0中的簡單使用方法。編譯環境:VC++6.0 sp5 、Windows 2000 Server sp3 (en)。一、匯入水晶報表使用的動態聯結庫:根據實際修改檔案路徑。#import "C:Documents and SettingsAdministrator案頭crcraxdrt9.dll" no_namespace

  二、定義介面指標變數//水晶報表變數

IApplicationPtr m_Application;
   IReportPtr m_Report;
//水晶報表控制項變數,在對話方塊中加入該控制項
   CCrystalReportViewer9  m_CRViewer1;三、具體實現步驟 //執行個體化m_Application
   m_Application.CreateInstance (__uuidof(Application));
//擷取m_Report變數
//staff.rpt為通過嚮導建立的報表檔案,資料庫採用SQL Server 7.0
  m_Report =m_Application->OpenReport ("C:Documents and SettingsAdministrator案頭crdebugstaff.rpt");
  //設定報表標題
  m_Report->put_ReportTitle (_bstr_t("Title"));
  //設定資料庫連接變數
//資料庫伺服器(local),資料庫名staff,使用者名稱sa,密碼sa
  m_Report->Database ->Tables ->Item [1]->SetLogOnInfo("(local)","staff","sa","sa");
//設定檢索SQL命令
m_Report->put_SQLQueryString ((_bstr_t)"select * from person where id<'4' order by id");
//不顯示重複欄位
  m_Report->PutEnableSelectDistinctRecords (TRUE);
  //設定檢索條件,採用水晶報表文法,功能同設定檢索SQL命令
m_Report->PutRecordSelectionFormula ((_bstr_t)"{person.id}='1'");
//設定報表作者
  m_Report->PutReportAuthor ("xiaojin");
  //將m_Report與報表控制項串連
  m_CRViewer1.SetReportSource(m_Report);
//顯示報表工具條
  m_CRViewer1.SetDisplayToolbar (TRUE);
//不顯示報表左邊的分組樹
  m_CRViewer1.SetDisplayGroupTree (FALSE);
  //不顯示控制項邊框
  m_CRViewer1.SetDisplayBorder (FALSE);
  //重新整理資料
  m_CRViewer1.Refresh ();
//顯示報表內容
  m_CRViewer1.ViewReport();這樣,漂亮的水晶報表就顯示出來了。程式異常處理部分省略,請自行加入。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.