nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Apache License 2.0
5.74k stars 1.43k forks source link

HSSFWorkbook . After moving a row down , it fails to copy the row correctly. #1425

Open yoi102 opened 2 months ago

yoi102 commented 2 months ago

NPOI Version

2.7.1

File Type

Upload the Excel File

input.xls

Reproduce Steps

string inputFile = "input.xlsx";
IWorkbook workbook;

using (FileStream file = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
    workbook = new HSSFWorkbook(file);
    //workbook = new XSSFWorkbook(file);
}

ISheet sheet = workbook.GetSheetAt(0);

sheet.ShiftRows(3, sheet.LastRowNum, 1);
sheet.CopyRow(4, 3);

string outputFile = "output.xlsx";
using (FileStream file = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
{
    workbook.Write(file);
}

Issue Description

After moving a row down, it fails to copy the row correctly, and the output does not match the expected result.

inpuit:

image

output:

image

The output result of XSSFWorkbook is shown in the following image:(Expected result):

image

tonyqus commented 1 day ago

1329 contains a fix for row-shifting