Bug 63475 - XSSFRow.copyFromRow failed at cross-sheet copy trying utilize FormulaShifter
Summary: XSSFRow.copyFromRow failed at cross-sheet copy trying utilize FormulaShifter
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 4.0.x-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
: 63352 (view as bug list)
Depends on:
Reported: 2019-05-30 11:27 UTC by VoloMyhal
Modified: 2020-01-01 20:02 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
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);
   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);
Comment 3 Dominik Stadler 2020-01-01 20:02:06 UTC
*** Bug 63352 has been marked as a duplicate of this bug. ***
Comment 4 Dominik Stadler 2020-01-01 20:02:39 UTC
There is some more information and a workaround discussed at https://stackoverflow.com/questions/54430518/why-am-i-getting-illegalargumentexception-while-using-copyrowfrom-in-xssfro