CR4E 水晶报告保存修改后的图表对象



我正在尝试使用 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的修改方法和ReportDefController的modifychartobject方法,并尝试刷新ReportDocument并保存以尝试更新某些内容,但没有任何反应。记录器显示值正在按预期更新。有什么想法吗?

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

ro = (IChartObject)ros.get(i) 

。所以它应该读...

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

..因此。。

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

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

最新更新