2012-02-23 63 views
1

我尝试使用公式连接某些单元格的格式化内容。
由于我不能用纯公式解决问题,所以我添加了一些基本代码。获取范围/单元格对象的格式化文本

但我不知道如何访问单个单元格中的格式化文本值。
似乎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 
+1

您是否在寻找openoffice或excel中的解决方案? – assylias 2012-02-23 12:16:31

+0

我正在寻找openoffice解决方案,我的excel解决方案工程 – jeb 2012-02-23 12:21:29

+0

jeb,我不确定你的问题。您编写的OO代码完美无缺,无需在oCell之后添加任何内容 – 2012-02-24 05:33:24

回答

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

+0

Thx,但这只能是一种解决方法,因为我想使用像excel = StringSumme(A1:A10)中的公式。我看到了页面和其他许多样本,但是我找不到任何一个使用(公式)函数范围的描述 – jeb 2012-02-24 08:37:19

+1

@jeb:我可能是错的,但是我的研究表明,你不能在'计算器”。从'Calc'传递给宏的参数始终是值。根据此链接(http://www.linuxtopia.org/online_books/office_guides/openoffice_3_calc_user_guide/openoffice_calc_Passing_arguments_to_a_macro.html),您可以将范围作为字符串传递,然后解析它。 – 2012-02-27 11:59:59

+0

好吧,这解释了为什么我找不到任何参考如何访问范围对象。现在我将切换回Excel – jeb 2012-02-27 13:44:03

相关问题