View Javadoc

1   package ar.com.fdvs.dj.test;
2   
3   import java.util.Date;
4   
5   import ar.com.fdvs.dj.core.layout.LayoutManager;
6   import ar.com.fdvs.dj.core.layout.ListLayoutManager;
7   import ar.com.fdvs.dj.domain.DynamicReport;
8   import ar.com.fdvs.dj.domain.Style;
9   import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
10  import ar.com.fdvs.dj.domain.constants.GroupLayout;
11  import ar.com.fdvs.dj.domain.constants.Page;
12  import ar.com.fdvs.dj.domain.entities.DJGroup;
13  
14  public class XlsReportTest extends BaseDjReportTest {
15  
16  	public DynamicReport buildReport() throws Exception {
17  
18  
19  		/**
20  		 * Creates the DynamicReportBuilder and sets the basic options for
21  		 * the report
22  		 */
23  		FastReportBuilder drb = new FastReportBuilder();
24  		Style columDetail = new Style();
25  //		columDetail.setBorder(Border.THIN());
26  
27  		drb.addColumn("State"			, "state"		, String.class.getName(), 30)
28  			.addColumn("Branch"			, "branch"		, String.class.getName(), 30)
29  			.addColumn("Product Line"	, "productLine"	, String.class.getName(), 50)
30  //			.addColumn("Item"			, "item"		, String.class.getName(), 50)
31  //			.addColumn("Item Code"		, "id"			, Long.class.getName()	, 30, true)
32  //			.addColumn("Quantity"		, "quantity"	, Long.class.getName()	, 60, true)
33  			.addColumn("Amount"			, "amount"		, Float.class.getName()	, 70, true)
34  			.addColumn("Date"			, "date"		, Date.class.getName()	, 70, true, "dd/MM/yyyy",null)
35  			.addGroups(2) //Not used by the ListLayoutManager
36  			.setPrintColumnNames(true)
37  			.setIgnorePagination(true) //for Excel, we may dont want pagination, just a plain list
38  			.setMargins(0, 0, 0, 0)
39  			.setPageSizeAndOrientation(Page.Page_Letter_Landscape())
40  			.setTitle("November " + getYear() +" sales report")
41  			.setSubtitle("This report was generated at " + new Date())
42  			.setReportName("My Excel Report")
43  			.setDefaultStyles(null, null, null, columDetail)
44  			.setUseFullPageWidth(true);
45  
46  		DynamicReport dr = drb.build();
47  
48  		DJGroup group = (DJGroup) dr.getColumnsGroups().iterator().next();
49  		group.setLayout(GroupLayout.EMPTY); //not used by ListLayoutManager
50  
51  		return dr;
52  	}
53  
54  	protected LayoutManager getLayoutManager() {
55  		return new ListLayoutManager();
56  	}
57  
58  	protected void exportReport() throws Exception {
59  		ReportExporter.exportReportXls(jp, System.getProperty("user.dir")+ "/target/" + this.getClass().getName() + ".xls");
60  	}
61  
62  
63  	public static void main(String[] args) throws Exception {
64  		XlsReportTest test = new XlsReportTest();
65  		test.testReport();
66  	}
67  }