0
我正在使用文本字段来显示列名称。对于示出的列的对应名称我曾尝试以下方法:用JasperReports API设置表达式的正确方法是什么?
方法1:
textField.setX(currentXPos);
textField.setY(0);
textField.setWidth(columnWidth);
textField.setPrintWhenDetailOverflows(false);
textField.setHeight(colDtlBandHeight);
textField.setStretchWithOverflow(true);
textField.setStretchType(StretchTypeEnum.RELATIVE_TO_BAND_HEIGHT);
textField.setStyle(normalFont);
textField.setBlankWhenNull(true);
JRDesignExpression expression = new JRDesignExpression();
expression.setValueClass(columnClass);
expression.setText("$F{" + columnName + "}");
但在使用它抛出异常上述方法话说:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. Syntax error on token "ID", delete this token
value = SHIFT ID; //$JR_EXPR_ID=44$
2. Syntax error, insert ";" to complete BlockStatements
value = BILL NO.; //$JR_EXPR_ID=45$
3. Syntax error on token ".", invalid VariableDeclarator
value = BILL NO.; //$JR_EXPR_ID=45$
4. Syntax error on token "DATE", delete this token
value = BILL DATE; //$JR_EXPR_ID=46$
但在使用下面的行时,列名称设置正确。
方法2:
textField.setExpression(new JRDesignExpression("new String(\""+colTitle+"\")"));
我的怀疑有:
1.用于显示用于所提到的第一种方法的数据。那么在那种情况下怎么没有例外呢?
2.为什么在使用相同的方法显示列名时会抛出这些异常?
3.第二种方法是如何工作的?