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 2024/10/02 16:02:32 UTC
[Bug 69366] New: CellUtil.setCellStyleProperties(Cell, Map) doesn't found same styles sometimes
https://bz.apache.org/bugzilla/show_bug.cgi?id=69366
Bug ID: 69366
Summary: CellUtil.setCellStyleProperties(Cell, Map<String,
Object>) doesn't found same styles sometimes
Product: POI
Version: 5.3.0-FINAL
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: XSSF
Assignee: dev@poi.apache.org
Reporter: fjyoyd89fd8c@mail.ru
Target Milestone: ---
I found out that CellUtil.setCellStyleProperties(Cell, Map<String, Object>)
doesn't found same styles sometimes. Especially when I set fillBackgroundColor
or fillForegroundColor property to null. It happens when setCellStyleProperties
calls getFormatProperties for already existed styles. Then getFormatProperties
calls XSSFCellStyle.getFillForegroundColor which return 64 instead of null.
Then styleMapsMatch says that these styles are different.
I suggest add some checks in setCellStyleProperties or styleMapsMatch. Or
prevent overwriting null to 64.
Hope you are ok with kotlin. Some code:
import org.apache.poi.ss.util.CellUtil.*
import org.apache.poi.xssf.usermodel.XSSFWorkbook
fun main() {
val workbook = XSSFWorkbook()
val sheet = workbook.createSheet()
val properties = mapOf(
FILL_FOREGROUND_COLOR to null,
FILL_BACKGROUND_COLOR to null,
)
for (i in 0..1000) {
val cell = getCell(getRow(0, sheet), i)
setCellStyleProperties(cell, properties)
}
println(workbook.numCellStyles)
}
Expected: 2
Actually: 1002
--
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 69366] CellUtil.setCellStyleProperties(Cell, Map) doesn't found same styles sometimes
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69366
--- Comment #2 from fjyoyd89fd8c@mail.ru ---
Of cause second from the end line should be
CellUtil.setCellStylePropertiesEnum(cell2, properties);
But bug exist even for same cell
--
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 69366] CellUtil.setCellStyleProperties(Cell, Map) doesn't found same styles sometimes
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69366
fjyoyd89fd8c@mail.ru changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
CC| |fjyoyd89fd8c@mail.ru
--
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 69366] CellUtil.setCellStyleProperties(Cell, Map) doesn't found same styles sometimes
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69366
--- Comment #3 from fjyoyd89fd8c@mail.ru ---
I got some results. New tests
@Test
public void testBug69366ColorSameCell() throws IOException {
try (Workbook workbook = new XSSFWorkbook()) {
final Sheet sheet = workbook.createSheet("Sheet");
final Row row = sheet.createRow(0);
final Cell cell = row.createCell(0);
Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR, null);
CellUtil.setCellStylePropertiesEnum(cell, properties);
int numStyles = workbook.getNumCellStyles();
CellUtil.setCellStylePropertiesEnum(cell, properties);
assertEquals(numStyles, workbook.getNumCellStyles());
}
}
@Test
public void testBug69366ColorDiffCell() throws IOException {
try (Workbook workbook = new XSSFWorkbook()) {
final Sheet sheet = workbook.createSheet("Sheet");
final Row row = sheet.createRow(0);
final Cell cell1 = row.createCell(0);
final Cell cell2 = row.createCell(1);
Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR, null);
CellUtil.setCellStylePropertiesEnum(cell1, properties);
int numStyles = workbook.getNumCellStyles();
CellUtil.setCellStylePropertiesEnum(cell2, properties);
assertEquals(numStyles, workbook.getNumCellStyles());
}
}
@Test
public void testBug69366ColorColorSameCell() throws IOException,
DecoderException {
try (Workbook workbook = new XSSFWorkbook()) {
final Sheet sheet = workbook.createSheet("Sheet");
final Row row = sheet.createRow(0);
final Cell cell = row.createCell(0);
final XSSFColor color = new XSSFColor(Hex.decodeHex("FFAAAA"));
Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR,
color);
CellUtil.setCellStylePropertiesEnum(cell, properties);
int numStyles = workbook.getNumCellStyles();
CellUtil.setCellStylePropertiesEnum(cell, properties);
assertEquals(numStyles, workbook.getNumCellStyles());
}
}
@Test
public void testBug69366ColorColorDiffCell() throws IOException,
DecoderException {
try (Workbook workbook = new XSSFWorkbook()) {
final Sheet sheet = workbook.createSheet("Sheet");
final Row row = sheet.createRow(0);
final Cell cell1 = row.createCell(0);
final Cell cell2 = row.createCell(1);
final XSSFColor color = new XSSFColor(Hex.decodeHex("FFAAAA"));
Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR,
color);
CellUtil.setCellStylePropertiesEnum(cell1, properties);
int numStyles = workbook.getNumCellStyles();
CellUtil.setCellStylePropertiesEnum(cell2, properties);
assertEquals(numStyles, workbook.getNumCellStyles());
}
}
The first and the second both don't pass test. The third pass and the fourth
fail. Obviously this all applies to background color too.
--
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 69366] CellUtil.setCellStyleProperties(Cell, Map) doesn't found same styles sometimes
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69366
--- Comment #1 from fjyoyd89fd8c@mail.ru ---
Just to check on last commit
(https://github.com/apache/poi/commit/f1a5571a617b62219df99a5faf7eaa7ce4cf0850)
I wrote test
@Test
public void testBug69366() throws IOException {
try (Workbook workbook = new XSSFWorkbook()) {
final Sheet sheet = workbook.createSheet("Sheet");
final Row row = sheet.createRow(0);
final Cell cell1 = row.createCell(0);
final Cell cell2 = row.createCell(1);
Map<CellPropertyType, Object> properties = new LinkedHashMap<>();
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR, null);
CellUtil.setCellStylePropertiesEnum(cell1, properties);
int numStyles = workbook.getNumCellStyles();
CellUtil.setCellStylePropertiesEnum(cell1, properties);
assertEquals(numStyles, workbook.getNumCellStyles());
}
}
Bug still here
--
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 69366] CellUtil.setCellStyleProperties(Cell, Map) doesn't found same styles sometimes
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69366
PJ Fanning <fa...@yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #4 from PJ Fanning <fa...@yahoo.com> ---
see https://github.com/apache/poi/pull/1338
--
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