1

我正在尝试使用 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 和 save 以尝试获取要更新的内容,但没有任何反应。Logger 显示值正在按照您的预期进行更新。有任何想法吗?

4

1 回答 1

0

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

ro = (IChartObject)ros.get(i) 

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

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

..以便..

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

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

于 2012-11-28T13:08:29.810 回答