gmadhavi Posted March 13, 2009 Share Posted March 13, 2009 Hello friends,Can anyone please send me code of how to create plain text output using Jasper Reports.I am using,Tomcat server andOpen OfficeThanks Link to comment Share on other sites More sharing options...
dnvsrikanth Posted March 13, 2009 Share Posted March 13, 2009 Hi,Using JasperReports we can export a report to RTF format. But we can't export the report to plain text format.DNV Srikanth Link to comment Share on other sites More sharing options...
gmadhavi Posted March 13, 2009 Author Share Posted March 13, 2009 Hi Srikanth,Thanks for your reply.Using JRCsvExporter only, we can export the report to plain text format itseems. But I am unable to do it.Even, I am unable to export a report to RTF format.Donno the reason.Its opening as unknown document.Please provide me code to export to csv(tab delimited) or look at my code and tell me where i am going wrong.Snippet code: jasperDesign = JRXmlLoader.load(reportFile);jasperReport = JasperCompileManager.compileReport(jasperDesign);Connection jdbcConnection = connectDB(databaseName, userName, password);jasperPrint = JasperFillManager.fillReport(jasperReport, null, jdbcConnection);OutputStream ouputStream = response.getOutputStream();JRExporter exporter = null;response.setContentType("application/csv");response.setHeader("Content-Disposition","inline;filename=file.csv");exporter = new JRCsvExporter();exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);Thanks Link to comment Share on other sites More sharing options...
dnvsrikanth Posted March 13, 2009 Share Posted March 13, 2009 In the statement mentioned u r passing null as one of the parameters. Dont you to pass parameters to the report???Code:jasperPrint = JasperFillManager.fillReport(jasperReport, null, jdbcConnection); Link to comment Share on other sites More sharing options...
shiyampas Posted March 19, 2009 Share Posted March 19, 2009 Hai gmadhavi,can u send your code to me. i'm also looking to generate the report in the text format.in the your example code i cant able to find the response.xxx and some of others.and which jasper jar need to use for this?please help me.very urgentthanksbyshiyam Link to comment Share on other sites More sharing options...
gmadhavi Posted March 20, 2009 Author Share Posted March 20, 2009 Hi shiyam,I am also unable to generate Jasper report in text format..So,got shifted to display it in CSV and HTML format.Here,I am placing my entire code.I am using following jar files:jasperreports-3.1.4.jarcommons-collections-2.1.jarcommons-digester-1.7.jarcommons-logging-1.0.2.jarclasses12.jariText-2.1.4.jarcommons-beanutils-1.7.jarPlease let me know if u have any queries.ByeMadhaviCode: HashMap parameters = new HashMap(); parameters.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE); jasperDesign = JRXmlLoader.load(reportFile); parameters.put("IP_ORG_ID",orgId); parameters.put("IP_INV_ORGANIZATION_ID",inv_organization_id); parameters.put("IP_CARRIER_CODE",carrierId); parameters.put("IP_USER_METHOD_MEANING",shipMethodStr);jasperReport = JasperCompileManager.compileReport(jasperDesign);Connection jdbcConnection = connectDB(databaseName, userName, password); jasperPrint = JasperFillManager.fillReport(jasperReport, parameters,jdbcConnection); OutputStream ouputStream = response.getOutputStream(); JRExporter exporter = null;if( "HTML".equalsIgnoreCase(reportType) ) //working fine without images { exporter = new JRHtmlExporter(); request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); // gonna set url pattern given for Image servlet with a reponse parameter <url-pattern>/image</url-pattern> exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,"imageServlet?image="); response.setContentType("text/html"); response.setHeader("Content-Disposition","inline;filename=file.html"); // exporter.exportReport(); } else if( "CSV".equalsIgnoreCase(reportType)) { exporter = new JRCsvExporter(); exporter.setParameter(JRCsvExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, ","); exporter.setParameter(JRCsvExporterParameter.RECORD_DELIMITER,System.getProperty("line.separator")); exporter.setParameter(JRCsvExporterParameter.OUTPUT_STREAM, ouputStream); response.setContentType("text/csv"); response.setHeader("Content-Disposition","inline;filename=file.csv"); } try { exporter.exportReport(); } catch (JRException e) { throw new ServletException(e); } finally { if (ouputStream != null) { try { ouputStream.flush(); ouputStream.close(); } catch (IOException ex) { logger.info("exception=="+ex); ex.printStackTrace(); } } } public static Connection connectDB(String databaseName, String userName, String password) { Connection jdbcConnection = null; try{ Class.forName("oracle.jdbc.driver.OracleDriver"); jdbcConnection = DriverManager.getConnection(databaseName,userName,password); }catch(Exception ex) { String connectMsg = "Could not connect to the database: " + ex.getMessage() + " " + ex.getLocalizedMessage(); logger.info(connectMsg); } return jdbcConnection; } Link to comment Share on other sites More sharing options...
usmann Posted April 6, 2009 Share Posted April 6, 2009 You may use Aspose.Words for JasperReports that enables you converting your reports into plain text (TXT) format. Other Word document formats (DOC, DOCX and HTML) are also supported. Read more here http://www.aspose.com/categories/jasperreports-exporters/aspose.words-for-jasperreports/default.aspx Link to comment Share on other sites More sharing options...
vishal29bhp Posted June 1, 2009 Share Posted June 1, 2009 Hi Madhavi, I trying to export a report which contains chart but nothing appeared on browser except report name. No images and Data displayed.I am using my own web application to display the report. Vishal Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now