Example usage for org.apache.poi.ss.usermodel Sheet shiftRows

List of usage examples for org.apache.poi.ss.usermodel Sheet shiftRows

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Sheet shiftRows.

Prototype

void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight);

Source Link

Document

Shifts rows between startRow and endRow n number of rows.

Usage

From source file:org.alanwilliamson.openbd.plugin.spreadsheet.functions.SpreadsheetShiftRows.java

License:Open Source License

public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
    cfSpreadSheetData spreadsheet = null;
    int start = 0, end = 0, rows = 1;

    /*//  w  w w . j  av a  2s .c  o  m
     * Collect up the parameters
     */
    if (parameters.size() == 2) {
        spreadsheet = (cfSpreadSheetData) parameters.get(1);
        start = parameters.get(0).getInt() - 1;
        end = start;
    } else if (parameters.size() == 3) {
        spreadsheet = (cfSpreadSheetData) parameters.get(2);
        start = parameters.get(1).getInt() - 1;
        rows = parameters.get(0).getInt() - 1;
    } else if (parameters.size() == 4) {
        spreadsheet = (cfSpreadSheetData) parameters.get(3);
        start = parameters.get(2).getInt() - 1;
        end = parameters.get(1).getInt() - 1;
        rows = parameters.get(0).getInt() - 1;
    }

    /*
     * Validate parameters
     */
    if (start < 0)
        throwException(_session, "column must be 1 or greater (" + start + ")");

    Sheet sheet = spreadsheet.getActiveSheet();
    sheet.shiftRows(start, end, rows, true, true);

    return cfBooleanData.TRUE;
}

From source file:org.tiefaces.components.websheet.utility.CellUtility.java

License:MIT License

/**
 * Copy rows./*from ww w . j a va 2s .  c o m*/
 *
 * @param srcSheet
 *            the src sheet
 * @param destSheet
 *            the dest sheet
 * @param srcRowStart
 *            the src row start
 * @param srcRowEnd
 *            the src row end
 * @param destRow
 *            the dest row
 * @param checkLock
 *            the check lock
 * @param setHiddenColumn
 *            the set hidden column
 */
public static void copyRows(final Sheet srcSheet, final Sheet destSheet, final int srcRowStart,
        final int srcRowEnd, final int destRow, final boolean checkLock, final boolean setHiddenColumn) {

    int length = srcRowEnd - srcRowStart + 1;
    if (length <= 0) {
        return;
    }
    destSheet.shiftRows(destRow, destSheet.getLastRowNum(), length, true, false);
    for (int i = 0; i < length; i++) {
        copySingleRow(srcSheet, destSheet, srcRowStart + i, destRow + i, checkLock, setHiddenColumn);
    }
    // If there are are any merged regions in the source row, copy to new
    // row
    for (int i = 0; i < srcSheet.getNumMergedRegions(); i++) {
        CellRangeAddress cellRangeAddress = srcSheet.getMergedRegion(i);
        if ((cellRangeAddress.getFirstRow() >= srcRowStart) && (cellRangeAddress.getLastRow() <= srcRowEnd)) {
            int targetRowFrom = cellRangeAddress.getFirstRow() - srcRowStart + destRow;
            int targetRowTo = cellRangeAddress.getLastRow() - srcRowStart + destRow;

            CellRangeAddress newCellRangeAddress = new CellRangeAddress(targetRowFrom, targetRowTo,
                    cellRangeAddress.getFirstColumn(), cellRangeAddress.getLastColumn());
            destSheet.addMergedRegion(newCellRangeAddress);
        }
    }
}