我正在使用报告工具编辑.jasper文件。我正在更改参数左对齐的对齐,然后我保存该文件。它会生成" jrxml"文件也。在我的Java代码中,我可以传递.jasper位置来打印一些项目。但我的改变不会影响,旧的设计仍然相同..
帮帮我,如何编辑和保存.jasper ???
public static JasperPrint createRefundPrint(Ticket ticket,HashMap map)抛出Exception { final String FILE_RECEIPT_REPORT =" /com/floreantpos/report/template/RefundReceipt.jasper" ;;
TicketDataSource dataSource = new TicketDataSource(ticket);
return createJasperPrint(FILE_RECEIPT_REPORT, map, new JRTableModelDataSource(dataSource));
}
答案 0 :(得分:1)
如果您使用IReport编辑.jrxml报告,则只需按下"预览"按钮。然后.jasper报告文件将自动生成包含.jrxml文件的文件夹
答案 1 :(得分:0)
要编辑jasper报告,请在JRXML文件中进行更改。一旦构建或编译报告,它将生成一个.jasper文件,该文件在您的java代码中使用。
答案 2 :(得分:0)
您尝试制作动态报告。 生成自己的报告时,您没有位置问题。 例子;
public JasperDesign createDesign() throws JRException {
JasperDesign jasperDesign = new JasperDesign();
jasperDesign.setName("sampleDynamicJasperDesign");
jasperDesign.setPageWidth(595); // page width
jasperDesign.setPageHeight(842); // page height
jasperDesign.setColumnWidth(515); // column width of page
jasperDesign.setColumnSpacing(0);
jasperDesign.setLeftMargin(40);
jasperDesign.setRightMargin(40);
jasperDesign.setTopMargin(20);
jasperDesign.setBottomMargin(20);
JRDesignExpression expression = new JRDesignExpression();
//Set style of page.
JRDesignStyle normalStyle = new JRDesignStyle();
normalStyle.setName("Sans_Normal");
normalStyle.setDefault(true);
normalStyle.setFontName("DejaVu Sans");
normalStyle.setFontSize(12);
normalStyle.setPdfFontName("Helvetica");
normalStyle.setPdfEncoding("Cp1252");
normalStyle.setPdfEmbedded(false);
jasperDesign.addStyle(normalStyle);
/*
* Generate field dynamically
* */
JRDesignField field = new JRDesignField();
field.setName("firstName");
field.setValueClass(String.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("lastName"); // set name for field.
field.setValueClass(String.class); // set class for field. Its always depends upon data type which we want to get in this field.
jasperDesign.addField(field); // Added field in design.
field = new JRDesignField();
field.setName("age");
field.setValueClass(Integer.class);
jasperDesign.addField(field);
JRDesignBand band = new JRDesignBand();
//Title Band
band = new JRDesignBand();
band.setHeight(30);
JRDesignStaticText staticText = new JRDesignStaticText();
staticText.setText("Person's Specification");
staticText.setX(0);
staticText.setY(0);
staticText.setHeight(20);
staticText.setWidth(515);
staticText.setHorizontalAlignment(HorizontalAlignEnum.CENTER);
band.addElement(staticText);
jasperDesign.setTitle(band);
band = new JRDesignBand(); // New band
band.setHeight(20); // Set band height
/*Create text field dynamically*/
JRDesignTextField textField = new JRDesignTextField();
textField.setX(0); // x position of text field.
textField.setY(0); // y position of text field.
textField.setWidth(160); // set width of text field.
textField.setHeight(20); // set height of text field.
JRDesignExpression jrExpression = new JRDesignExpression(); // new instanse of expression. We need create new instance always when need to set expression.
jrExpression.setText(""" + "First Name: " + """ + "+" + "$F{firstName}"); // Added String before field in expression.
textField.setExpression(jrExpression); // set expression value in textfield.
band.addElement(textField); // Added element in textfield.
textField = new JRDesignTextField();
textField.setX(160);
textField.setY(0);
textField.setWidth(160);
textField.setHeight(20);
jrExpression = new JRDesignExpression();
jrExpression.setText("$F{lastName}" + "+" + """ + " :Last Name" + """); // Added string after field value
textField.setExpression(jrExpression);
band.addElement(textField);
textField = new JRDesignTextField();
textField.setX(320);
textField.setY(0);
textField.setWidth(160);
textField.setHeight(20);
jrExpression = new JRDesignExpression();
String age = """ + "<font>" + """ + "+" + """ + "Age is: " + """ + "+" + """ + "</font><font>" + """ + "+" + "$F{age}" + "+" + """ + "</font>" + """; // added html in text field with different color.
jrExpression.setText(age);
textField.setExpression(jrExpression);
textField.setMarkup("html"); // By Default markup is none, We need to set it as html if we set expression as html.
band.addElement(textField);
((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);
return jasperDesign;
}