Bug 63475 - XSSFRow.copyFromRow failed at cross-sheet copy trying utilize FormulaShifter
Summary: XSSFRow.copyFromRow failed at cross-sheet copy trying utilize FormulaShifter
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 5.0.0-FINAL
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: 2021-10-08 20:14 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
Comment 5 virinchi 2021-04-17 08:25:38 UTC
when can we expect this bug to be fixed.
Comment 6 Dominik Stadler 2021-04-17 12:40:44 UTC
Apache POI is a volunteer-only project, nobody is paid to work on it. So nobody is tasked with working on a specific bug and there is no ETA. 

If you would like to speed up things, you can try to help by doing some more analysis yourself and if possible provide a possible patch.
Comment 7 virinchi 2021-04-19 11:46:36 UTC
Thank you for replying.

Any work arounds that can be used for now?
Comment 8 PJ Fanning 2021-10-08 20:14:01 UTC
I added a fix for this - will appear in v5.1.0 release
Comment 9 PJ Fanning 2021-10-08 20:14:35 UTC
I added a fix for this - will appear in v5.1.0 release