//打开一个报表以修改和预览
CFileDialog FileOpenDlg(TRUE,"*.rpt",NULL, OFN_EXPLORER, mFilter);
int iResult = FileOpenDlg.DoModal();
if(iResult == IDOK)
{
//取得所选择的文件名
_bstr_t OpenFileName(FileOpenDlg.GetPathName().AllocSysString());
//建立应用程序实例
HRESULT hr = m_Application.CreateInstance("CrystalDesignRuntime.Application");
if(FAILED(hr))
{
AfxMessageBox("水晶报表初始化出错!",MB_ICONINFORMATION);
return false;
}
else
AfxMessageBox("水晶报表初始成功!", MB_ICONINFORMATION);
m_Report = m_Application->OpenReport(OpenFileName);
}
else if (iResult == IDCANCEL)
{
return TRUE;
}
//设置预览的报表数据源
m_ReportVewer.put_ReportSource(m_Report);
//设置报表预览的放大比例
m_ReportVewer.Zoom(1);
//在Viewer控件中先显示报表
m_ReportVewer.ViewReport();
m_ReportVewer.Refresh();