VC中直接向水晶报表中添加图片

本文档展示了如何在Visual C++(VC)中直接向水晶报表添加图片,并详细介绍了设置图片属性和边框样式的过程。通过创建 Crystal Reports 对象、打开或新建报表,然后使用接口方法在特定区域添加图片并调整其大小、位置和样式。最后,保存报表并显示在查看器中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//头文件定义 

_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();

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值