如何用代码导出报表?
1.创建报表引擎
2.创建设计处理器
reportRunnable = reportEngine.openReportDesign(filePath); designHandle = (ReportDesignHandle) reportRunnable.getDesignHandle( );
HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();HTMLRenderOption option = new HTMLRenderOption();option.setOutputFileName(savePath+"/"+fileName); option.setImageHandler(imageHandler); option.setActionHandler(new HTMLActionHandler());option.setOutputFormat("html"); HTMLRenderContext renderContext = new HTMLRenderContext();renderContext.SetRenderOption(option);renderContext.setSupportedImageFormats("JPG;PNG;BMP;SVG");String imgPath = fileName.substring(0,fileName.indexOf(".")); renderContext.setImageDirectory(savePath+"/"+imgPath+".files");renderContext.setBaseImageURL("./"+imgPath+".files");HashMap<Object, Object> contextMap = new HashMap<Object, Object>();contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );task.setAppContext(contextMap);option.setEmbeddable(true);task.setRenderOption(option); task.run();
PDFRenderContext renderContext = new PDFRenderContext();renderContext.setBaseURL(""); HashMap<Object, Object> contextMap = new HashMap<Object, Object>();contextMap.put(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT,renderContext);task.setAppContext(contextMap);RenderOptionBase options = new RenderOptionBase(); options.setOutputFileName(savePath+"/"+fileName); options.setOutputFormat("pdf"); options.setActionHandler(new HTMLActionHandler());task.setRenderOption(options);task.run();
Map<Object, Object> xlsMap = new HashMap<Object, Object>();xlsMap.put("fixed_column_width", Integer.valueOf(30));xlsMap.put("show_grid_lines", Boolean.valueOf(false));engineConfig.setEmitterConfiguration("xls", xlsMap);RenderOptionBase options = new RenderOptionBase();options.setOutputFormat("xls");options.setOutputFileName(filePath);EXCELRenderOption excelOptions = new EXCELRenderOption(options);excelOptions.setSupportedImageFormats("JPG;PNG;BMP;SVG");HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();excelOptions.setImageHandler(imageHandler);task.setRenderOption(excelOptions);