- public class TestExcel {
- public static void main(String[] args) {
- File reportFile = new File(
- "WebRoot\\report1.jasper");
- Map parameters = new HashMap();
- Connection conn = null;
- FileOutputStream output = null;
- try {
- String driver = "net.sourceforge.jtds.jdbc.Driver";
- String url = "jdbc:jtds:sqlserver://server:1433/pcbsyn";
- Class.forName(driver);
- conn = DriverManager.getConnection(url, "sa", "711");
- Map parameter = new HashMap();
- JasperPrint report = null;
- report = JasperFillManager.fillReport(reportFile.getPath(),
- parameter, conn);
- JRAbstractExporter exporter = new JExcelApiExporter();
- output = new FileOutputStream("D:\\excel.xls");
- exporter.setParameter(JRExporterParameter.JASPER_PRINT, report);
- exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, output);
- exporter.exportReport();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- output.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- try {
- conn.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
IReport如何汇出到指定位置
最新推荐文章于 2022-07-14 10:33:59 发布