excel - 为什么无法通过 VBA 精确设置 Excel 图表的大小?
问题描述
我正在尝试通过 VBA 设置 Excel 图表的大小,我注意到 .ChartArea.Width 和 .ChartArea.Height 属性设置的值通常与所需的值略有不同。例如下面的代码:
Sub test_chart_area()
Dim CA_w As Double
Dim CA_h As Double
CA_w = 500
CA_h = 300
With ActiveChart
.ChartArea.Width = CA_w
Debug.Print (".ChartArea.Width: " & .ChartArea.Width)
.ChartArea.Height = CA_h
Debug.Print (".ChartArea.Height: " & .ChartArea.Height)
End With
End Sub
将图表设置为“.ChartArea.Width: 496.902204724409”和“.ChartArea.Height: 293.152125984252”
另一方面,.PlotArea.InsideWidth 和 .PlotArea.InsideHeight 属性显然只分配整数值。例如下面的代码:
Sub test_plot_area_inside()
Dim PA_iw As Double
Dim PA_ih As Double
PA_iw = 200.411968503937
PA_ih = 100.642677165354
With ActiveChart
.PlotArea.InsideWidth = PA_iw
Debug.Print (".PlotArea.InsideWidth: " & .PlotArea.InsideWidth)
.PlotArea.InsideHeight = PA_ih
Debug.Print (".PlotArea.InsideHeight: " & .PlotArea.InsideHeight)
End With
End Sub
将图表设置为“.PlotArea.InsideWidth: 200”和“.PlotArea.InsideHeight: 100”。
所需值和返回值之间的差异无关紧要,但我想了解这种行为的原因。
提前谢谢了。
解决方案
设置 的.Width
和.Height
属性ActiveChart.Parent
。
推荐阅读
- python - 如何通过迭代熊猫数据框来填充函数参数
- reactjs - 在 scss 中使用 API 中的变量
- mysql - 如何通过 SSH 导出数据库?
- css - 如果条件为真,则添加 className
- opencv - cv2.COLOR_GRAY2RGB 有什么作用?
- angular - 如何在不更改后端的情况下解决 Angular 8 中的 CORS 问题?
- python - python for循环函数输出一遍又一遍地带来相同的结果
- python - pandas.Series.str.contains 不支持 Python 中的换行符或反斜杠
- mysql - 没有架构的 MySQL 转储文件
- python - 单个excel中的多个选项卡