0

我最近发现,当我通过 ActiveX 从 aspx / html 页面并使用 javascript 写入 excel 文件时,您在 Excel IDE 中看到的宏 / vba 代码不会完全匹配。

例如 - 在 Excel 中,如果您在删除单元格边框时录制宏,您会看到如下内容:

Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

但是,如果您想通过活动 X 从 JS 执行相同的操作,则无法识别该代码。(下面回答)

4

1 回答 1

1

上面的代码会写成这样:

ws.Range("A1:Z65536").Borders(5).LineStyle = -4142;
ws.Range("A1:Z65536").Borders(6).LineStyle = -4142;
ws.Range("A1:Z65536").Borders(7).LineStyle = -4142;
ws.Range("A1:Z65536").Borders(8).LineStyle = -4142;
ws.Range("A1:Z65536").Borders(9).LineStyle = -4142;
ws.Range("A1:Z65536").Borders(10).LineStyle = -4142;
ws.Range("A1:Z65536").Borders(11).LineStyle = -4142;
ws.Range("A1:Z65536").Borders(12).LineStyle = -4142;

因为每个位置和 LineStyle 都有数字映射。从这里

These define the style of the border
xlNone = -4142; Note this is the same as xlLineStyleNone
xlContinuous = 1;
xlDash = -4115;
xlDashDot = 4;
xlDashDotDot = 5;
xlDot = -4118;
xlDouble = -4119;
xlSlantDashDot = 13;

These define the weight of the border
xlHairLine = 1;
xlMedium = -4138;
xlThick = 4;
xlThin = 2;

Thise is handy to make borders have the default color index
xlAutomatic = -4105;

These define the placement of border pieces
xlDiagonalDown = 5;
xlDiagonalUp = 6;
xlEdgeLeft = 7;
xlEdgeTop = 8;
xlEdgeBottom = 9;
xlEdgeRight = 10;
xlInsideVertical = 11;
xlInsideHorizontal = 12;
于 2013-03-27T22:17:34.387 回答