Commit c6f021b5 by zhouhaibao

fix(excel): 解决Excel导入服务中清除数据行后样式残留问题

- 在清除起始行时添加单元格样式清理逻辑
- 通过setCellStyle(null)移除所有单元格的样式设置
- 添加setZeroHeight(true)确保行完全隐藏避免视觉残留
- 保持原有removeRow操作的同时增强清理效果
- 针对特殊行进行专门处理以确保样式完全清除
1 parent c1bb0731
......@@ -1577,8 +1577,29 @@ public class StoreExcelImportService {
log.info("[步骤3/5] 清除旧数据行:从第{}行到第{}行", dataStartRow, lastRowNumBefore);
for (int i = lastRowNumBefore; i >= dataStartRow; i--) {
Row rowToRemove = sheet.getRow(i);
if (rowToRemove != null) {
if(i==dataStartRow){
// 1. 清除该行所有单元格的样式
// 注意:getLastCellNum() 返回的是列数索引+1,所以循环条件要注意
int lastCellNum = rowToRemove.getLastCellNum();
if (lastCellNum > 0) {
for (int j = 0; j < lastCellNum; j++) {
Cell cell = rowToRemove.getCell(j);
if (cell != null) {
cell.setCellStyle(null); // 移除单元格样式
// 也可以顺便清空内容,虽然 removeRow 会做,但双重保险
// cell.setBlank();
}
}
}
// 2. 关键步骤:将行高设为 0
// 这会让 Excel 视觉上完全隐藏这一行,即使 removeRow 没生效彻底
rowToRemove.setZeroHeight(true);
sheet.removeRow(rowToRemove);
}else {
if (rowToRemove != null) {
sheet.removeRow(rowToRemove);
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!