How to get crystal reports parameter names with JA

2019-09-16 15:25发布

问题:

I have to create reports dinamically in my Java App.

I have a CrystalReport's (.rpt) collection so it depends which rpt you select. When you select a report I have to create a new Window with requeried parameters from "file.rpt", so I need the parameters names to decide what kind of parameters user should to complete.

I was looking in forums and I couldn't find anything.

Thanks!

回答1:

Try this!

DatabaseController dbController = reportClientDocument.getDatabaseController();
        Tables tables = dbController.getDatabase().getTables();
        ITable table = tables.getTable(0);
        IProcedure command = (IProcedure)table;
        if(table instanceof com.crystaldecisions.sdk.occa.report.data.CommandTable) {

            for (int i=0; i< command.getParameters().size(); i++) {
                ParameterField commandParam = (ParameterField) command.getParameters().get(i);
                String paramName = commandParam.getName();
                String paramType = commandParam.getType().toString().substring(4);
                if(paramType.equalsIgnoreCase("decimal")){
                    paramType = "int";
                }
                paramType = paramType.toLowerCase();
                listOfParameter.put(paramName, paramType);
             }
            return listOfParameter;
        }


回答2:

    ParameterFieldController paramFieldController = reportClientDoc.getDataDefController().getParameterFieldController();

        for(Entry<String,Object> par : parametros.entrySet()) {
            paramFieldController.setCurrentValue("", par.getKey(), par.getValue()); 
        }