Пример #1
0
  public void runCommand(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
    if (itemStack != null || NBTHelper.getBoolean(itemStack, "isSet")) {
      switch (NBTHelper.getInt(itemStack, "commandID")) {
        case 0: // toggleDownFall
          toggleDownfall();
          break;
        case 1: // give Random
          giveItem(entityPlayer);
          break;
        case 2: // kill Entity
          // EntityLivingBase entity = (EntityLivingBase) getEntityLookingAt(world, entityPlayer);

          break;
        case 3: // time set day
          setTime(world, entityPlayer, "day");
          break;
        case 4: // time set night
          setTime(world, entityPlayer, "night");
          break;
        default:
          LogHelper.error("Error running command in ItemCommandScroll");
          LogHelper.error("Case index out of bounds:" + NBTHelper.getInt(itemStack, "commandID"));
          break;
      }
    }
  }
Пример #2
0
  /**
   * 写入公式
   *
   * @param colNum 列号
   * @param rowNum 行号
   * @param formula 写入公式内容
   */
  public void setFormula(int colNum, int rowNum, String formula) {
    try {
      wrCurrentSheet.addCell(new Formula(6, 3, formula));

    } catch (RowsExceededException e) {
      logger.error(e.getMessage());
      throw new BaseException(e);
    } catch (WriteException e) {
      logger.error(e.getMessage());
      throw new BaseException(e);
    }
  }
Пример #3
0
 /**
  * 写入文本值
  *
  * @param colNum 列号
  * @param rowNum 行号
  * @param sText 文本内容
  */
 public void setText(int colNum, int rowNum, String sText) {
   Label labelc = new Label(colNum, rowNum, sText);
   try {
     // 写入文本值
     wrCurrentSheet.addCell(labelc);
   } catch (RowsExceededException e) {
     logger.error(e.getMessage());
     throw new BaseException(e);
   } catch (WriteException e) {
     logger.error(e.getMessage());
     throw new BaseException(e);
   }
 }
Пример #4
0
 /**
  * 写入数值
  *
  * @param colNum 列号
  * @param rowNum 行号
  * @param num 数值
  */
 public void setNumber(int colNum, int rowNum, double num) {
   jxl.write.Number number = new jxl.write.Number(colNum, rowNum, num);
   try {
     // 写入数值
     wrCurrentSheet.addCell(number);
   } catch (RowsExceededException e) {
     logger.error(e.getMessage());
     throw new BaseException(e);
   } catch (WriteException e) {
     logger.error(e.getMessage());
     throw new BaseException(e);
   }
 }
Пример #5
0
 /**
  * 从(开始行号,开始列号)起,到xls有效数据行结束, 按行取得一个sheet中所有数据,行号作为map中key值 一行中的所有数据放置为list中作为map的value值
  *
  * @return
  */
 public HashMap<String, List> getExcelMapByRow(int iBeginCol, int iBeginRow, String sheetName) {
   try {
     // 设置当前操作sheet
     setCurrentSheet(sheetName);
     // 数据存放map
     HashMap<String, List> map = new HashMap<String, List>();
     int i, j, iRowSum, iColSum;
     // 取得有效数据行数
     iRowSum = getRows();
     // 取得有效数据列数
     iColSum = getCols();
     for (i = iBeginRow; i < iRowSum; i++) {
       // 用于存放一行数据的list
       List<String> lst = new ArrayList<String>();
       for (j = iBeginCol; j < iColSum; j++) {
         lst.add(getCell(j, i).getContents().toString().trim());
       }
       // 行号作为key,将数据存放,map中
       map.put(String.valueOf(i), lst);
     }
     return map;
   } catch (Exception e) {
     logger.error(e.getMessage());
     throw new BaseException(e);
   }
 }
Пример #6
0
 /**
  * 创建xls
  *
  * @param fileName 文件名
  */
 public void createXLS(String fileName) {
   try {
     // 创建workbook
     wrWorkbook = Workbook.createWorkbook(new File(fileName));
   } catch (IOException e) {
     logger.error(e.getMessage());
     throw new BaseException(e);
   }
 }
