ongdisheng commented on issue #696:
URL: https://github.com/apache/fesod/issues/696#issuecomment-3556451821
Hi @delei, I tried using `EscapeHexCellWriteHandler`, but found it doesn't
work properly when reading back with `FesodSheet.read()`. I created a test to
demonstrate:
```java
@Test
public void testEscapeHexWithFesodRead() throws Exception {
// Write data with _xHHHH_ pattern using EscapeHexCellWriteHandler
List<DemoData> writeData = new ArrayList<>();
DemoData data = new DemoData();
data.setString("Product_xB9f0_Code");
data.setDate(new Date());
data.setDoubleData(123.45);
writeData.add(data);
File file = new File("escapehex_bug_demo.xlsx");
FesodSheet.write(file, DemoData.class)
.registerWriteHandler(new EscapeHexCellWriteHandler())
.sheet("Sheet1")
.doWrite(writeData);
String original = writeData.get(0).getString();
// Read with POI
String poiResult;
try (Workbook workbook = WorkbookFactory.create(file)) {
Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(1);
poiResult = row.getCell(0).getStringCellValue();
}
// Read with FesodSheet
List<DemoData> readData = new ArrayList<>();
FesodSheet.read(file, DemoData.class, new
AnalysisEventListener<DemoData>() {
@Override
public void invoke(DemoData data, AnalysisContext context) {
readData.add(data);
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
}).sheet().doRead();
String fesodResult = readData.get(0).getString();
System.out.println("Original: " + original);
System.out.println("POI read: " + poiResult);
System.out.println("FesodSheet read: " + fesodResult);
}
```
### Output:
[escapehex_bug_demo.xlsx](https://github.com/user-attachments/files/23648295/escapehex_bug_demo.xlsx)
```bash
Original: Product_xB9f0_Code
POI read: Product_xB9f0_Code
FesodSheet read: Product_x005F_xB9f0_Code
```
It seems like the `_x005F_` is not being decoded back. The handler works if
you read with POI's API like `WorkbookFactory.create`, but not with
`FesodSheet.read`. I looked into the code and found that
`SharedStringsTableHandler` has a `utfDecode` method that decodes `_xHHHH_`
patterns, but `CellTagHandler` doesn't decode them for inline strings. Since
`FesodSheet` uses `SXSSFWorkbook` by default which writes inline strings, the
decode doesn't happen when reading back. Just wondering if `utfDecode` was
intentionally only for shared strings, or should it also work for inline
strings?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]