我已在我的桌面应用程序中成功地将 Crystal Report 与 Java 连接起来。现在我想以编程方式在报告中添加一行。
我已经用下面的代码试过了。
try {
ReportDefController rdc = reportClientDoc.getReportDefController();
} catch (ReportSDKException ex) {
Logger.getLogger(PurchaseReport.class.getName()).log(Level.SEVERE, null, ex);
}
Tables tables = null;
try {
tables = reportClientDoc.getDatabase().getTables();
} catch (ReportSDKException ex) {
Logger.getLogger(PurchaseReport.class.getName()).log(Level.SEVERE, null, ex);
}
LineObject lineObject = new LineObject();
lineObject.clone(false);
lineObject.setSectionCode(0);
lineObject.setLineThickness(10);
lineObject.setLeft(50);
lineObject.setWidth(50);
lineObject.setHeight(10);
lineObject.setRight(20);
lineObject.setTop(10);
lineObject.setLineColor(Color.BLUE);
ReportObjectController roc = null;
try {
roc = reportClientDoc.getReportDefController().getReportObjectController();
} catch (ReportSDKException ex) {
Logger.getLogger(PurchaseReport.class.getName()).log(Level.SEVERE, null, ex);
}
ReportDefController reportDefController = null;
try {
reportDefController = reportClientDoc.getReportDefController();
ISection section = reportDefController.getReportDefinition().getDetailArea().getSections().getSection(0);
lineObject.setSectionName(section.getName());
//roc.add(fieldObject, section, 0);
if(roc.canAddReportObject(lineObject, section))
{
roc.add(lineObject, section, -1);
}
} catch (ReportSDKException ex) {
Logger.getLogger(PurchaseReport.class.getName()).log(Level.SEVERE, null, ex);
}
这会引发错误roc.add(lineObject, section, -1)
如何解决此错误并正确添加该行?