dynamicreports1

转载 2016年08月28日 19:26:13
package report;

import static net.sf.dynamicreports.report.builder.DynamicReports.cmp;
import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.exp;
import static net.sf.dynamicreports.report.builder.DynamicReports.grid;
import static net.sf.dynamicreports.report.builder.DynamicReports.report;
import static net.sf.dynamicreports.report.builder.DynamicReports.sbt;
import static net.sf.dynamicreports.report.builder.DynamicReports.stl;
import static net.sf.dynamicreports.report.builder.DynamicReports.type;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.sf.dynamicreports.adhoc.AdhocManager;
import net.sf.dynamicreports.adhoc.configuration.AdhocColumn;
import net.sf.dynamicreports.adhoc.configuration.AdhocConfiguration;
import net.sf.dynamicreports.adhoc.configuration.AdhocReport;
import net.sf.dynamicreports.examples.Templates;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.base.expression.AbstractSimpleExpression;
import net.sf.dynamicreports.report.builder.column.ColumnBuilder;
import net.sf.dynamicreports.report.builder.column.TextColumnBuilder;
import net.sf.dynamicreports.report.builder.grid.ColumnTitleGroupBuilder;
import net.sf.dynamicreports.report.builder.style.StyleBuilder;
import net.sf.dynamicreports.report.builder.subtotal.AggregationSubtotalBuilder;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.datasource.DRDataSource;
import net.sf.dynamicreports.report.definition.ReportParameters;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;

    

    /**

     * @author Ricardo Mariaca (r.mariaca@dynamicreports.org)

     */

    public class Invoicetest {

       private InvoiceData data = new InvoiceData();

       private AggregationSubtotalBuilder<BigDecimal> totalSum;

       private JRDataSource createDataSource1() {
           
           DRDataSource dataSource = new DRDataSource("item", "quantity", "unitprice", "quantity1", "unitprice1", "quantity2", "unitprice2", "quantity3");
 
       //    dataSource.add("Notebook", 1, new BigDecimal(500));
 
        dataSource.add(null,null , null,null , null,null , null);
           return dataSource;
 
        }
       
       private JRDataSource createDataSource() {

              DRDataSource dataSource = new DRDataSource("item", "orderdate", "quantity");

              for (int i = 0; i < 20; i++) {

                 dataSource.add("Book", new Date(), (int) (Math.random() * 10) + 1);

              }

              return dataSource;

           }

       public JasperReportBuilder build() throws DRException {
           JasperReportBuilder report5 = report();
           try {
               TextColumnBuilder<String>[] columns = new TextColumnBuilder[7];
               columns[0] =  col.column("Totle",       "item",      type.stringType()).setWidth(200);
               columns[1] =  col.column("Totle1",       "item1",      type.stringType());
               columns[2] =  col.column("Totle2",       "item2",      type.stringType());
               columns[3] =  col.column("Totle3",       "item3",      type.stringType());
               columns[4] =  col.column("Totle4",       "item4",      type.stringType());
               columns[5] =  col.column("Totle5",       "item5",      type.stringType());
               columns[6] =  col.column("Totle6",       "item6",      type.stringType());
            //   columns[7] =  col.column("Totle7",       "item7",      type.stringType());
               
               StyleBuilder columnStyle = stl.style(Templates.columnStyle)

                 .setBorder(stl.pen1Point());

              StyleBuilder subtotalStyle = stl.style(columnStyle)

                 .bold();

              StyleBuilder shippingStyle = stl.style(Templates.boldStyle)

                 .setHorizontalAlignment(HorizontalAlignment.RIGHT);
              
               report5 =  report()//create new report design
               .setTemplate(Templates.reportTemplate)

          //   .setColumnStyle(columnStyle)

         //    .setSubtotalStyle(subtotalStyle)
                              .columns(//add columns
                                      columns)
                          
                              .setDataSource(createDataSource1());//set datasource
               
                         //     .show();//create and show report
               
                         } catch (Exception e) {
               
                            e.printStackTrace();
               
                         }
           
            String titlev = "test title";

          JasperReportBuilder report = report();

         

          //init styles

          StyleBuilder columnStyle = stl.style(Templates.columnStyle)

             .setBorder(stl.pen1Point());

          StyleBuilder subtotalStyle = stl.style(columnStyle)

             .bold();

          StyleBuilder shippingStyle = stl.style(Templates.boldStyle)

             .setHorizontalAlignment(HorizontalAlignment.RIGHT);

    

          //init columns

          TextColumnBuilder<Integer> rowNumberColumn = col.reportRowNumberColumn()

             .setFixedColumns(2)

             .setHorizontalAlignment(HorizontalAlignment.CENTER);

//          TextColumnBuilder<String> descriptionColumn = col.column("Description", "description", type.stringType())
//
//             .setFixedWidth(250);
         
          TextColumnBuilder<Integer> quantityColumn = col.column("Quantity", "quantity", type.integerType()).setWidth(100)

             .setHorizontalAlignment(HorizontalAlignment.CENTER);

          TextColumnBuilder<BigDecimal> unitPriceColumn = col.column("Unit Price", "unitprice", Templates.currencyType).setWidth(100);

          
          TextColumnBuilder<String> colaa = col.column("Unit Price", "description1", type.stringType());
          TextColumnBuilder<String> colbb = col.column("Unit Price", "description2", type.stringType());

          TextColumnBuilder<String> colaa1 = col.column("Unit Price", "description1", type.stringType());
          TextColumnBuilder<String> colbb1 = col.column("Unit Price", "description2", type.stringType());

          TextColumnBuilder<String> colaa2 = col.column("Unit Price", "description1", type.stringType());
          TextColumnBuilder<String> colbb2 = col.column("Unit Price", "description2", type.stringType());

          
          TextColumnBuilder<String> priceColumn = colaa

                  .setTitle("Price")

                  .setDataType(type.stringType());

               //vat = price * tax
          TextColumnBuilder<String> priceColumn2 = colbb

                  .setTitle("Price1")

                  .setDataType(type.stringType());
              
          TextColumnBuilder<String> priceColumna = colaa1

                  .setTitle("aPrice")

                  .setDataType(type.stringType());

               //vat = price * tax
          TextColumnBuilder<String> priceColumn2a = colbb1

                  .setTitle("aPrice1")

                  .setDataType(type.stringType());
          
          TextColumnBuilder<String> priceColumnb = colaa2

                  .setTitle("bPrice")

                  .setDataType(type.stringType());

               //vat = price * tax
          TextColumnBuilder<String> priceColumn2b = colbb2

                  .setTitle("bPrice1")

                  .setDataType(type.stringType());
     
          //total = price + vat
          ColumnTitleGroupBuilder totalColumn = grid.titleGroup("Total Price 1", priceColumn, priceColumn2);
          ColumnTitleGroupBuilder totalColumn1 = grid.titleGroup("Total Price 2", priceColumna, priceColumn2a);
          ColumnTitleGroupBuilder totalColumn2 = grid.titleGroup("Total Price 3", priceColumnb, priceColumn2b);
          
          
          report

             .setTemplate(Templates.reportTemplate)

             .setColumnStyle(columnStyle)

             .setSubtotalStyle(subtotalStyle)

               .columnGrid(
                      quantityColumn, unitPriceColumn, totalColumn,totalColumn1,totalColumn2)
               .columns(
                       quantityColumn, unitPriceColumn,priceColumn, priceColumn2,priceColumna, priceColumn2a,priceColumnb, priceColumn2b)
              
                        .summary(cmp.subreport(report5))
                       .pageFooter(

                Templates.footerComponent)

             .setDataSource(createInvoice());

          return report;

       }

       private class TotalPaymentExpression extends AbstractSimpleExpression<String> {

          private static final long serialVersionUID = 1L;

    

          @Override

          public String evaluate(ReportParameters reportParameters) {

return null;
          }

       }

    

       public static void main(String[] args) {

           Invoicetest design = new Invoicetest();

          try {

             JasperReportBuilder report = design.build();

             report.show();

          } catch (DRException e) {

             e.printStackTrace();

          }

       }
       private List<Item> createInvoice() {
           List<Item> items = new ArrayList<Item>();
           items.add(createItem("Notebook", 1, new BigDecimal(1000)));
           items.add(createItem("DVD", 5, new BigDecimal(40)));
           items.add(createItem("Book", 2, new BigDecimal(10)));
           items.add(createItem("Phone", 1, new BigDecimal(200)));
           
           return items;
       }
       
       private Item createItem(String description, Integer quantity, BigDecimal unitprice) {
           Item item = new Item();
           item.setDescription(description);
           item.setQuantity(quantity);
           item.setUnitprice(unitprice);
           item.setDescription1("aaa");
           item.setDescription2("bbb");
           return item;
       }
    }

