Пример #1
0
  /**
   * Extended headers / footers example
   *
   * @param args Unused
   */
  public static void main(String[] args) {
    System.out.println("Demonstrates use of the RtfHeaderFooter for extended headers and footers");
    try {
      Document document = new Document();
      RtfWriter2.getInstance(document, new FileOutputStream("ExtendedHeaderFooter.rtf"));

      // Create the Paragraphs that will be used in the header.
      Paragraph date = new Paragraph("01.01.2010");
      date.setAlignment(Paragraph.ALIGN_RIGHT);
      Paragraph address = new Paragraph("TheFirm\nTheRoad 24, TheCity\n" + "+00 99 11 22 33 44");

      // Create the RtfHeaderFooter with an array containing the Paragraphs to add
      RtfHeaderFooter header = new RtfHeaderFooter(new Element[] {date, address});

      // Set the header
      document.setHeader(header);

      // Create the table that will be used as the footer
      Table footer = new Table(2);
      footer.setBorder(0);
      footer.getDefaultCell().setBorder(0);
      footer.setWidth(100);
      footer.addCell(new Cell("(c) Mark Hall"));
      Paragraph pageNumber = new Paragraph("Page ");

      // The RtfPageNumber is an RTF specific element that adds a page number field
      pageNumber.add(new RtfPageNumber());
      pageNumber.setAlignment(Paragraph.ALIGN_RIGHT);
      footer.addCell(new Cell(pageNumber));

      // Create the RtfHeaderFooter and set it as the footer to use
      document.setFooter(new RtfHeaderFooter(footer));

      document.open();

      document.add(
          new Paragraph(
              "This document has headers and footers created"
                  + " using the RtfHeaderFooter class."));

      document.close();
    } catch (FileNotFoundException fnfe) {
      fnfe.printStackTrace();
    } catch (DocumentException de) {
      de.printStackTrace();
    }
  }
Пример #2
0
 /*
  * (non-Javadoc)
  *
  * @see com.afunms.report.ExportInterface#insertChart(java.lang.String)
  */
 public void insertChart(String path) throws Exception {
   if (!document.isOpen()) {
     document.open();
   }
   Image png = Image.getInstance(path);
   // png.scaleAbsolute(560, 320);
   png.scalePercent(90);
   Table pngtable = new Table(1);
   pngtable.setAutoFillEmptyCells(true);
   pngtable.setAlignment(Element.ALIGN_CENTER);
   pngtable.setCellsFitPage(true);
   pngtable.setWidth(100);
   pngtable.setBorder(0);
   RtfCell cell = new RtfCell(png);
   cell.setBorder(0);
   pngtable.addCell(cell);
   document.add(pngtable);
 }
