【发布时间】:2020-06-09 08:42:52
【问题描述】:
我是使用 OOobasic 构建 LibreOffice 宏的新手。
我正在测试方法 .getDataArray() 正如您在示例中看到的那样,数组被加载了值,但后来,我想用这个数组进行迭代,直到用 UBound() 结束数组,但 UBound 始终为 0,我不知道为什么。 如您所见, getDataArray 获取范围的值。就我而言,我的范围是从 A1 到 AH1 的简单行。
Sub TestArray2
Dim oSheet as object
Dim Simple_Row_array() As Variant
Dim SimpleRow 'Como no sabemos lo grande que es lo redimensionamos despues.
Dim Columnas as Long
oSheet = ThisComponent.Sheets.getByName("Concedidos")
Dim oRange As Object : oRange = oSheet.getCellRangebyName( "A1:AH1" )
Columnas = oRange.Columns.getCount() - 1'Get the number of columns. getColumn, getRow existe.
Redim Preserve Simple_Row_array (0 To Columnas)
Redim Preserve SimpleRow (Columnas)
Simple_Row_array() = oRange.getDataArray() 'Asign values to an array
For i = LBound(Simple_Row_array()) To UBound(Simple_Row_array())
SimpleRow(i) = Simple_Row_array(0)(i)
Next i
Print UBound(SimpleRow()) 'It display the amount of values correctly
Print UBound(Simple_Row_array(),1)'it displays always 0.
Print UBound(Simple_Row_array())'it displays always 0.
End Sub
在循环“For”中,如果我通过变量“Columnas”更改 UBound(),则迭代有效。 任何想法为什么我错了? 请具体点。如果您有解决方案,请将代码发送给我。
【问题讨论】:
标签: libreoffice-calc libreoffice-basic