Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grouping columns works only with a blank sheet #728

Closed
pragmaware opened this issue Jan 10, 2022 · 1 comment
Closed

Grouping columns works only with a blank sheet #728

pragmaware opened this issue Jan 10, 2022 · 1 comment

Comments

@pragmaware
Copy link

In certain cases XSSFSheet.GroupColumn() produces a overly large columns array in the xml output.
LibreOffice seems to interpret it properly (not sure if always) while Office 365 will either group the wrong number of columns or display no outline at all.

I've found out that it seems to work when it's applied to an empty sheet, when columns aren't present yet. When it's applied after some columns have been created then it seems to multiply them internally and produce wrong results.

The multiplication seems to happen in columnHelper.AddCleanColIntoCols(colsArray, newCol). In a debug session I did the following:

  1. created a sheet with 34 columns filled with some data and attributes
  2. grouped columns from 4 to 31
  3. after AddCleanColIntoCols() the column array contained 93 entries (!) and these were reflected in the produced xlsx file.

If I swap steps 1 and 2 then the resulting column array seems to be correct.

@tonyqus tonyqus added this to the NPOI 2.5.7 milestone Feb 14, 2022
@tonyqus tonyqus modified the milestones: NPOI 2.6.1, NPOI 2.6.2 Jun 13, 2023
@tonyqus tonyqus added this to the NPOI 2.7.0 milestone Jun 23, 2023
@artem-iron
Copy link
Contributor

Tested it with #1261 and at least the described behaviour isn't reproduced.

EDIT: To be fair, even on the master branch this isn't reproduced.

Tried with this code:

public void CheckIssue728()
{
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet("Sheet 1");
    for (int i = 0; i < 34; i++)
    {
        for (int j = 0; j < 34; j++)
        {
            var row = sheet.GetRow(i) ?? sheet.CreateRow(i);
            var cell = row.CreateCell(j);
            cell.SetCellValue("cell" + i + j);
        }
    }

    sheet.GroupColumn(4, 31);

    using (FileStream fs = new FileStream("test.xlsx", FileMode.Create, FileAccess.ReadWrite))
    {
        workbook.Write(fs);
    }

    workbook.Dispose();
}

@tonyqus tonyqus closed this as completed Mar 7, 2024
@tonyqus tonyqus added the xlsx label Mar 7, 2024
@tonyqus tonyqus removed this from the NPOI 2.7.0 milestone Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants