【发布时间】:2019-05-24 08:54:50
【问题描述】:
尝试使用 powershell 生成的条形图格式化 datalabel 字体大小,但不起作用
阅读适用于 VBA 和 .NET 的 Chart.SeriesCollection 的“完整”API。但这无济于事。是虫子还是我脑子有虫?谁能帮忙?
https://docs.microsoft.com/de-de/office/vba/api/excel.chart.seriescollection
我的尝试(对此有不同的迭代)
$chart.SeriesCollection(1).DataLabels.Format.TextFrame2.TextRange2.Font.Size = 18
Powershell 错误消息:在此对象上找不到属性“大小”。验证该属性是否存在并且可以设置。
整个简短的 powershell 脚本:
$excel = New-Object -comobject Excel.Application
$excel.Visible = $True
$workbook = $excel.Workbooks.Add()
$sheet = $excel.Worksheets.Item(1)
$sheet.Activate() | Out-NULL
$sheet.Cells.Item(1,1).Value2 = "City"
$sheet.Cells.Item(1,2).Value2 = "Citizens"
$sheet.Cells.Item(2,1) = "Offenbach"
$sheet.Cells.Item(2,2) = 111020
$sheet.Cells.Item(3,1) = "Heusenstamm"
$sheet.Cells.Item(3,2) = 18200
$sheet.Cells.Item(4,1) = "Rembruecken"
$sheet.Cells.Item(4,2) = 1850
$range = "A1:B4"
$chartSelect = $sheet.range($range)
$ch = $sheet.shapes.addChart().chart
$ch.chartType = 51
$ch.ApplyDataLabels(2)
$ch.SeriesCollection(1).DataLabels.Format.TextFrame2.TextRange2.Font.Size = 18
$ch.setSourceData($chartSelect)
【问题讨论】:
-
请添加更多代码,以便我们尝试重现它...
标签: excel powershell charts format