【问题标题】:Get the formatted text of a range/cell object获取范围/单元格对象的格式化文本
【发布时间】:2012-02-23 11:50:26
【问题描述】:

我尝试用公式连接一些单元格的格式化内容。
因为我看不到用纯公式解决它的方法,所以我添加了一些基本代码。

但我不知道如何从单个单元格中访问格式化的文本值。
oCell 似乎不是单元格对象,而只是单元格内容。

我该如何改变这个,所以我可以使用类似的东西 oCell.Text 或 oCell.String ...

Function StringSumme(oCellRange )
    dim result as String
    dim nRow as Integer

    result = ""
   For nRow = LBound( oCellRange, 1) To UBound( oCellRange, 1 )
        For nCol = LBound( oCellRange, 2) To UBound( oCellRange, 2 )
            oCell=oCellRange(nRow,1)
            result = result + oCell
        Next 
    Next 
    StringSumme = result 
End Function

在 Excel 中这个可以工作

Function StringSumme(bezug As Range) As String
    Dim txt As String
    Dim ce As Range

    txt = ""
    For Each ce In bezug.Cells
        txt = txt & ce.Text
    Next
    StringSumme = txt
End Function

【问题讨论】:

  • 您是在 openoffice 还是在 excel 中寻找解决方案?
  • 我正在寻找一个 openoffice 解决方案,我的 excel 解决方案有效
  • jeb,我不确定你的问题。您编写的 OO 代码可以完美运行,无需在 oCell 之后添加任何内容
  • 但它只复制没有格式的文本。我有格式为“0”的单元格,OO 代码我丢失了,
  • +1 好问题。我今天学到了一些新东西,哈哈

标签: excel openoffice-calc openoffice-basic vba


【解决方案1】:

杰布

我想我现在明白你的问题了。

当你输入这个时

Function StringSumme(oCellRange)

oCellRange 不是范围。它是一个正在传递的数组。因此 oCell 不是单元格对象,而是您猜对的单元格内容。

你可能想把它改成类似

oCell = Sheet.getCellByPosition(X, Y)

然后使用oCell.Value

有趣的阅读

http://wiki.services.openoffice.org/wiki/Documentation/BASIC_Guide/Cells_and_Ranges

【讨论】:

  • 谢谢,但这只能是一种解决方法,因为我想使用像 excel `=StringSumme(A1:A10) 这样的公式。我看到了页面和许多其他示例,但我找不到任何使用范围和(公式)函数的描述
  • @jeb:我可能是错的,但我的研究表明您不能在“Calc”中的函数中传递范围。从“Calc”传递给宏的参数始终是值。根据此链接 (linuxtopia.org/online_books/office_guides/…),您可以将范围作为字符串传递,然后对其进行解析。
  • 好的,这就解释了为什么我找不到任何参考如何访问范围对象。现在我将切换回 Excel
  • @jeb:是的。如果您想将其作为范围传递,这似乎是唯一的选择。否则你将不得不使用我上面给出的选项:(
猜你喜欢
  • 1970-01-01
  • 2021-06-07
  • 2015-02-17
  • 2017-02-03
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
  • 2014-10-12
  • 2012-07-16
相关资源
最近更新 更多