IReport如何汇出到指定位置

来源:互联网 发布:淘宝店做自己的品牌 编辑:程序博客网 时间:2024/06/08 06:56
  • 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();  
  •             }  
  •         }  
  •     }  
  • }

  • 原创粉丝点击