Пример #7
0
 /**
  * 取得文本公式的cell
  *
  * @param colNum 列号
  * @param rowNum 行号
  * @return
  */
 public StringFormulaCell getStringFormulaCell(int colNum, int rowNum) {
   Cell cell = getCell(colNum, rowNum);
   // 如果cell为字符公式型cell
   if (cell instanceof StringFormulaCell) {
     return (StringFormulaCell) cell;
   } else {
     logger.error("cell type is not StringFormulaCell");
     throw new BaseException("cell type is not StringFormulaCell");
   }
 }
Пример #8
0
 /**
  * 取得日期公式的cell
  *
  * @param colNum 列号
  * @param rowNum 行号
  * @return
  */
 public DateFormulaCell getDateFormulaCell(int colNum, int rowNum) {
   Cell cell = getCell(colNum, rowNum);
   // 如果cell为日期公式型
   if (cell instanceof DateFormulaCell) {
     return (DateFormulaCell) cell;
   } else {
     logger.error("cell type is not DateFormulaCell");
     throw new BaseException("cell type is not DateFormulaCell");
   }
 }
Пример #9
0
 /**
  * 取得字符型的cell
  *
  * @param colNum 列号
  * @param rowNum 行号
  * @return
  */
 public LabelCell getLabelCell(int colNum, int rowNum) {
   Cell cell = getCell(colNum, rowNum);
   // 如果cell为日期型cell
   if (cell instanceof LabelCell) {
     return (LabelCell) cell;
   } else {
     logger.error("cell type is not LabelCell");
     throw new BaseException("cell type is not LabelCell");
   }
 }
Пример #10
0
 /** 写入xls */
 public void writeXls() {
   try {
     if (wrWorkbook != null) {
       wrWorkbook.write();
     }
   } catch (IOException e) {
     logger.error(e.getMessage());
     throw new BaseException(e);
   }
 }
Пример #11
0
 /** 关闭xls */
 public void closeXls() {
   try {
     if (readOnlyWBook == true) {
       if (wrWorkbook != null) {
         wrWorkbook.close();
       }
     } else {
       if (workbook != null) {
         workbook.close();
       }
     }
   } catch (WriteException e) {
     logger.error(e.getMessage());
     throw new BaseException(e);
   } catch (IOException e) {
     logger.error(e.getMessage());
     throw new BaseException(e);
   }
 }
Пример #12
0
  /**
   * 写入日期型
   *
   * @param colNum 列号
   * @param rowNum 行号
   * @param dt 日期或时间
   * @param dateformat “YYY-MM-dd” "YYYY-MM-dd hh:mm:ss" 日期或时间格式
   */
  public void setDate(int colNum, int rowNum, Date dt, String dateformat) {
    try {
      // 定义日期格式
      DateFormat df = new DateFormat(dateformat);
      // 定义cell的日期格式
      WritableCellFormat wcfDF = new WritableCellFormat(df);

      DateTime labelDTF = new DateTime(colNum, rowNum, dt, wcfDF);
      // 写入日期
      wrCurrentSheet.addCell(labelDTF);

    } catch (RowsExceededException e) {
      logger.error(e.getMessage());
      throw new BaseException(e);
    } catch (WriteException e) {
      logger.error(e.getMessage());
      throw new BaseException(e);
    }
  }
Пример #13
0
 /**
  * 取得布尔公式的cell
  *
  * @param colNum 列号
  * @param rowNum 行号
  * @return
  */
 public BooleanFormulaCell getBooleanFormula(int colNum, int rowNum) {
   Cell cell = getCell(colNum, rowNum);
   // 如果cell为布尔公式型
   if (cell instanceof BooleanFormulaCell) {
     return (BooleanFormulaCell) cell;
   } else {
     logger.error("cell type is not BooleanFormulaCell");
     throw new BaseException("cell type is not BooleanFormulaCell");
   }
 }
Пример #14
0
 /**
  * 取得数字公式的cell
  *
  * @param colNum 列号
  * @param rowNum 行号
  * @return
  */
 public NumberFormulaCell getNumberFormulaCell(int colNum, int rowNum) {
   Cell cell = getCell(colNum, rowNum);
   // 如果cell为数值公式型cell
   if (cell instanceof NumberFormulaCell) {
     return (NumberFormulaCell) cell;
   } else {
     logger.error("cell type is not NumberFormulaCell");
     throw new BaseException("cell type is not NumberFormulaCell");
   }
 }
