⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 position.java

📁 Excel Report是一款基于Excel的报表生成工具
💻 JAVA
字号:
/***********************************************************************
 * Module:  Position.java
 * Author:  juny
 * Created: 2006年7月17日 12:42:59
 * Purpose: 用来管理坐标位置,并负责坐标间的转换。
 ***********************************************************************/

package net.excel.report.base;

/**
 * 坐标管理类,该类用来管理坐标位置,并负责坐标间的转换。
 * @author juny
 */
public class Position {
    public Position(int column, int row){
        this.col = column;
        this.row = row;
    }
    
    /**
     * 判断传入参数的位置是否是当前位置的下一个单元格
     * @param pos	当前坐标对象
     * @param ishorizon	true 表示是判断水平方向  false 表示判断垂直方向
     * @return true 当前对象的坐标是传入坐标对象的下一个坐标位	false 则不是
     */
    public boolean isNextPos(Position pos, boolean ishorizon){
        if(ishorizon){
            return pos.col == (this.col + 1);
        }else{
            return pos.row == (this.row + 1);
        }
    }
    /**
     * 取得Excel中单元格位置描述, 将以12表示的坐标转换成A01坐标表示方式
     * @return	返回当前坐标值在Excel中的描述字符串。
     */
    public String getPositionExcelDec() {
        int v = this.col / 26;
        int r = this.col % 26;

        StringBuffer tmp = new StringBuffer();
        while (v != 0) {
            char col = (char) ((int) 'A' + r);

            tmp.append(col);

            r = v % 26 - 1; // subtract one because only rows >26 preceded by A
            v = v / 26;
        }

        char column = (char) ((int) 'A' + r);
        tmp.append(column);

        StringBuffer buf = new StringBuffer();
        // Insert into the proper string buffer in reverse order
        for (int i = tmp.length() - 1; i >= 0; i--) {
            buf.append(tmp.charAt(i));
        }
        return buf.toString() + (row + 1);
    }
    
    public String toString(){
        return this.getPositionExcelDec();
    }
    
    private int col = 0;
    private int row = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -