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
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-30 11:27 UTC by VoloMyhal
Modified: 2019-10-11 17:18 UTC (History)
0 users



Attachments

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);
   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);
}