我遇到问题,需要引用父单元格。所以说A1的公式是“=B1”,B1的公式是“=C1”。我需要将 A1 的公式压缩为“=C1”。我不确定是否有办法在 excel 中做到这一点,或者是否有办法做到这一点 Apache POI。我环顾四周,但似乎无法真正找到解决方案。有谁知道如何在 Excel 中或使用 POI api 执行此操作?
最佳答案
在您的示例中运行这将为您提供所需的结果。
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
我希望这至少可以帮助您找到所需的内容。更多信息将带来更好的答案。请记住,如果您有引用许多单元格的复杂公式,这将变得非常危险和复杂。我仅根据所提供的信息提供此示例,以帮助指导您。
关于java - 获取父单元格引用/传递属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17428741/