ongdisheng commented on issue #687:
URL: https://github.com/apache/fesod/issues/687#issuecomment-3539431228
I think this issue occurs because `LongestMatchColumnWidthStyleStrategy` and
the manual `@ColumnWidth` handler operate independently, and they both call
`sheet.setColumnWidth()` on the same columns. Below is the current execution
order:
1. Manual width handler applies `@ColumnWidth` annotations first
2. `LongestMatchColumnWidthStyleStrategy` runs afterward for every cell
including header and data rows
3. The strategy overwrites the manual widths because it doesn't check if a
manual width was already set
## Proposed Approach
I think we can add a check to skip adaptive width calculation when
`@ColumnWidth` is present:
```java
// LongestMatchColumnWidthStyleStrategy.java
@Override
protected void setColumnWidth(...) {
boolean needSetWidth = isHead || !CollectionUtils.isEmpty(cellDataList);
if (!needSetWidth) {
return;
}
// Skip adaptive width if manual @ColumnWidth is specified
if (head != null && head.getColumnWidthProperty() != null) {
return;
}
// Continue with adaptive width calculation only for columns without
@ColumnWidth
Map<Integer, Integer> maxColumnWidthMap = ...
}
```
This can help to ensure:
- Columns with `@ColumnWidth`: Use the manual width and adaptive strategy
skips them
- Columns without `@ColumnWidth`: Use adaptive width based on content
Feel free to share any feedback or suggestions on this approach!
--
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]