//头文件定义
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
ICROleObjectPtr pCROleObj;
IGraphObjectPtr pChartObj;
ISectionsPtr pSections;
ISectionPtr pSection ;
IParameterFieldDefinitionsPtr pParamFields;
IParameterFieldDefinitionPtr pParamField;
ILineObjectPtr pLineObj;
//cpp实现
m_Application.CreateInstance (__uuidof(Application));
_bstr_t strRptName = "E://Cristal//MultDetailsExamp//DataAndPic.rpt";
_bstr_t strPicName = "E://Cristal//MultDetailsExamp//AreaStudytemp.jpg";
m_Report =m_Application->OpenReport((_bstr_t)strRptName);
//新建一个报表
//m_Report = m_Application->NewReport();
//直接向水晶报表内部添加图片并修改属性 bmp jpg 都可以导入
pChartObj = NULL;
pSections = NULL;
pSection = NULL;
pCROleObj = NULL;
_variant_t var;
VariantInit(&var);
var.vt = VT_I2;
var.iVal = 1;
//向某个特定区域比如头文件详细部分添加图片
pSections = m_Report->GetAreas()->GetItem("D")->GetSections();
pSection = pSections->GetItem(var);
pSection->PutName("test");
pCROleObj = pSection->AddPictureObject((_bstr_t)strPicName, 0, 0);
//修改图片属性 报表中的位置
pCROleObj->Name = "水晶报表测试图例";
pCROleObj->BackColor = RGB(111,111,111);
pCROleObj->Left = 1000;
pCROleObj->Top = 500;
pCROleObj->XScaling = 0.80;
pCROleObj->YScaling = 0.80;
//设定边框颜色和边框线形
pCROleObj->BorderColor = RGB(0,255,255);
pCROleObj->BottomLineStyle = crLSSingleLine ;
pCROleObj->TopLineStyle = crLSSingleLine;
pCROleObj->RightLineStyle = crLSSingleLine;
pCROleObj->LeftLineStyle = crLSSingleLine;
//..具体属性设置,可以参考craxddrt.dll中的接口属性说明
//添加参数数据
pParamField = m_Report->GetParameterFields()->GetItemByName("MyName");
pParamField->AddCurrentValue("HuTianYu");
m_Report->GetParameterFields()->GetItemByName("MyCountry")->AddCurrentValue("China");
//向区域中添加一条线,矩形框等...
pLineObj = pSection->AddLineObject(500,400,400,1000);
m_Report->SaveAs("DataAndPicTmp.rpt", (CRReportFileFormat)0);
m_wndCRViewer.put_ReportSource(m_Report);
m_wndCRViewer.ViewReport();
m_wndCRViewer.Refresh();