Пример #15
0
  /** 只用于读取xls数据 xls文件名做成参数 */
  public ExcelOper(File file) {
    try {
      // Workbook workbook = null;
      readOnlyWBook = true;
      // 设置workbook
      workbook = Workbook.getWorkbook(file);
    } catch (BiffException e) {
      logger.error(e.getMessage());
      throw new BaseException(e);
    } catch (IOException e) {
      logger.error(e.getMessage());
      throw new BaseException(e);
    }
    // 设置当前工作workbook
    if (workbook != null) {

      setWorkbook(workbook);
    }
  }
Пример #16
0
 /**
  * 用于根据模板生成新的xls
  *
  * @param tplFile 模板文件路径
  * @param sFile 新的文件路径
  */
 public ExcelOper(File tplFile, File sFile) {
   try {
     // 取得模板文件
     workbook = Workbook.getWorkbook(tplFile);
     // 生成新文件
     wrWorkbook = Workbook.createWorkbook(sFile, workbook);
     readOnlyWBook = false;
   } catch (BiffException e) {
     // 写日志
     logger.error(e.getMessage());
     // 抛出异常
     throw new BaseException(e);
   } catch (IOException e) {
     // 写日志
     logger.error(e.getMessage());
     // 抛出异常
     throw new BaseException(e);
   }
 }
Пример #17
0
  /**
   * 取得空的cell
   *
   * @param colNum
   * @param rowNum
   * @return
   */
  public EmptyCell getEmptyCell(int colNum, int rowNum) {

    Cell cell = getCell(colNum, rowNum);
    // 如果cell为空cell
    if (cell instanceof EmptyCell) {

      return (EmptyCell) cell;

    } else {
      logger.error("cell type is not EmptyCell");
      throw new BaseException("cell type is not EmptyCell");
    }
  }
Пример #18
0
 private void setTime(World world, EntityPlayer entityPlayer, String timeStr) {
   long time;
   if (timeStr == "day") {
     time = 1000;
   } else if (timeStr == "night") {
     time = 13000;
   } else {
     time = 0;
     LogHelper.error("Improper setTime call in ItemCommandScroll");
   }
   for (int j = 0; j < MinecraftServer.getServer().worldServers.length; ++j) {
     MinecraftServer.getServer().worldServers[j].setWorldTime(time);
   }
 }
Пример #19
0
 /**
  * 取得公式内容
  *
  * @param colNum
  * @param rowNum
  * @return
  * @throws FormulaException
  */
 public String getFormula(int colNum, int rowNum) throws FormulaException {
   Cell cell = getCell(colNum, rowNum);
   FormulaCell nfc = (FormulaCell) cell;
   // 如果为公式类型
   if (cell.getType() == CellType.NUMBER_FORMULA
       || cell.getType() == CellType.STRING_FORMULA
       || cell.getType() == CellType.BOOLEAN_FORMULA
       || cell.getType() == CellType.DATE_FORMULA
       || cell.getType() == CellType.FORMULA_ERROR) {
     return nfc.getFormula();
   } else {
     logger.error("cell is not Formula");
     throw new BaseException("cell is not Formula");
   }
 }
Пример #20
0
 /**
  * 锁定单元格
  *
  * @param colNum 列号
  * @param rowNum 行号
  * @param bln true:锁定 ,false :取消
  */
 public void setLock(int colNum, int rowNum, Boolean bln) {
   WritableCellFormat format_unlock = new WritableCellFormat();
   try {
     // 锁定单元格
     if (bln == true) {
       format_unlock.setLocked(true);
       // 解锁单元格
     } else {
       format_unlock.setLocked(false);
     }
     wrCurrentSheet.getWritableCell(colNum, rowNum).setCellFormat(format_unlock);
   } catch (WriteException e) {
     logger.error(e.getMessage());
     throw new BaseException(e);
   }
 }