ExcelMergerData.java 1.71 KB
package com.yanzuoguang.excel;

import com.yanzuoguang.util.helper.StringHelper;

/**
 * 数据合并处理
 *
 * @author 颜佐光
 */
public class ExcelMergerData {

    /**
     * 上次合并的数据
     */
    private String data;

    /**
     * 合并行号
     */
    private int rowIndex = -1;

    /**
     * 数据合并行数
     */
    private int rowCell = 1;

    /**
     * 判断是否可以合并
     */
    private boolean mergerFlag = false;

    /**
     * 上次合并行号
     */
    private int rowIndexHistory = -1;

    /**
     * 上次合并单元格
     */
    private int rowCellHistory = 1;

    /**
     * 写入新数据
     *
     * @param rowIndex    行号
     * @param nowCellData 新数据
     */
    public void updateMerger(int rowIndex, String nowCellData) {
        this.mergerFlag = false;
        boolean isMergerSuccess = this.rowIndex == -1 || !StringHelper.compare(this.data, nowCellData);
        if (isMergerSuccess) {

            this.rowIndexHistory = this.rowIndex;
            this.rowCellHistory = this.rowCell;

            this.data = nowCellData;
            this.rowIndex = rowIndex;
            this.rowCell = 1;

            if (this.rowIndexHistory != -1) {
                this.mergerFlag = true;
            }

        } else {
            this.rowCell++;
        }
    }

    public String getData() {
        return data;
    }

    public int getRowIndex() {
        return rowIndex;
    }

    public int getRowCell() {
        return rowCell;
    }

    public boolean isMergerFlag() {
        return mergerFlag;
    }

    public int getRowIndexHistory() {
        return rowIndexHistory;
    }

    public int getRowCellHistory() {
        return rowCellHistory;
    }
}