这是我打印发票页的源线。我的报告在Java包中。我将它保存在一个名为“report”的文件夹中。
try {
String date1 = new SimpleDateFormat("yyyy-MM-dd").format(isdate.getDate());
String time1 = istime.getValue().toString().split(" ")[3];
date1 = date1 + " " + time1;
String date2 = new SimpleDateFormat("yyyy-MM-dd").format(redate.getDate());
String time2 = retime.getValue().toString().split(" ")[3];
date2 = date2 + " " + time2;
JRTableModelDataSource dataSource = new JRTableModelDataSource(jTable1.getModel());
String reportsource = " D:/Catering/report/report1.jrxml";
Map<String, Object> params = new HashMap<String, Object>();
params.put("inid", txtInvoiceID.getText());
params.put("cuname", txtCuName.getText());
params.put("cuadd", txtCuid.getText());
params.put("cutp", txtTPNo.getText());
params.put("isdate", date1);
params.put("redate", date2);
params.put("advance", txtAdvance.getText());
params.put("due", txtDue.getText());
params.put("total", txtGtotal.getText());
JasperReport jasperReport = JasperCompileManager.compileReport(reportsource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
JasperViewer.viewReport(jasperPrint, true);
JOptionPane.showMessageDialog(null, "Done");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "jasper error"+e);
}