excel - 如何在 Excel VBA 中绘制带轮廓的楔形?
问题描述
我想在 Excel(Office 365 ProPlus 的桌面版本)中使用 VBA 绘制一个圆的扇区(即楔形)。下面的代码给了我正确的形状,但在弯曲部分只有一个轮廓:
Dim myArc as Shape
Set myArc = ActiveSheet.Shapes.AddShape(msoShapeArc, 200, 100, 100, 100)
With myArc
.Adjustments(1) = 0
.Adjustments(2) = 45
.Fill.Visible = msoTrue
End With
直边没有轮廓,只有曲线。 我怎样才能在形状周围得到一个轮廓? 我应该使用不同的形状msoShapeArc
吗?我尝试使用下面的代码更改线条颜色、粗细和可见性,但它只影响弯曲边缘,而不影响直线边缘。
With myArc
.Line.ForeColor.RGB = RGB(0, 0, 0)
.Line.Weight = 1
.Line.Visible = msoTrue
End With
我已经能够找到有关一般形状属性的文档,但没有找到哪些属性适用于哪种形状,以及它们如何实际控制其外观。
解决方案
根据https://docs.microsoft.com/en-us/office/vba/api/excel.adjustments:
由于每个可调整形状都有一组不同的调整,因此验证特定形状的调整行为的最佳方法是手动创建形状的实例,在打开宏记录器的情况下进行调整,然后检查记录的代码。
这对我来说创建了一个馅饼楔:
Sub WedgeTest()
Dim ws As Worksheet, shp As Shape
Set ws = ActiveSheet
Set shp = ws.Shapes.AddShape(msoShapePie, 50, 50, 100, 100)
With shp
.Adjustments.Item(1) = -90 'degrees from 3 oclock
.Adjustments.Item(2) = -45 'degrees from 3 oclock
.Fill.Visible = msoFalse
With .Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
End Sub
请注意,从 3 点开始的度数是正数(顺时针)或负数(逆时针),但不能超过绝对值 180,因此顺时针 +190 度将设置为 -170(逆时针)。
推荐阅读
- c# - 生成 ERR_HTTP2_PROTOCOL_ERROR 的 Azure 应用注册快速入门代码
- ruby-on-rails - Rails 多对多 API 查询
- python - 电报机器人 GetUpdate 返回 {"ok":true,"result":[]}
- json - 数据工厂 - 从 JSON 文件中使用破折号“-”从字段中检索值
- c++ - 访问者模式是否比受控使用 RTTI 更好?
- typescript - Webstorm+TypeScript 无法解析 CRA 项目中的 SCSS 模块(错误 TS2339)
- javascript - NodeJS API 不会删除或更新 mongodb 中的数据
- c# - 当 WPF 中的文本太长时,带有滑块的 TextBlock
- sql - SQL Server 错误操作数类型冲突:int 与日期不兼容
- azure-resource-manager - Azure 门户是否使用未记录的 ARM 功能来部署应用服务?