CR4E Crystal Reports保存修改后的ChartObject

时间:2012-11-28 11:30:55

标签: java charts crystal-reports

我正在尝试使用Java以编程方式修改Crystal Report中的图表。然后,java将报告提供给查看器。删除项目有效,修改没有。

//Experiment : Can we programatically modify a chart?
            ReportDefController rdc = reportClientDocument.getReportDefController();
            ReportObjectController roc = rdc.getReportObjectController();
            ReportObjects ros = roc.getReportObjectsByKind(ReportObjectKind.chart);

            logger.debug("There are " + ros.size() + " chart items");
            IChartObject ro = null;
            IChartObject ro_original = null;
            ISection iSection = null;
            for (int i = 0; i <ros.size(); i++){
                ro = (IChartObject)ros.get(i);
                ro_original = (IChartObject)ros.get(i);
                String rn = ro.getName();
                ChartStyle cs = (ChartStyle) ro.getChartStyle();
                cs.setEnableDataAxisAutoRange(false);
                cs.setEnableShowLegend(false);
                cs.setEnableDepthEffect(true);
                cs.setIsVertical(true);
                cs.setDataAxisMinValue(-2.0);
                cs.setDataAxisMaxValue(100.0);
                Double minVal = (Double)cs.getDataAxisMinValue();
                Double maxVal = (Double)cs.getDataAxisMaxValue();
                boolean d = cs.getEnableDepthEffect();
                boolean l = cs.getEnableShowLegend();
                boolean a = cs.getEnableDataAxisAutoRange();
                boolean v = cs.getIsVertical();
                ro.setChartStyle(cs);
                int sectionCode = ro.getSectionCode();
                iSection = rdc.getReportDefinition().getDetailArea().getSections().getSection(0);
                try
                {
                    //roc.modify((IChartObject)ros.get(i), ro);
                    rdc.modifyChartObject((IChartObject)ros.get(i), ro);
                    reportClientDocument.refreshReportDocument();
                    reportClientDocument.save();
                } catch (ReportSDKException e){
                    writer.println("Couldn't modify graph");
                    e.printStackTrace();
                }
                logger.debug("Chart named "+rn + " With Min Val " + minVal + " and Max Val " + maxVal +" with depth " + d + " and legend " + l + " autorange " + a + " Vertical " + v);
            }

我已经尝试了ReportObjectController的modify方法和ReportDefController的modifychartobject方法,并尝试了refreshReportDocument并保存以尝试获取更新内容,但没有发生任何事情。记录器显示值正在按照您的预期进行更新。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我的错误在于没有克隆对象......

ro = (IChartObject)ros.get(i) 

......所以它应该读......

ro = (IChartObject)ros.get(i).clone(false)

..所以......

roc.modify((IChartObject)ros.get(i), ro)

..现在可以工作了。希望这有助于其他人有类似的乐趣和游戏。