Пример #3
0
  // utility function to make an item Element.
  private Table makeItemElement(ShoppingCartItemData pItm) throws DocumentException {

    Table itmTbl = new PTable(mColumnCount);
    itmTbl.setWidth(100);
    itmTbl.setWidths(itmColumnWidth);
    itmTbl.getDefaultCell().setBorderColor(java.awt.Color.black);
    itmTbl.getDefaultCell().setVerticalAlignment(Cell.ALIGN_TOP);
    itmTbl.setOffset(0);
    itmTbl.setBorder(Table.NO_BORDER);

    if (!catalogOnly) {
      String t0 = "";
      if (pItm.getIsaInventoryItem()) {
        t0 = "i";
      }

      if (null != mSiteData
          && mSiteData.isAnInventoryAutoOrderItem(pItm.getProduct().getProductId())) {
        t0 += "a";
      }

      Cell tpc0 = new Cell(makePhrase(t0, small, true));
      if (!pItm.getIsaInventoryItem()) {
        tpc0.setBorder(0);
      }
      itmTbl.addCell(tpc0);
    }

    Cell tpc01 = new Cell(makePhrase("", normal, true));
    itmTbl.addCell(tpc01);

    String t = "";
    if (pItm.getProduct().isPackProblemSku()) {
      t += "*";
    }
    if (t.length() > 0) t += " ";
    Cell tpc1 = new Cell(makePhrase(t + pItm.getActualSkuNum(), normal, true));
    itmTbl.addCell(tpc1);

    itmTbl.addCell(makePhrase(pItm.getProduct().getCatalogProductShortDesc(), normal, true));
    if (mShowSize) {
      itmTbl.addCell(makePhrase(pItm.getProduct().getSize(), normal, true));
    }
    // itmTbl.addCell(makePhrase(pItm.getProduct().getPack(), normal, true));
    // itmTbl.addCell(makePhrase(pItm.getProduct().getUom(), normal, true));
    // itmTbl.addCell(makePhrase(pItm.getProduct().getManufacturerName(),normal,true));

    if (mShowPrice) {
      BigDecimal price = new BigDecimal(pItm.getPrice());
      String priceStr = "";
      try {
        priceStr = mFormatter.priceFormatWithoutCurrency(price);
      } catch (Exception exc) {
        exc.printStackTrace();
      }
      Cell pcell = new Cell(makePhrase(priceStr, normal, true));
      pcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
      itmTbl.addCell(pcell);
    }

    if (catalogOnly) {
      if (pItm.getProduct() != null
          && pItm.getProduct().getCatalogDistrMapping() != null
          && Utility.isTrue(pItm.getProduct().getCatalogDistrMapping().getStandardProductList())) {
        String yStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.y", null);
        itmTbl.addCell(makePhrase(yStr, normal, true));
      } else {
        String nStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.n", null);
        itmTbl.addCell(makePhrase(nStr, normal, true));
      }
    }

    if (!catalogOnly) {
      // BigDecimal amount = new BigDecimal(pItm.getAmount());
      itmTbl.addCell(makePhrase("", normal, true));
    }

    return itmTbl;
  }
  // int sportId = 1;
  public void SelPlaWD(String filePath, String fileName) {

    SelectPlayerDAO sd = new SelectPlayerDAO();
    // ArrayList departList = new ArrayList();
    ArrayList stuDepartList = new ArrayList();
    ArrayList teaDepartList = new ArrayList();
    // ArrayList selectSportsid=new ArrayList();
    // departList=sd.selectDepartment(sportId);
    // selectSportsid=sd.selectSportsid();

    stuDepartList = sd.slectStuDepidBySid(sportId);
    teaDepartList = sd.selectDepartment(sportId);
    Document document = new Document(PageSize.A4);
    try {
      RtfWriter2.getInstance(document, new FileOutputStream(filePath + fileName));

      document.open();

      for (int i = 0; i < stuDepartList.size(); i++) {

        int id = Integer.parseInt(stuDepartList.get(i).toString());
        // int sid = Integer.parseInt(selectSportsid.get(i).toString());
        ArrayList playBoy = new ArrayList();
        ArrayList playGirl = new ArrayList();
        // ArrayList playTeacher = new ArrayList();
        // int type=sd.selectDepartmentType(id);
        // if(type==1){
        // 查询学生男子组的姓名和号码
        playBoy = sd.selectPlayersByDept(1, id, sportId);
        String groupname = "男子组";
        String departname = sd.selectDepartmentName(id);
        Paragraph p =
            new Paragraph(departname, new Font(Font.BOLD, 18, Font.BOLD, new Color(0, 0, 0)));
        p.setAlignment(1);
        document.add(p);
        // document.add(new Paragraph(groupname));
        Table table = new Table(8);
        Cell cc5 = new Cell(groupname);

        cc5.setColspan(8);
        cc5.setBorderWidth(0);
        table.addCell(cc5);

        // 指定表格为八列

        table.setBorder(0);
        table.setBorderWidth(0);
        table.setBorderColor(Color.WHITE);
        table.setPadding(0);
        table.setSpacing(0);
        for (int a = 0; a < playBoy.size(); a++) {
          PlayerPojo pojp = (PlayerPojo) playBoy.get(a);

          Cell cc = new Cell(pojp.getPlayernum());
          cc.setBorderWidth(0);
          table.addCell(cc);
          Cell ce = new Cell(pojp.getPlayername());
          ce.setBorderWidth(0);
          table.addCell(ce);
        }

        // document.add(p1);
        document.add(table);
        // 查询学生女子组的姓名和号码
        Table table1 = new Table(8);
        // 指定表格为八列
        table1.setBorder(0);
        table1.setBorderWidth(0);
        table1.setBorderColor(Color.WHITE);
        table1.setPadding(0);
        table1.setSpacing(0);
        playGirl = sd.selectPlayersByDept(0, id, sportId);
        String groupname1 = "女子组";
        // document.add(new Paragraph(groupname1));

        Cell cc6 = new Cell(groupname1);
        cc6.setColspan(8);
        cc6.setBorderWidth(0);
        table1.addCell(cc6);

        for (int a = 0; a < playGirl.size(); a++) {
          PlayerPojo pojp = (PlayerPojo) playGirl.get(a);
          Cell cc1 = new Cell(pojp.getPlayernum());
          cc1.setBorderWidth(0);
          table1.addCell(cc1);
          Cell ce1 = new Cell(pojp.getPlayername());
          ce1.setBorderWidth(0);
          table1.addCell(ce1);
        }
        document.add(table1);
        document.add(new Paragraph());
        document.add(new Paragraph());
        // } else{
      }
      for (int i = 0; i < teaDepartList.size(); i++) {
        int id = Integer.parseInt(teaDepartList.get(i).toString());
        ArrayList playTeacher = sd.selectPlayersByDept1(id, sportId);

        String groupname = "教工组";
        String departname = sd.selectDepartmentName(id);
        Paragraph p =
            new Paragraph(departname, new Font(Font.BOLD, 18, Font.BOLD, new Color(0, 0, 0)));
        p.setAlignment(1);
        document.add(p);
        // document.add(new Paragraph(groupname));
        Table table2 = new Table(8);
        Cell cc6 = new Cell(groupname);
        cc6.setColspan(8);
        cc6.setBorderWidth(0);
        table2.addCell(cc6);

        // 指定表格为八列

        table2.setBorder(0);
        table2.setBorderWidth(0);
        table2.setBorderColor(Color.WHITE);
        table2.setPadding(0);
        table2.setSpacing(0);
        for (int a = 0; a < playTeacher.size(); a++) {
          PlayerPojo pojp = (PlayerPojo) playTeacher.get(a);

          Cell cc = new Cell(pojp.getPlayernum());
          cc.setBorderWidth(0);
          table2.addCell(cc);
          Cell ce = new Cell(pojp.getPlayername());
          ce.setBorderWidth(0);
          table2.addCell(ce);
        }
        document.add(table2);
      }

      // 查询教工组的姓名和号码

      // document.add(p1);

      document.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (DocumentException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }