Bug 63475

Summary: XSSFRow.copyFromRow failed at cross-sheet copy trying utilize FormulaShifter
Product: POI Reporter: VoloMyhal <volo.myhal>
Component: XSSFAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: 4.0.x-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description VoloMyhal 2019-05-30 11:27:23 UTC
XSSFRow.copyFromRow is failed when try to copy Row having the same row-index from another Sheet.

It calls FormulaShifter.createForRowCopy passing rowDifference=0, which in turns raises IllegalArgumentException("amountToMove must not be zero").

I suppose, for cross-sheet row copy FormulaShifter should be adapted, or at least skipped.
Comment 1 Dominik Stadler 2019-06-20 08:16:03 UTC
Can you provide some sample code and sample file to make it possible to reproduce this more easily?
Comment 2 Paul Bilnoski 2019-10-11 17:18:50 UTC
Here is a simple test case that attempts to copy data across sheets at the same row index:

try (XSSFWorkbook wb = new XSSFWorkbook())
{
   XSSFSheet first = wb.createSheet();
   XSSFRow row = first.createRow(0);
   row.createCell(0).setCellValue("Value");
   XSSFSheet second = wb.createSheet();
   second.copyRows(Collections.singletonList(row), 0, new CellCopyPolicy());
}
catch (Exception e)
{
   /* poi-ooxml-4.1.0.jar
    java.lang.IllegalArgumentException: amountToMove must not be zero
    at org.apache.poi.ss.formula.FormulaShifter.<init>(FormulaShifter.java:80)
    at org.apache.poi.ss.formula.FormulaShifter.createForRowCopy(FormulaShifter.java:118)
    at org.apache.poi.xssf.usermodel.XSSFRow.copyRowFrom(XSSFRow.java:623)
    at org.apache.poi.xssf.usermodel.XSSFSheet.copyRows(XSSFSheet.java:2938)
    */
   throw new IllegalStateException(e);
}