dmolony-DiskBrowser/src/com/bytezone/diskbrowser/visicalc/Lookup.java
2016-03-06 19:05:32 +11:00

43 lines
889 B
Java

package com.bytezone.diskbrowser.visicalc;
public class Lookup
{
Range range;
Cell source;
Sheet parent;
boolean hasValue;
public Lookup (Sheet parent, String text)
{
this.parent = parent;
int pos = text.indexOf (',');
String sourceText = text.substring (8, pos);
String rangeText = text.substring (pos + 1, text.length () - 1);
source = parent.getCell (new Address (sourceText));
range = parent.getRange (rangeText);
}
// need a mechanism to return NA and ERROR
public boolean hasValue ()
{
return hasValue;
}
public double getValue ()
{
Address target = null;
for (Address address : range)
{
if (parent.getCell (address).getValue () > source.getValue ())
break;
target = address;
}
if (target != null)
return parent.getCell (target.nextColumn ()).getValue ();
return 0;
}
}