在 LibreOffice Calc 中自动化图表标题
Automating the Title of a chart in LibreOffice Calc
我找到了下面的代码(根据我的需要更改)here
我尝试使用 libre calc 7.3.0 中的宏自动更改许多图表的标题。
我知道哪些单元格包含标题,我希望他们将它们添加到图表中。
我怎样才能让这个 VBA vcode 工作?
Const SCells = "L8, T8, AA8"
' Set the title of the first Chart to the contents of C1
Sub SetTitle
' Get active sheet
oSheet = ThisComponent.CurrentController.ActiveSheet
aCells = Split(SCells,",")
for i = uBound(aCells) to 0 step -1
' Get the cell containing the chart title, in this case C1
oCell = oSheet.getCellRangeByName(aCells(i))
oCharts = oSheet.getCharts()
' Get the chart with index 0, which is the first chart created
' to get the second you would use 1, the third 2 and so on...
oChart = oCharts.getByIndex(i)
oChartDoc = oChart.getEmbeddedObject()
'Change title
oChartDoc.getTitle().String = oCell.getString()
next i
End Sub
我做错了什么?我在 Const SCells 内容中有空格:
“L11、T11、E11”是错误的。
我使用 xraytool 检查了 aCells 的内容,发现内容被解析为 1) "L11"、2) " T11" 和 3) " E11",带有空格。
因此您可以使用 vba 代码在 librecalc sheet 中自动更改图表的标题:
' NOTE: NO SPACES OR OTHER CHARACTERS
Const SCells = "L11,T11,E11"
Sub SetTitle
' Get active sheet
oSheet = ThisComponent.CurrentController.ActiveSheet
' Split SCells content by ","
' see Print aCells for corrent content
aCells = Split(SCells,",")
'enumarate by "1" point increment
for i = uBound(aCells) to 0 step -1
' using aCells Content
oCell = oSheet.getCellRangeByName(aCells(i))
oCharts = oSheet.getCharts()
' Get the chart with index 0, which is the first chart created
' to get the second you would use 1, the third 2 and so on...
oChart = oCharts.getByIndex(i)
oChartDoc = oChart.getEmbeddedObject()
'Change title
oChartDoc.getTitle().String = oCell.getString()
' xray oChart.Name
next i
End Sub
我找到了下面的代码(根据我的需要更改)here
我尝试使用 libre calc 7.3.0 中的宏自动更改许多图表的标题。
我知道哪些单元格包含标题,我希望他们将它们添加到图表中。 我怎样才能让这个 VBA vcode 工作?
Const SCells = "L8, T8, AA8"
' Set the title of the first Chart to the contents of C1
Sub SetTitle
' Get active sheet
oSheet = ThisComponent.CurrentController.ActiveSheet
aCells = Split(SCells,",")
for i = uBound(aCells) to 0 step -1
' Get the cell containing the chart title, in this case C1
oCell = oSheet.getCellRangeByName(aCells(i))
oCharts = oSheet.getCharts()
' Get the chart with index 0, which is the first chart created
' to get the second you would use 1, the third 2 and so on...
oChart = oCharts.getByIndex(i)
oChartDoc = oChart.getEmbeddedObject()
'Change title
oChartDoc.getTitle().String = oCell.getString()
next i
End Sub
我做错了什么?我在 Const SCells 内容中有空格: “L11、T11、E11”是错误的。
我使用 xraytool 检查了 aCells 的内容,发现内容被解析为 1) "L11"、2) " T11" 和 3) " E11",带有空格。
因此您可以使用 vba 代码在 librecalc sheet 中自动更改图表的标题:
' NOTE: NO SPACES OR OTHER CHARACTERS Const SCells = "L11,T11,E11" Sub SetTitle ' Get active sheet oSheet = ThisComponent.CurrentController.ActiveSheet ' Split SCells content by "," ' see Print aCells for corrent content aCells = Split(SCells,",") 'enumarate by "1" point increment for i = uBound(aCells) to 0 step -1 ' using aCells Content oCell = oSheet.getCellRangeByName(aCells(i)) oCharts = oSheet.getCharts() ' Get the chart with index 0, which is the first chart created ' to get the second you would use 1, the third 2 and so on... oChart = oCharts.getByIndex(i) oChartDoc = oChart.getEmbeddedObject() 'Change title oChartDoc.getTitle().String = oCell.getString() ' xray oChart.Name next i End Sub