0

我在需要引用父单元格时遇到问题。所以说A1的公式是“=B1”,B1的公式是“=C1”。我需要将 A1 的公式压缩为“=C1”。我不确定是否有办法在 excel 中执行此操作,或者是否有办法执行此 Apache POI。我环顾四周,但似乎无法真正找到解决方案。有谁知道如何在 excel 或 POI api 中做到这一点?

4

1 回答 1

2

在您的示例运行中,这将为您提供您要求的结果。

Sub GetLastPrecedent()

Dim pres As Range
Dim TestCell As Range

Set TestCell = Range("A1")
'Set pres to all cells that are used in getting the value of TestCell
'This includes all precedents of precedents
Set pres = TestCell.Precedents
'This will return the absolute precedent of the ones returned
Set pres = pres.Cells(pres.Rows.Count, pres.Columns.Count)
'This will set the formula in TestCell to use the absolute address
TestCell.Formula = "=" & pres.Address

End Sub

我希望这至少可以帮助指导您找到所需的内容。更多信息将导致更好的答案。请记住,如果您有引用许多单元格的复杂公式,这将变得非常危险和复杂。我仅根据提供的信息提供此示例,以帮助指导您。

于 2013-07-02T15:07:52.167 回答