@凌晨风
public class XMLDataSource {
private static final String JASPER_FILE_NAME = "D:\\workspace\\Person.jasper";
private static final String XML_FILE_NAME = "D:\\workspace\\person.xml";
private void viewerReport() throws JRException {
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(JASPER_FILE_NAME);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
getReportParameter(XML_FILE_NAME));
new ViewReport().viewer(jasperPrint);
}
private HashMap getReportParameter(String xmlFileName) {
HashMap parameters = new HashMap();
try {
parameters.put("reportTitle", "laoshulin");
Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(xmlFileName));
parameters.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT,
document);
parameters.put(JRXPathQueryExecuterFactory.XML_DATE_PATTERN, "yyyy-MM-dd");
parameters.put(JRXPathQueryExecuterFactory.XML_NUMBER_PATTERN, "#,##0.##");
parameters.put(JRXPathQueryExecuterFactory.XML_LOCALE, Locale.CHINESE);
parameters.put(JRParameter.REPORT_LOCALE, Locale.CHINA);
} catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return parameters;
}
public static void main(String[] args) throws Exception {
new XMLDataSource().viewerReport();
}
}
就是这个类 里面有个new ViewReport().viewer(jasperPrint);
回复 更多评论