示例#1
0
  @POST
  @At("/ht/pamlist")
  @Ok("json")
  public JSONObject list(@Param("..") Pages page, String sid) {
    JSONObject json = new JSONObject();
    json.put(Constant.SUCCESS, true);

    List<Record> list = baseService.dao.query(sid + ":parameterID", null, page.getNutzPager());

    json.put(Constant.TOTAL, baseService.dao.count(sid));

    JsonConfig cfg = new JsonConfig();
    cfg.setExcludes(new String[] {"station", "createDate"});
    JSONArray array = new JSONArray();

    Station sa = new Station();
    sa.setId(sid);
    sa = baseService.dao.fetch(sa);
    for (Record rd : list) {
      Parameter pm = this.record2Object(rd);
      JSONObject item = JSONObject.fromObject(pm, cfg);

      if (null != sa) {
        item.put("stationName", sa.getName());
      } else {
        item.put("stationName", "无");
      }

      item.put("ID", pm.getParameterID());
      item.put(
          "createDate",
          null != pm.getCreateDate()
              ? DateUtil.convertDateToString(pm.getCreateDate(), DateUtil.pattern2)
              : "");

      item.put("Es", pm.getEs());
      item.put("Fmin", pm.getFmin());
      item.put("M3000F1", pm.getM3000F1());
      item.put("M3000F2", pm.getM3000F2());

      array.add(item);
    }
    json.put(Constant.ROWS, array);
    return json;
  }
示例#2
0
文件: Test1.java 项目: naily/iph
  @Test
  public void createex() {
    Workbook wb = new HSSFWorkbook();
    CreationHelper createHelper = wb.getCreationHelper();
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFillPattern(CellStyle.NO_FILL);

    Sheet sheet = wb.createSheet("数据日志");
    Sheet sheet2 = wb.createSheet("second sheet");
    String safeName =
        WorkbookUtil.createSafeSheetName("[O'Brien's sales*?]"); // returns " O'Brien's sales   "
    Sheet sheet3 = wb.createSheet(safeName);

    Header header = sheet.getHeader();
    header.setCenter("Center Header");
    header.setLeft("Left Header");
    header.setRight(
        HSSFHeader.font("Stencil-Normal", "Italic")
            + HSSFHeader.fontSize((short) 16)
            + "Right w/ Stencil-Normal Italic font and size 16");

    sheet.setColumnWidth(0, 15 * 256); // .autoSizeColumn(0 ); // 调整第一列宽度
    sheet.setColumnWidth(1, 17 * 256); // 调整第二列宽度
    sheet.setColumnWidth(3, 17 * 256); // 调整第三列宽度
    sheet.autoSizeColumn(2); // 调整第四列宽度

    // Create a row and put some cells in it. Rows are 0 based.
    Row row = sheet.createRow((short) 1);
    // Create a cell and put a value in it.
    Cell cell = row.createCell(0);
    cell.setCellValue("ID");
    cell.setCellStyle(cellStyle);

    // Or do it on one line.
    row.createCell(1).setCellValue("表名");
    row.createCell(2).setCellValue(createHelper.createRichTextString("操作类型"));
    row.createCell(3).setCellValue("操作日期");
    row.createCell(4).setCellValue("操作者");

    List<Log> list = this.logList();
    Row rw;
    for (int i = 2; i < list.size(); i++) {
      Log log = list.get(i);
      rw = sheet.createRow((short) i);

      rw.createCell(0).setCellValue(createHelper.createRichTextString(log.getId()));
      rw.createCell(1).setCellValue(log.getDataTable());
      rw.createCell(2).setCellValue(this.convertActionType(log.getActionType()));
      rw.createCell(3)
          .setCellValue(DateUtil.convertDateToString(log.getLogDate(), DateUtil.pattern2));
      rw.createCell(4).setCellValue(log.getAdminId());
    }

    String bp = this.getClass().getResource("/").toString();
    try {
      System.out.println(bp);
      File f = new File("workbook.xls");
      FileOutputStream fileOut = new FileOutputStream(f);
      wb.write(fileOut);
      fileOut.close();
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }