2012-02-23 60 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

相關問題