Skip to content

Commit d54ef9d

Browse files
committed
fix(IE.Excel): 修复 P0-1 DoAdjustDrawings ship-blocker 及配套清理
P0-1 [高] DoAdjustDrawings = false 恢复无 try/finally 位置: ExportHelper.AddPictures line 932-1014 风险: 任一处抛未捕获异常时, package.DoAdjustDrawings 永久卡在 false, 后续用户代码 Row.Height = X / Column.Width = X / Column.Hidden = X 静默失效 (setter 走 _worksheet._package.DoAdjustDrawings 分支) 修复: 用 try/finally 包裹原 938-1010 整段, finally 恢复 prevDoAdjust 验证: 33/33 image-related 测试通过 (含 500/1000/2000 行压力); 319/319 全套测试通过 P1-1 [中] Preallocate 估算过乘 旧: imageUrls.Count * rowCount * imageColCount (3-way 过乘) 新: rowCount * imageColCount (精确值) 实际 drawing 数 = rowCount * imageColCount, imageUrls.Count 是 unique URLs P1-2 [低] _doNotAdjust 收紧访问 旧: protected internal (允许跨 assembly 子类访问) 新: internal (仅同 assembly, ExcelPicture 与基类同 assembly 仍可访问) 影响: 0 (vendored EPPlus 不暴露给外部继承) 参考: .claude/plans/abstract-gathering-raven.md (P0-1, P1-1, P1-2)
1 parent acc01a3 commit d54ef9d

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/EPPlus/EPPlus/Drawing/ExcelDrawingBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public int RowOff
184184
public const int EMU_PER_PIXEL = 9525;
185185
protected internal int _width = int.MinValue, _height = int.MinValue, _top = int.MinValue, _left = int.MinValue;
186186
// Subclasses (e.g. ExcelPicture ctor) set this to skip GetPositionSize side effects.
187-
protected internal bool _doNotAdjust = false;
187+
internal bool _doNotAdjust = false;
188188
internal ExcelDrawing(ExcelDrawings drawings, XmlNode node, string nameXPath) :
189189
base(drawings.NameSpaceManager, node)
190190
{

src/Magicodes.ExporterAndImporter.Excel/Utility/ExportHelper.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,12 +926,16 @@ protected void AddPictures(int rowCount)
926926
if (ExporterHeaderList[c].ExportImageFieldAttribute != null)
927927
imageColCount++;
928928
}
929-
CurrentExcelWorksheet.Drawings.Preallocate(imageUrls.Count * rowCount * Math.Max(imageColCount, 1));
929+
CurrentExcelWorksheet.Drawings.Preallocate(rowCount * Math.Max(imageColCount, 1));
930930

931931
// 关闭 Row.Height 触发的 drawings 重算(EditAs=OneCell 不依赖 row height 重定位)
932+
// 必须用 try/finally 保证 flag 恢复,否则任一处抛未捕获异常都会让 flag 卡在 false,
933+
// 后续用户对 Row.Height / Column.Width / Column.Hidden 的 setter 静默失效.
932934
var package = CurrentExcelPackage;
933935
var prevDoAdjust = package.DoAdjustDrawings;
934936
package.DoAdjustDrawings = false;
937+
try
938+
{
935939

936940
// 并行加载图片
937941
var imageCache = new System.Collections.Concurrent.ConcurrentDictionary<string, (byte[] bytes, Magicodes.IE.Excel.Images.ImageExtensions.ImageInfo meta)>();
@@ -1007,7 +1011,11 @@ protected void AddPictures(int rowCount)
10071011
}
10081012
}
10091013
}
1010-
package.DoAdjustDrawings = prevDoAdjust;
1014+
}
1015+
finally
1016+
{
1017+
package.DoAdjustDrawings = prevDoAdjust;
1018+
}
10111019
}
10121020

10131021
internal static void AddImage(int rowIndex, int colIndex, ExcelPicture picture, int yOffset, int xOffset)

0 commit comments

Comments
 (0)