-
Notifications
You must be signed in to change notification settings - Fork 369
Render and fill the template with automatic handling of cell merging functionality 渲染填充模板自动处理单元格合并功能 #397
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
base: main
Are you sure you want to change the base?
Conversation
…he merge styles of the first row
…he merge styles of the first row
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request implements automatic handling of cell merging when filling Excel templates, ensuring that newly added rows inherit merge information under specific FillConfig settings. Key changes include:
- Addition of a new test case in TemplateMergeTest to validate the merge functionality.
- Modifications in ExcelWriteFillExecutor to capture original row merged region information and apply these merges to newly added rows.
- Updates to record and propagate cell styles and merged regions when creating new cells in vertical fill mode with forceNewRow and autoStyle enabled.
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
fastexcel-test/src/test/java/cn/idev/excel/test/core/template/TemplateMergeTest.java | Adds a new test ensuring that fill processing properly handles merged cell regions. |
fastexcel-core/src/main/java/cn/idev/excel/write/executor/ExcelWriteFillExecutor.java | Implements logic to record merged regions in the original row and apply them to new rows. |
Comments suppressed due to low confidence (1)
fastexcel-core/src/main/java/cn/idev/excel/write/executor/ExcelWriteFillExecutor.java:77
- [nitpick] Consider renaming 'originalMergeRegionMap' to 'initialRowMergeRegions' to more clearly indicate that it holds merged region information from the initial row.
private final Map<AnalysisCell,List<CellRangeAddress>> originalMergeRegionMap = MapUtils.newHashMap();
for (CellRangeAddress cellAddresses : regionList) { | ||
cachedSheet.addMergedRegionUnsafe(new CellRangeAddress(index, index, cellAddresses.getFirstColumn(), cellAddresses.getLastColumn())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the loop range based on 'collectionData.size()' is valid and that the new merged region does not exceed the sheet's boundaries, as using 'addMergedRegionUnsafe' without boundary checks may lead to runtime exceptions.
for (CellRangeAddress cellAddresses : regionList) { | |
cachedSheet.addMergedRegionUnsafe(new CellRangeAddress(index, index, cellAddresses.getFirstColumn(), cellAddresses.getLastColumn())); | |
if (index < 0 || index >= cachedSheet.getWorkbook().getSpreadsheetVersion().getMaxRows()) { | |
continue; // Skip if the row index is out of bounds | |
} | |
for (CellRangeAddress cellAddresses : regionList) { | |
int firstColumn = cellAddresses.getFirstColumn(); | |
int lastColumn = cellAddresses.getLastColumn(); | |
if (firstColumn < 0 || lastColumn >= cachedSheet.getWorkbook().getSpreadsheetVersion().getMaxColumns()) { | |
continue; // Skip if the column range is out of bounds | |
} | |
cachedSheet.addMergedRegionUnsafe(new CellRangeAddress(index, index, firstColumn, lastColumn)); |
Copilot uses AI. Check for mistakes.
Resolve the issue where newly added rows do not inherit the original row's merge information during template filling: