You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2025/03/25 16:34:08 UTC

[Bug 69629] New: Explicit style of XSSFCell does not get retrieved

https://bz.apache.org/bugzilla/show_bug.cgi?id=69629

            Bug ID: 69629
           Summary: Explicit style of XSSFCell does not get retrieved
           Product: POI
           Version: 5.4.0-FINAL
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: dev@poi.apache.org
          Reporter: aoellerer@protonmail.com
  Target Milestone: ---

Created attachment 40010
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=40010&action=edit
A file to replicate the issue

I am using Apache POI XSSF to create spreadsheets where values can be resolved
dynamically (see https://github.com/DDS-GmbH/jocument).

A few days ago, I noticed an issue where in some cases the style of a cell is
not applied to a copy of the cell, but only the default style of the document.

While debugging this, I noticed that there seems to be a problem when
retrieving the explicit style of some cells (see attached file).
The code I am using to create a new cell from an existing one is the following:
```java
  private Cell createNewCell(Cell templateCell) {
    var newCell = currentRow.createCell(templateCell.getColumnIndex(),
templateCell.getCellType());
    newCell.setCellStyle(cellStyleMap.computeIfAbsent((int)
templateCell.getCellStyle().getIndex(), i ->
copyStyle(templateCell.getCellStyle())));
    return newCell;
  }

  private CellStyle copyStyle(CellStyle cellStyle) {
    var newStyle = workbook.createCellStyle();
    newStyle.cloneStyleFrom(cellStyle);
    return newStyle;
  }
```
Stepping into `templateCell.getCellStyle()`, I saw that
`XSSFCell#getExplicitCellStyle()` returns `null`, which is caused by
`_cell.isSetS()` returning `false`.

Looking at the xml, I can see that the value for the cell is
```xml
<c r="B2" s="17" t="s">
    <v>0</v>
</c>
```

Is this some issue during parsing/workbook creation, or did I understand
something wrong?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 69629] Explicit style of XSSFCell does not get retrieved

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69629

aoellerer@protonmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #1 from aoellerer@protonmail.com ---
It turned out that when invoking on an existing cell,
`currentRow.createCell(templateCell.getColumnIndex(),
templateCell.getCellType())`, the template cell was overwritten and the styling
removed

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 69629] Explicit style of XSSFCell does not get retrieved

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69629

Matafagafo <ma...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matafagafo@gmail.com

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org