mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-12-24 08:29:20 +00:00
created lookup function
This commit is contained in:
parent
d93e676739
commit
4859c81511
43
src/com/bytezone/diskbrowser/visicalc/Lookup.java
Normal file
43
src/com/bytezone/diskbrowser/visicalc/Lookup.java
Normal file
@ -0,0 +1,43 @@
|
||||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
public class Lookup
|
||||
{
|
||||
Range range;
|
||||
VisicalcCell source;
|
||||
VisicalcSpreadsheet parent;
|
||||
boolean hasValue;
|
||||
|
||||
public Lookup (VisicalcSpreadsheet 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;
|
||||
}
|
||||
}
|
@ -88,28 +88,8 @@ class VisicalcCell implements Comparable<VisicalcCell>
|
||||
|
||||
if (formula.startsWith ("@LOOKUP("))
|
||||
{
|
||||
int pos = formula.indexOf (',');
|
||||
String sourceText = formula.substring (8, pos);
|
||||
String rangeText = formula.substring (pos + 1, formula.length () - 1);
|
||||
VisicalcCell source = parent.getCell (new Address (sourceText));
|
||||
Range range = parent.getRange (rangeText);
|
||||
// System.out.printf ("lookup[%s][%s]%n", source, range);
|
||||
|
||||
Address target = null;
|
||||
for (Address address : range)
|
||||
{
|
||||
// System.out.printf ("%s %s%n", source, parent.getCell (address));
|
||||
if (parent.getCell (address).value > source.value)
|
||||
break;
|
||||
target = address;
|
||||
}
|
||||
if (target != null)
|
||||
{
|
||||
value = parent.getCell (target.nextColumn ()).value;
|
||||
valid = true;
|
||||
return value;
|
||||
}
|
||||
return result;
|
||||
Lookup lookup = new Lookup (parent, formula);
|
||||
return lookup.getValue ();
|
||||
}
|
||||
|
||||
Matcher m = cellContents.matcher (formula);
|
||||
|
Loading…
Reference in New Issue
Block a user