Пример #1
0
 /**
  * Counts the Data objects returned by the {@link DataIterator}.
  *
  * @param it provides the iterator of Data objects to be counted.
  * @return the count of Data objects.
  */
 public static int count(DataIterator it) {
   @SuppressWarnings("unused") // used in while loop
   int count = 0;
   for (DataElement element = it.next(); element != null; element = it.next()) {
     count++;
   }
   return count;
 }
Пример #2
0
  public static void export(
      String field, String value, String start, String end, TaodianApi api, OutputStream os) {
    try {
      WritableWorkbook wbook = Workbook.createWorkbook(os);
      WritableSheet wsheet = wbook.createSheet("访问详情", 0);

      WritableFont wfont =
          new WritableFont(
              WritableFont.ARIAL,
              16,
              WritableFont.BOLD,
              false,
              UnderlineStyle.NO_UNDERLINE,
              Colour.BLACK);
      WritableCellFormat wcfFC = new WritableCellFormat(wfont);
      wcfFC.setBackground(Colour.AQUA);
      // wsheet.addCell(new Label(1, 0, tmptitle, wcfFC));
      wfont =
          new jxl.write.WritableFont(
              WritableFont.ARIAL,
              14,
              WritableFont.BOLD,
              false,
              UnderlineStyle.NO_UNDERLINE,
              Colour.BLACK);
      wcfFC = new WritableCellFormat(wfont);

      int row = 0;

      wsheet.addCell(new Label(0, row, "短网址"));
      wsheet.setColumnView(0, 10);

      wsheet.addCell(new Label(1, row, "商家"));
      wsheet.setColumnView(1, 12);

      wsheet.addCell(new Label(2, row, "商品"));
      wsheet.setColumnView(2, 12);

      wsheet.addCell(new Label(3, row, "推广者"));
      wsheet.setColumnView(3, 6);

      wsheet.addCell(new Label(4, row, "点击单价"));
      wsheet.setColumnView(4, 7);

      wsheet.addCell(new Label(5, row, "访问IP"));
      wsheet.setColumnView(5, 14);

      wsheet.addCell(new Label(6, row, "访问设备"));
      wsheet.setColumnView(6, 8);

      wsheet.addCell(new Label(7, row, "浏览器"));
      wsheet.setColumnView(7, 8);

      wsheet.addCell(new Label(8, row, "访问时间"));
      wsheet.setColumnView(8, 20);

      wsheet.addCell(new Label(9, row, "访问者ID"));
      wsheet.setColumnView(9, 12);

      wsheet.addCell(new Label(10, row, "访问来源"));
      wsheet.setColumnView(10, 80);

      wsheet.addCell(new Label(11, row, "Agent"));
      wsheet.setColumnView(11, 80);

      DataIterator data = new DataIterator(field, value, start, end, api);

      row++;
      while (data.hasNext()) {
        writeRow(wsheet, data.next(), row++);
      }

      wbook.write(); // 写入文件
      wbook.close();

    } catch (Exception e) {
      log.error(e, e);
    }
  }