Skip to content

Commit

Permalink
allow context to be set in XSSFSheet copyRows
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923793 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Feb 13, 2025
1 parent ca8014e commit f61ddde
Showing 1 changed file with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2900,7 +2900,6 @@ public void setZoom(int scale) {
dsv.setZoomScale(scale);
}


/**
* copyRows rows from srcRows to this sheet starting at destStartRow
*
Expand All @@ -2916,6 +2915,27 @@ public void setZoom(int scale) {
*/
@Beta
public void copyRows(List<? extends Row> srcRows, int destStartRow, CellCopyPolicy policy) {
copyRows(srcRows, destStartRow, policy, new CellCopyContext());
}

/**
* copyRows rows from srcRows to this sheet starting at destStartRow
*
* Additionally copies merged regions that are completely defined in these
* rows (ie. merged 2 cells on a row to be shifted).
* @param srcRows the rows to copy. Formulas will be offset by the difference
* in the row number of the first row in srcRows and destStartRow (even if srcRows
* are from a different sheet).
* @param destStartRow the row in this sheet to paste the first row of srcRows
* the remainder of srcRows will be pasted below destStartRow per the cell copy policy
* @param policy is the cell copy policy, which can be used to merge the source and destination
* when the source is blank, copy styles only, paste as value, etc
* @param context the context - see {@link CellCopyContext}
* @since POI 5.4.1
*/
@Beta
public void copyRows(List<? extends Row> srcRows, int destStartRow,
CellCopyPolicy policy, CellCopyContext context) {
if (srcRows == null || srcRows.isEmpty()) {
throw new IllegalArgumentException("No rows to copy");
}
Expand Down Expand Up @@ -2972,7 +2992,7 @@ public void copyRows(List<? extends Row> srcRows, int destStartRow, CellCopyPoli
}
//removeRow(destRowNum); //this probably clears all external formula references to destRow, causing unwanted #REF! errors
final XSSFRow destRow = createRow(destRowNum);
destRow.copyRowFrom(srcRow, options);
destRow.copyRowFrom(srcRow, options, context);
}

// ======================
Expand Down Expand Up @@ -3008,8 +3028,27 @@ public void copyRows(List<? extends Row> srcRows, int destStartRow, CellCopyPoli
*/
@Beta
public void copyRows(int srcStartRow, int srcEndRow, int destStartRow, CellCopyPolicy cellCopyPolicy) {
copyRows(srcStartRow, srcEndRow, destStartRow, cellCopyPolicy, new CellCopyContext());
}

/**
* Copies rows between srcStartRow and srcEndRow to the same sheet, starting at destStartRow
* Convenience function for {@link #copyRows(List, int, CellCopyPolicy, CellCopyContext)}
*
* Equivalent to copyRows(getRows(srcStartRow, srcEndRow, false), destStartRow, cellCopyPolicy)
*
* @param srcStartRow the index of the first row to copy the cells from in this sheet
* @param srcEndRow the index of the last row to copy the cells from in this sheet
* @param destStartRow the index of the first row to copy the cells to in this sheet
* @param cellCopyPolicy the policy to use to determine how cells are copied
* @param context the context - see {@link CellCopyContext}
* @since POI 5.4.1
*/
@Beta
public void copyRows(int srcStartRow, int srcEndRow, int destStartRow,
CellCopyPolicy cellCopyPolicy, CellCopyContext context) {
final List<XSSFRow> srcRows = getRows(srcStartRow, srcEndRow, false); //FIXME: should be false, no need to create rows where src is only to copy them to dest
copyRows(srcRows, destStartRow, cellCopyPolicy);
copyRows(srcRows, destStartRow, cellCopyPolicy, context);
}

/**
Expand Down

0 comments on commit f61ddde

Please sign in to comment.