相关文章推荐

纯JAVA代码利用DynamicReports插件生成动态报表

1.首先,我的目的是纯java项目连接SQL2008数据库,之后能够应客户需要打印出用户的近期10次的消费回单。 2.昨天想到用ireport+jasperreports生成报表,发现生成的是静态...

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

jasperreport插件dynamicreports使用实例

jasperreport插件dynamicreports使用实例 源代码下载地址:http://www.zuidaima.com/share/1550463624694784.htm...

iReport输出为HTML或PDF、XLS、DOC【输出HTML两种方法】

//ireport 导出word格式 //导出word格式 在它的文档中也没有, // String sql = "select * from cfg_static_user_relation...
  • cbjcry
  • cbjcry
  • 2017年04月13日 10:06
  • 1122

认识iReport并创建其模板

被Ireport狂虐了一个礼拜,终于在今天做出了第一个成型的例子,撒花~~~~~ 好吧,为了记录这个跌跌撞撞的认识过程,必须写一篇博客呀。   一、认识ireport iReport是一个开源...

dynamicreports demo

  • 2015年04月23日 12:02
  • 22.92MB
  • 下载

dynamicreports

  • 2015年01月11日 01:16
  • 41.43MB
  • 下载

React-Native项目技术分享(1)

网络封装 /** * 网络请求工具类 * Songlcy create * params:请求参数 * successCallback:成功回调 * failCallback:失败回调 ...

高通camera预览拍照流程1

  • 2017年12月11日 10:56
  • 872KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:dynamicreports1
举报原因:
原因补充:

(最多只允许输入30个字)