如何在 OpenOffice Calc 宏中获取合并单元格 row/column 跨度
How to get merged cell row/column span in OpenOffice Calc Macro
我可以检测 sheet 中的给定单元格是否与 sheet.getCellByPosition(0,0).IsMerged
合并
有什么办法可以发现合并单元格的width/height吗?
首先弄清楚单元格横跨哪些行或列。例如,假设我们想要计算出跨两列的单元格的宽度。
然后对于涉及的每一列,找出它的宽度,并将宽度相加。此代码改编自 https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=19790,确定列的宽度:
Sub GetColumnWidth
dim oSheet as object, oDoc As Object
dim w as single
dim col as integer
oDoc = ThisComponent
oSheet = ThisComponent.getCurrentController.getActiveSheet
col = 1 'column B
oColumn = oSheet.getColumns.getByIndex( col )
'column width (in 100ths of mm)
w = oColumn.Width / 2540
MsgBox w
End Sub
还有一点,好像有一个ShrinkToFit属性。我没有测试这是否反映在 Width
属性.
我可以检测 sheet 中的给定单元格是否与 sheet.getCellByPosition(0,0).IsMerged
有什么办法可以发现合并单元格的width/height吗?
首先弄清楚单元格横跨哪些行或列。例如,假设我们想要计算出跨两列的单元格的宽度。
然后对于涉及的每一列,找出它的宽度,并将宽度相加。此代码改编自 https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=19790,确定列的宽度:
Sub GetColumnWidth
dim oSheet as object, oDoc As Object
dim w as single
dim col as integer
oDoc = ThisComponent
oSheet = ThisComponent.getCurrentController.getActiveSheet
col = 1 'column B
oColumn = oSheet.getColumns.getByIndex( col )
'column width (in 100ths of mm)
w = oColumn.Width / 2540
MsgBox w
End Sub
还有一点,好像有一个ShrinkToFit属性。我没有测试这是否反映在 Width
属性.