Jump to content

Generating jasper report & export it to .xls


askme

Recommended Posts

Hi all,

             I am new to jasper reports. Actually i need to show some data in jasper report and then export it to either .xls (or) .csv format. Please find the attachment, actually that is the format in which my report need to be generated. At first i thought of doing the template in .jrxml format. But some of the marks for the students should be displayed in red color, if it  the students mark is less that average mark. So i thought of doing the template coding in java and then pass on the student values to this class file.

 

Please find the sample codes which i was trying to use for generating a sample report in the code segment below.

 

 

As a beginner i don't know hot to do this.

 

Can somebody help me generate a report in the format as shown in the file(please find the attachment) using a similiar type of coding as mentioned in the code section and with out using .jrxml template file.

 

Kindly help me.

 

Thanks

 

   

Code:
//Actually this if the type of coding i wish to follow.Something likeimport net.sf.jasperreports.engine.JRAlignment;import net.sf.jasperreports.engine.JRElement;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperCompileManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;import net.sf.jasperreports.engine.design.JRDesignBand;import net.sf.jasperreports.engine.design.JRDesignExpression;import net.sf.jasperreports.engine.design.JRDesignField;import net.sf.jasperreports.engine.design.JRDesignLine;import net.sf.jasperreports.engine.design.JRDesignStaticText;import net.sf.jasperreports.engine.design.JRDesignStyle;import net.sf.jasperreports.engine.design.JRDesignTextField;import net.sf.jasperreports.engine.design.JasperDesign;import net.sf.jasperreports.view.JasperViewer;//---Then write a function which sets the design---private static JasperDesign getProductJasperDesign() throws JRException {        JasperDesign jasperDesign = new JasperDesign();        jasperDesign.setName("Product_Report");        jasperDesign.setLeftMargin(10);        jasperDesign.setRightMargin(10);        jasperDesign.setBottomMargin(20);        jasperDesign.setTopMargin(20);        jasperDesign.setPageHeight(800);        jasperDesign.setPageWidth(600);        jasperDesign.setColumnWidth(500);        jasperDesign.setIgnorePagination(true);        // Add styles to report        JRDesignStyle titleText = new JRDesignStyle();        titleText.setName("titleText");        titleText.setDefault(false);        titleText.setMode(JRElement.MODE_OPAQUE);        titleText.setFontName("Arial");        titleText.setFontSize(16);        jasperDesign.addStyle(titleText);}//And then finally call this design to the main function like  JasperDesign jasperDesign = getProductJasperDesign();            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);//and then export the result to either .xls (or) .csv format.
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...